From: Mathieu Baudier Date: Thu, 17 Mar 2011 17:03:20 +0000 (+0000) Subject: Introduce JCR / LDAP mapping X-Git-Tag: argeo-commons-2.1.30~1345 X-Git-Url: https://git.argeo.org/?a=commitdiff_plain;h=772c16a288d19cc10a320c3798b30d6d02f969ba;p=lgpl%2Fargeo-commons.git Introduce JCR / LDAP mapping git-svn-id: https://svn.argeo.org/commons/trunk@4319 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/jcr/JcrUserDetails.java b/security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/jcr/JcrUserDetails.java new file mode 100644 index 000000000..f200a28a4 --- /dev/null +++ b/security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/jcr/JcrUserDetails.java @@ -0,0 +1,23 @@ +package org.argeo.security.jcr; + +import org.springframework.security.GrantedAuthority; +import org.springframework.security.userdetails.User; + +public class JcrUserDetails extends User { + private static final long serialVersionUID = -3594542993773402380L; + private final String homePath; + + public JcrUserDetails(String homePath, String username, String password, + boolean enabled, boolean accountNonExpired, + boolean credentialsNonExpired, boolean accountNonLocked, + GrantedAuthority[] authorities) throws IllegalArgumentException { + super(username, password, enabled, accountNonExpired, + credentialsNonExpired, accountNonLocked, authorities); + this.homePath = homePath; + } + + public String getHomePath() { + return homePath; + } + +} diff --git a/security/runtime/org.argeo.security.ldap/pom.xml b/security/runtime/org.argeo.security.ldap/pom.xml index 9c222e9be..99b123c58 100644 --- a/security/runtime/org.argeo.security.ldap/pom.xml +++ b/security/runtime/org.argeo.security.ldap/pom.xml @@ -1,4 +1,5 @@ - + 4.0.0 org.argeo.commons.security @@ -53,6 +54,12 @@ 0.2.3-SNAPSHOT + + + org.argeo.dep.osgi + org.argeo.dep.osgi.jcr + + org.argeo.dep.osgi diff --git a/security/runtime/org.argeo.security.ldap/src/main/java/org/argeo/security/ldap/jcr/JcrUserDetailsContextMapper.java b/security/runtime/org.argeo.security.ldap/src/main/java/org/argeo/security/ldap/jcr/JcrUserDetailsContextMapper.java new file mode 100644 index 000000000..b5b77474c --- /dev/null +++ b/security/runtime/org.argeo.security.ldap/src/main/java/org/argeo/security/ldap/jcr/JcrUserDetailsContextMapper.java @@ -0,0 +1,25 @@ +package org.argeo.security.ldap.jcr; + +import javax.jcr.Session; + +import org.springframework.ldap.core.DirContextAdapter; +import org.springframework.ldap.core.DirContextOperations; +import org.springframework.security.GrantedAuthority; +import org.springframework.security.userdetails.UserDetails; +import org.springframework.security.userdetails.ldap.UserDetailsContextMapper; + +public class JcrUserDetailsContextMapper implements UserDetailsContextMapper { + private Session session; + + public UserDetails mapUserFromContext(DirContextOperations ctx, + String username, GrantedAuthority[] authority) { + // TODO Auto-generated method stub + return null; + } + + public void mapUserToContext(UserDetails user, DirContextAdapter ctx) { + // TODO Auto-generated method stub + + } + +} diff --git a/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/JcrUtils.java b/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/JcrUtils.java index d9eeb4998..8c6d6a78d 100644 --- a/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/JcrUtils.java +++ b/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/JcrUtils.java @@ -548,9 +548,29 @@ public class JcrUtils { return name.replace(':', '_'); } + /** Cleanly disposes a {@link Binary} even if it is null. */ public static void closeQuietly(Binary binary) { if (binary == null) return; binary.dispose(); } + + /** + * Creates depth from a string (typically a username) by adding levels based + * on its first characters: "aBcD",2 => a/aB + */ + public static String firstCharsToPath(String str, Integer nbrOfChars) { + if (str.length() < nbrOfChars) + throw new ArgeoException("String " + str + + " length must be greater or equal than " + nbrOfChars); + StringBuffer path = new StringBuffer(""); + StringBuffer curr = new StringBuffer(""); + for (int i = 0; i < nbrOfChars; i++) { + curr.append(str.charAt(i)); + path.append(curr); + if (i < nbrOfChars - 1) + path.append('/'); + } + return path.toString(); + } }