]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/jcr/JcrUserDetails.java
Remove old interfaces
[lgpl/argeo-commons.git] / security / runtime / org.argeo.security.core / src / main / java / org / argeo / security / jcr / JcrUserDetails.java
index ea66b5ff74e529f03d2bb97b766253b51e227f7d..f7d016cf40cbd1983400c83adbd301e344a3d81e 100644 (file)
@@ -3,11 +3,6 @@ package org.argeo.security.jcr;
 import java.util.ArrayList;
 import java.util.List;
 
-import javax.jcr.Node;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-
-import org.argeo.ArgeoException;
 import org.springframework.security.GrantedAuthority;
 import org.springframework.security.GrantedAuthorityImpl;
 import org.springframework.security.userdetails.User;
@@ -29,41 +24,20 @@ public class JcrUserDetails extends User {
                return homePath;
        }
 
-       public static JcrUserDetails argeoUserToJcrUserDetails(
-                       JcrArgeoUser argeoUser) {
-               try {
-                       List<GrantedAuthority> gas = new ArrayList<GrantedAuthority>();
-                       for (String role : argeoUser.getRoles())
-                               gas.add(new GrantedAuthorityImpl(role));
-                       return new JcrUserDetails(argeoUser.getHome().getPath(),
-                                       argeoUser.getUsername(), argeoUser.getPassword(),
-                                       argeoUser.getEnabled(), true, true, true,
-                                       gas.toArray(new GrantedAuthority[gas.size()]));
-               } catch (Exception e) {
-                       throw new ArgeoException("Cannot convert " + argeoUser
-                                       + " to JCR user details", e);
+       public JcrUserDetails cloneWithNewRoles(List<String> roles) {
+               List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
+               for (String role : roles) {
+                       authorities.add(new GrantedAuthorityImpl(role));
                }
+               return new JcrUserDetails(homePath, getUsername(), getPassword(),
+                               isEnabled(), isAccountNonExpired(), isAccountNonExpired(),
+                               isAccountNonLocked(),
+                               authorities.toArray(new GrantedAuthority[authorities.size()]));
        }
 
-       public static JcrArgeoUser jcrUserDetailsToArgeoUser(Session userSession,
-                       JcrUserDetails jcrUserDetails) {
-               if (!userSession.getUserID().equals(jcrUserDetails.getUsername()))
-                       throw new ArgeoException("User session has user id "
-                                       + userSession.getUserID() + " while details has username "
-                                       + jcrUserDetails.getUsername());
-
-               Node userHome;
-               try {
-                       userHome = userSession.getNode(jcrUserDetails.getHomePath());
-               } catch (RepositoryException e) {
-                       throw new ArgeoException("Cannot retrieve user home with path "
-                                       + jcrUserDetails.getHomePath(), e);
-               }
-               List<String> roles = new ArrayList<String>();
-               for (GrantedAuthority ga : jcrUserDetails.getAuthorities())
-                       roles.add(ga.getAuthority());
-               return new JcrArgeoUser(userHome, jcrUserDetails.getPassword(), roles,
-                               jcrUserDetails.isEnabled());
-
+       public JcrUserDetails cloneWithNewPassword(String password) {
+               return new JcrUserDetails(homePath, getUsername(), password,
+                               isEnabled(), isAccountNonExpired(), isAccountNonExpired(),
+                               isAccountNonLocked(), getAuthorities());
        }
 }