- // password
- byte[] arr = (byte[]) ctx.getAttributeSortedStringSet("userPassword")
- .first();
- JcrUserDetails userDetails = new JcrUserDetails(userHomePath, username,
- new String(arr), true, true, true, true, authorities);
- Arrays.fill(arr, (byte) 0);
- return userDetails;
- }
-
- public void mapUserToContext(UserDetails user, final DirContextAdapter ctx) {
- if (!(user instanceof JcrUserDetails))
- throw new ArgeoException("Unsupported user details: "
- + user.getClass());
-
- ctx.setAttributeValues("objectClass", new String[] { "inetOrgPerson" });
- ctx.setAttributeValue("uid", user.getUsername());
- ctx.setAttributeValue("userPassword", user.getPassword());
-
- final JcrUserDetails jcrUserDetails = (JcrUserDetails) user;
- systemExecutionService.executeAsSystem(new Runnable() {
- public void run() {
- Session session = null;
- try {
- Repository nodeRepo = JcrUtils.getRepositoryByAlias(
- repositoryFactory, ArgeoJcrConstants.ALIAS_NODE);
- session = nodeRepo.login();
- Node userProfile = session.getNode(jcrUserDetails
- .getHomePath()
- + '/'
- + ArgeoNames.ARGEO_USER_PROFILE);
- for (String jcrProperty : propertyToAttributes.keySet())
- jcrToLdap(userProfile, jcrProperty, ctx);
- if (log.isDebugEnabled())
- log.debug("Mapped " + userProfile + " to "
- + ctx.getDn());
- } catch (RepositoryException e) {
- throw new ArgeoException("Cannot synchronize JCR and LDAP",
- e);
- } finally {
- session.logout();
- }
- }
- });
- }
-
- protected String usernameToHomePath(String username) {
- return homeBasePath + '/' + JcrUtils.firstCharsToPath(username, 2)
- + '/' + username;
- }
-
- protected void ldapToJcr(Node userProfile, String jcrProperty,
- DirContextOperations ctx) {