01: package org.theospi.portfolio.security.impl;
02:
03: import org.apache.commons.codec.digest.DigestUtils;
04: import org.sakaiproject.metaobj.shared.model.Agent;
05: import org.sakaiproject.metaobj.shared.model.OspException;
06: import org.sakaiproject.user.api.UserEdit;
07: import org.sakaiproject.user.cover.UserDirectoryService;
08: import org.theospi.portfolio.shared.model.AgentImplOsp;
09:
10: /**
11: * Created by IntelliJ IDEA.
12: * User: bbiltimier
13: * Date: Apr 18, 2006
14: * Time: 3:35:28 PM
15: * To change this template use File | Settings | File Templates.
16: */
17: public class AgentManagerOsp extends
18: org.sakaiproject.metaobj.security.impl.sakai.AgentManager {
19: public Agent createAgent(Agent agent) {
20: if (!agent.isInRole(Agent.ROLE_GUEST)) {
21: // we don't support creating real agents
22: throw new UnsupportedOperationException();
23: }
24:
25: try {
26: UserEdit uEdit = UserDirectoryService.addUser(agent.getId()
27: .getValue(), agent.getId().getValue());
28:
29: //set email address
30: uEdit.setEmail(agent.getId().getValue());
31:
32: // set id
33: uEdit.setId(agent.getId().getValue());
34:
35: // set the guest user type
36: uEdit.setType("guest");
37:
38: String pw = getPasswordGenerator().generate();
39: uEdit.setPassword(pw);
40: UserDirectoryService.commitEdit(uEdit);
41:
42: AgentImplOsp impl = (AgentImplOsp) agent;
43: impl.setPassword(pw);
44: impl.setMd5Password(DigestUtils.md5Hex(pw));
45:
46: return agent;
47: } catch (RuntimeException exp) {
48: throw exp;
49: } catch (Exception exp) {
50: throw new OspException(exp);
51: }
52: }
53:
54: }
|