Introduce JCR / LDAP mapping
authorMathieu Baudier <mbaudier@argeo.org>
Thu, 17 Mar 2011 17:03:20 +0000 (17:03 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Thu, 17 Mar 2011 17:03:20 +0000 (17:03 +0000)
git-svn-id: https://svn.argeo.org/commons/trunk@4319 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/jcr/JcrUserDetails.java [new file with mode: 0644]
security/runtime/org.argeo.security.ldap/pom.xml
security/runtime/org.argeo.security.ldap/src/main/java/org/argeo/security/ldap/jcr/JcrUserDetailsContextMapper.java [new file with mode: 0644]
server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/JcrUtils.java

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 (file)
index 0000000..f200a28
--- /dev/null
@@ -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;
+       }
+
+}
index 9c222e9be815e54844a7fd3d47116ede30da7b3d..99b123c58fd1685d939cb2532f620d911f28c3b0 100644 (file)
@@ -1,4 +1,5 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
                <groupId>org.argeo.commons.security</groupId>
                        <version>0.2.3-SNAPSHOT</version>
                </dependency>
 
+               <!-- JCR -->
+               <dependency>
+                       <groupId>org.argeo.dep.osgi</groupId>
+                       <artifactId>org.argeo.dep.osgi.jcr</artifactId>
+               </dependency>
+
                <!-- Spring -->
                <dependency>
                        <groupId>org.argeo.dep.osgi</groupId>
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 (file)
index 0000000..b5b7747
--- /dev/null
@@ -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
+
+       }
+
+}
index d9eeb4998d6c1a648fba54c719661bf65450a62a..8c6d6a78db2355377d0b0e0a7bf6789054178544 100644 (file)
@@ -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();
+       }
 }