View Javadoc

1   package gov.bnl.gums.account;
2   
3   import javax.persistence.Entity;
4   import javax.persistence.Transient;
5   
6   import gov.bnl.gums.Mapping;
7   import gov.bnl.gums.SiteUser;
8   import gov.bnl.gums.configuration.Configuration;
9   
10  @Entity
11  public class LdapAccountPoolMapper extends AccountPoolMapper {
12  	protected LdapAccountMapper ldap = new LdapAccountMapper();
13  	
14  	// persistent variables
15  	protected String jndiLdapUrl;
16  	protected String ldapPrincipal;
17  	protected String ldapPassword;
18  	protected String dnField = "description";
19  	protected String accountField = "uid";
20  	protected String memberUidField = "memberUid";
21  	protected String gidNumberField = "gidNumber";
22  	protected String groupCnField = "cn";
23  	protected String peopleTree;
24  	protected String peopleObject = "ou=People";
25  	protected String peopleContext;
26  	protected String groupTree;
27  	protected String groupObject = "ou=Group";
28  	protected String groupContext;
29  	protected boolean synchGroups;
30  
31      public LdapAccountPoolMapper() {
32      	super();
33      }
34      
35      public LdapAccountPoolMapper(Configuration configuration, String name) {
36      	super(configuration, name);
37      }
38  	
39  	public String getAccountField() {
40  		return ldap.getAccountField();
41  	}
42  	
43  	public String getDnField() {
44  		return ldap.getDnField();
45  	}
46  	
47  	public String getGidNumberField() {
48  		return ldap.getGidNumberField();
49  	}
50  	
51  	public String getGroupCnField() {
52  		return ldap.getGroupCnField();
53  	}
54  	
55  	public String getGroupTree() {
56  		return ldap.getGroupTree();
57  	}
58  	
59  	public String getJndiLdapUrl() {
60  		return ldap.getJndiLdapUrl();
61  	}
62  	
63  	public String getMemberUidField() {
64  		return ldap.getMemberUidField();
65  	}
66  	
67  	public String getPeopleTree() {
68  		return ldap.getPeopleTree();
69  	}
70  	
71  	public boolean isSynchGroups() {
72  		return ldap.isSynchGroups();
73  	}
74  	
75  	public SiteUser mapDn(String dn, boolean createNew){
76  		SiteUser siteUser = super.mapDn(dn, createNew);
77  		boolean justCreated = false;
78  		synchronized(mappings) {
79  			if (siteUser == null && createNew) {
80  				for (Mapping m: mappings) {
81  					if (m.getDn() == null) {
82  						m.setDn(dn);
83  						siteUser = m.getSiteUser();
84  					}
85  				}
86  			}
87  			
88  			// Assign groups in ldap
89  			if (siteUser!=null && (justCreated || ldap.isSynchGroups())) {
90  				ldap.changeGroup(siteUser.getAccount(), primaryGroup);
91  				for (String g: secondaryGroups)
92  					ldap.addToSecondaryGroup(siteUser.getAccount(), g);
93  			}
94  		}
95  		return null;
96  	}
97  	
98  	@ConfigFieldAnnotation(label="LDAP UID Field", example="uid", help="(account UID field)")
99  	public void setAccountField(String accountField) {
100 		ldap.setAccountField(accountField);
101 	}
102 	
103 	@ConfigFieldAnnotation (label="LDAP Certificate DN Field", example="description", help="certificate DN field")
104 	public void setDnField(String dnField) {
105 		ldap.setDnField(dnField);
106 	}
107 	
108 	@ConfigFieldAnnotation(label="LDAP GID Number Field", example="gidNumber", help="(group ID number field in 'People' object)")
109 	public void setGidNumberField(String gidNumberField) {
110 		ldap.setGidNumberField(gidNumberField);
111 	}
112 	
113 	@ConfigFieldAnnotation(label="LDAP Group CN Field", example="cn", help="(group common name field)")
114 	public void setGroupCnField(String groupCnField) {
115 		ldap.setGroupCnField(groupCnField);
116 	}
117 	
118 	@ConfigFieldAnnotation(label="Group Tree", example="ou=Group,dc=usatlas,dc=bnl,dc=gov", help="(relative to context in LDAP URL - optional)")
119 	public void setGroupTree(String groupTree) {
120 		ldap.setGroupTree(groupTree);
121 	}
122 	
123 	@ConfigFieldAnnotation(label="JNDI LDAP URL", example="ldap://localhost/dc=usatlas,dc=bnl,dc=gov") 
124 	public void setJndiLdapUrl(String jndiLdapUrl) {
125 		ldap.setJndiLdapUrl(jndiLdapUrl);
126 	}
127 	
128 	@ConfigFieldAnnotation(label="Member Field", example="memberUid", help="field containing user ID in 'Group' object")
129 	public void setMemberUidField(String memberUidField) {
130 		ldap.setMemberUidField(memberUidField);
131 	}
132 	
133 	@ConfigFieldAnnotation(label="People Tree", example="ou=People,dc=usatlas,dc=bnl,dc=gov", help="relative to context in LDAP URL - optional")
134 	public void setPeopleTree(String peopleTree) {
135 		ldap.setPeopleTree(peopleTree);
136 	}
137 	
138 	@ConfigFieldAnnotation(label="Update group and email for every access")
139 	public void setSynchGroups(boolean synchGroups) {
140 		ldap.setSynchGroups(synchGroups);
141 	}
142 }