- byte[] arr = (byte[]) ctx
- .getAttributeSortedStringSet(passwordAttribute).first();
- JcrUserDetails userDetails = new JcrUserDetails(
- userHomePathT.toString(), username, new String(arr), true,
- true, true, true, authorities);
- // erase password
- Arrays.fill(arr, (byte) 0);
- return userDetails;
- }
-
- /** @return path to the user home node */
- protected String mapLdapToJcr(String username, DirContextOperations ctx) {
- // Session session = null;
- try {
- // Repository nodeRepo = JcrUtils.getRepositoryByAlias(
- // repositoryFactory, ArgeoJcrConstants.ALIAS_NODE);
- // session = nodeRepo.login();
- Node userHome = JcrUtils.getUserHome(session, username);
- if (userHome == null)
- userHome = JcrUtils.createUserHome(session, homeBasePath,
- username);
- String userHomePath = userHome.getPath();
- Node userProfile = userHome.getNode(ARGEO_PROFILE);
- if (userHome.hasNode(ARGEO_PROFILE)) {
- userProfile = userHome.getNode(ARGEO_PROFILE);
- } else {
- userProfile = userHome.addNode(ARGEO_PROFILE);
- userProfile.addMixin(NodeType.MIX_TITLE);
- userProfile.addMixin(NodeType.MIX_CREATED);
- userProfile.addMixin(NodeType.MIX_LAST_MODIFIED);
- }
- for (String jcrProperty : propertyToAttributes.keySet())
- ldapToJcr(userProfile, jcrProperty, ctx);
- session.save();
- if (log.isDebugEnabled())
- log.debug("Mapped " + ctx.getDn() + " to " + userProfile);
- return userHomePath;
- } catch (Exception e) {
- JcrUtils.discardQuietly(session);
- throw new ArgeoException("Cannot synchronize JCR and LDAP", e);
- } finally {
- // JcrUtils.logoutQuietly(session);
- }
- }
-
- public void mapUserToContext(UserDetails user, final DirContextAdapter ctx) {
- if (!(user instanceof JcrUserDetails))
- throw new ArgeoException("Unsupported user details: "
- + user.getClass());
-
- ctx.setAttributeValues("objectClass", userClasses);
- ctx.setAttributeValue(usernameAttribute, user.getUsername());
- ctx.setAttributeValue(passwordAttribute,
- encodePassword(user.getPassword()));
-
- final JcrUserDetails jcrUserDetails = (JcrUserDetails) user;
- // systemExecutor.execute(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()
- + '/' + ARGEO_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();
- }