1 package net.sourceforge.blogentis.turbine;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import net.sourceforge.blogentis.om.TurbineUser;
26 import net.sourceforge.blogentis.om.TurbineUserPeer;
27
28 import org.apache.torque.TorqueException;
29 import org.apache.turbine.om.security.User;
30 import org.apache.turbine.services.security.ldap.LDAPUserManager;
31 import org.apache.turbine.util.security.DataBackendException;
32 import org.apache.turbine.util.security.UnknownEntityException;
33
34 /***
35 * LDAP User manager that ensures the user exists in the database.
36 *
37 * @author abas
38 */
39 public class BlogUserManager
40 extends LDAPUserManager {
41
42 public User retrieve(String username)
43 throws UnknownEntityException, DataBackendException {
44 BlogUser u = (BlogUser)super.retrieve(username);
45
46 try {
47 TurbineUserPeer.retrieveByPK(u.getPrimaryKey());
48 } catch (TorqueException e) {
49 try {
50 TurbineUser tu = new TurbineUser();
51 tu.setCreateDate(u.getCreateDate());
52 tu.setFirstName(u.getFirstName());
53 tu.setLastName(u.getLastName());
54 tu.setEmail(u.getEmail());
55 tu.setLastLogin(u.getLastLogin());
56 tu.setUserId(Integer.parseInt(u.getPrimaryKey().toString()));
57 tu.setNew(false);
58 tu.setPassword("");
59 tu.setUserName(u.getName());
60 TurbineUserPeer.doInsert(TurbineUserPeer.buildCriteria(tu));
61 } catch (Exception e2) {
62 throw new DataBackendException(
63 "Could not store user in database", e2);
64 }
65 }
66 return u;
67 }
68 }