-
- 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 {
- throw new ArgeoException("We should never reach this point");
- // 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);
-
- // assign default values
- if (!userProfile.hasProperty(Property.JCR_DESCRIPTION))
- userProfile.setProperty(Property.JCR_DESCRIPTION, "");
- if (!userProfile.hasProperty(Property.JCR_TITLE))
- userProfile.setProperty(Property.JCR_TITLE, userProfile
- .getProperty(ARGEO_FIRST_NAME).getString()
- + " "
- + userProfile.getProperty(ARGEO_LAST_NAME).getString());
-
- session.save();
- if (log.isTraceEnabled())
- log.trace("Mapped " + ctx.getDn() + " to " + userProfile);
- return userHomePath;
- } catch (Exception e) {
- JcrUtils.discardQuietly(session);
- throw new ArgeoException("Cannot synchronize JCR and LDAP", e);
- }
- }
-
- 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;
- try {
- Node userProfile = session.getNode(jcrUserDetails.getHomePath()
- + '/' + ARGEO_PROFILE);
- for (String jcrProperty : propertyToAttributes.keySet())
- jcrToLdap(userProfile, jcrProperty, ctx);
-
- if (log.isTraceEnabled())
- log.trace("Mapped " + userProfile + " to " + ctx.getDn());