Improve user admin
[lgpl/argeo-commons.git] / security / runtime / org.argeo.security.core / src / main / java / org / argeo / security / jcr / JcrUserDetails.java
index a59eabc0a8dd862083c3bb027bce5524d91b6ce2..05ae165e03fbcccd0d63be4679745b787742f567 100644 (file)
@@ -5,8 +5,10 @@ import java.util.List;
 
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
+import javax.jcr.Session;
 
 import org.argeo.jcr.ArgeoNames;
+import org.argeo.jcr.JcrUtils;
 import org.springframework.security.BadCredentialsException;
 import org.springframework.security.DisabledException;
 import org.springframework.security.GrantedAuthority;
@@ -46,6 +48,24 @@ public class JcrUserDetails extends User implements ArgeoNames {
                securityWorkspace = userProfile.getSession().getWorkspace().getName();
        }
 
+       /**
+        * Convenience constructor
+        * 
+        * @param session
+        *            the security session
+        * @param username
+        *            the username
+        * @param password
+        *            the password, can be null
+        * @param authorities
+        *            the granted authorities
+        */
+       public JcrUserDetails(Session session, String username, String password,
+                       GrantedAuthority[] authorities) throws RepositoryException {
+               this(JcrUtils.getUserProfile(session, username),
+                               password != null ? password : "", authorities);
+       }
+
        /**
         * Check the account status in JCR, throwing the exceptions expected by
         * Spring security if needed.