Update of 
/var/cvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/services/community/security
In directory 
james.mmbase.org:/tmp/cvs-serv13333/src/java/com/finalist/cmsc/services/community/security

Modified Files:
        UserNotFoundException.java Authority.java 
        AuthorityService.java PermissionService.java 
        Authentication.java UserDetailsHibernateService.java 
        AuthenticationService.java AuthenticationHibernateService.java 
        AuthorityHibernateService.java 
Log Message:



See also: 
http://cvs.mmbase.org/viewcvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/services/community/security


Index: UserNotFoundException.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/services/community/security/UserNotFoundException.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- UserNotFoundException.java  25 Jan 2008 13:03:38 -0000      1.1
+++ UserNotFoundException.java  29 Jan 2008 09:59:40 -0000      1.2
@@ -15,6 +15,8 @@
  */
 public class UserNotFoundException extends Exception {
 
+       private static final long serialVersionUID = 1L;
+
     public UserNotFoundException() {
         super();
     }


Index: Authority.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/services/community/security/Authority.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- Authority.java      25 Jan 2008 13:03:38 -0000      1.1
+++ Authority.java      29 Jan 2008 09:59:40 -0000      1.2
@@ -41,7 +41,7 @@
     @ManyToMany(mappedBy = "authorities")
     private Set<Authentication> authentications = new 
HashSet<Authentication>();
     
-    @ManyToMany(mappedBy = "permissions")
+    @ManyToMany(mappedBy = "authorities")
     private Set<Permission> permissions = new HashSet<Permission>();
 
     public Long getId() {
@@ -90,11 +90,9 @@
     public int hashCode() {
         final int prime = 31;
         int result = 1;
-        result = prime * result
-                + ((name == null) ? 0 : name.hashCode());
+               result = prime * result + ((name == null) ? 0 : 
name.hashCode());
         return result;
     }
-    
     @Override
     public boolean equals(Object obj) {
         if (this == obj)
@@ -111,4 +109,6 @@
             return false;
         return true;
     }
+    
+    
 }


Index: AuthorityService.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/services/community/security/AuthorityService.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- AuthorityService.java       25 Jan 2008 13:03:38 -0000      1.1
+++ AuthorityService.java       29 Jan 2008 09:59:40 -0000      1.2
@@ -45,16 +45,18 @@
 
     /**
      * Does an authority exist?
+     * 
      * @param authorityName
      * @return boolean true if the authority exists, otherwise false
      */
     boolean authorityExists(String authorityName);
 
     /**
+     * Finds the authoritdy 
      * @param authorityName
      * @return Authority with the requested name (if it exists)
      */
-    Authority findAuthorityByAuthorityName(String authorityName);
+    Authority findAuthorityByName(String authorityName);
 
 //    boolean isAdminAuthority(String authorityName);
 //    void addAuthority(String parentName, String childName);


Index: PermissionService.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/services/community/security/PermissionService.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- PermissionService.java      25 Jan 2008 13:03:38 -0000      1.1
+++ PermissionService.java      29 Jan 2008 09:59:40 -0000      1.2
@@ -9,11 +9,9 @@
 */
 package com.finalist.cmsc.services.community.security;
 
-import java.util.Map;
-import java.util.Set;
-
-
-
+/**
+ * @author Remco Bos
+ */
 public interface PermissionService {
 
 //    String getAllPermission();


Index: Authentication.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/services/community/security/Authentication.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- Authentication.java 25 Jan 2008 13:03:38 -0000      1.1
+++ Authentication.java 29 Jan 2008 09:59:40 -0000      1.2
@@ -38,8 +38,10 @@
     private Long id;
     
     @Column(unique = true)
-    private String userName;
+    private String userId;
+    
     private String password;
+    
     private boolean enabled;
     
     @ManyToMany
@@ -57,11 +59,11 @@
         this.id = id;
     }
     
-    public String getUserName() {
-        return userName;
+    public String getUserId() {
+        return userId;
     }
-    public void setUserName(String userName) {
-        this.userName = userName;
+    public void setUserId(String userId) {
+        this.userId = userId;
     }
     
     public String getPassword() {
@@ -91,16 +93,16 @@
         authorities.remove(authority);
         authority.getAuthentications().remove(this);
     }
-
     @Override
     public int hashCode() {
         final int prime = 31;
         int result = 1;
         result = prime * result
-                + ((userName == null) ? 0 : userName.hashCode());
+                               + ((password == null) ? 0 : 
password.hashCode());
+               result = prime * result
+                               + ((userId == null) ? 0 : userId.hashCode());
         return result;
     }
-
     @Override
     public boolean equals(Object obj) {
         if (this == obj)
@@ -110,11 +112,18 @@
         if (getClass() != obj.getClass())
             return false;
         final Authentication other = (Authentication) obj;
-        if (userName == null) {
-            if (other.userName != null)
+               if (password == null) {
+                       if (other.password != null)
                 return false;
-        } else if (!userName.equals(other.userName))
+               } else if (!password.equals(other.password))
+                       return false;
+               if (userId == null) {
+                       if (other.userId != null)
+                               return false;
+               } else if (!userId.equals(other.userId))
             return false;
         return true;
     }
+    
+    
 }


Index: UserDetailsHibernateService.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/services/community/security/UserDetailsHibernateService.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- UserDetailsHibernateService.java    25 Jan 2008 13:03:38 -0000      1.1
+++ UserDetailsHibernateService.java    29 Jan 2008 09:59:40 -0000      1.2
@@ -48,14 +48,14 @@
 
         /* Get authorities */
         Set<Authority> authorities = authentication.getAuthorities();
-        List grantedAuthorities = new ArrayList();
+        List<GrantedAuthority> grantedAuthorities = new 
ArrayList<GrantedAuthority>();
         for (Authority authority : authorities) {
             grantedAuthorities.add(new 
GrantedAuthorityImpl(authority.getName()));
         }
         GrantedAuthority[] grantedAuthorityArray = (GrantedAuthority[]) 
grantedAuthorities.toArray(new GrantedAuthority[grantedAuthorities.size()]);
 
         /* Create user object */
-        User user = new User(authentication.getUserName(), 
authentication.getPassword(), authentication.isEnabled(), true, true, true, 
grantedAuthorityArray);
+        User user = new User(authentication.getUserId(), 
authentication.getPassword(), authentication.isEnabled(), true, true, true, 
grantedAuthorityArray);
         return user;
     }
 


Index: AuthenticationService.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/services/community/security/AuthenticationService.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- AuthenticationService.java  25 Jan 2008 13:03:38 -0000      1.1
+++ AuthenticationService.java  29 Jan 2008 09:59:40 -0000      1.2
@@ -17,90 +17,97 @@
     /**
      * Create an authentication
      *
-     * @param userName
+     * @param userId
      * @param password
      */
-    void createAuthentication(String userName, String password);
+    void createAuthentication(String userId, String password);
 
     /**
      * Update the login information for the authentication (typically called 
by the user)
      *
-     * @param userName
+     * @param userId
      * @param oldPassword
      * @param newPassword
      */
-    void updateAuthentication(String userName, String oldPassword, String 
newPassword);
+    void updateAuthentication(String userId, String oldPassword, String 
newPassword);
 
     /**
      * Set the login information for an authentication (typically called by an 
admin user)
      *
-     * @param userName
+     * @param userId
      * @param newPassword
      */
-    void updateAuthenticationPassword(String userName, String newPassword);
+    void updateAuthenticationPassword(String userId, String newPassword);
 
 
     /**
      * Delete an authentication entry
      * TODO if a authentication is deleted, what should happen with the user's 
content (in other systems)?
      *
-     * @param userName
+     * @param userId
      */
-    void deleteAuthentication(String userName);
+    void deleteAuthentication(String userId);
 
     /**
      * Check if the given authentication exists
      *
-     * @param userName
+     * @param userId
      * @return boolean returns true if a user exists, otherwise it returns 
false
      */
-    boolean authenticationExists(String userName);
+    boolean authenticationExists(String userId);
 
     /**
      * Enable or disable a authentication
      *
-     * @param userName
+     * @param userId
      * @param enabled
      */
-    void setAuthenticationEnabled(String userName, boolean enabled);
+    void setAuthenticationEnabled(String userId, boolean enabled);
 
     /**
      * Is an authentication enabled or disabled?
      *
-     * @param userName
+     * @param userId
      * @return boolean returns true if a user is enabled, otherwise it returns 
false
      */
-    boolean isAuthenticationEnabled(String userName);
+    boolean isAuthenticationEnabled(String userId);
 
     /**
      * Carry out an authentication attempt
      *
-     * @param userName
+     * @param userId
      * @param password
      */
-    boolean authenticate(String userName, String password);
+    boolean authenticate(String userId, String password);
 
     /**
      * Adds an authority to a user
      *
-     * @param userName
+     * @param userId
      * @param authority
      */
-    void addAuthorityToUser(String userName, String authority);
+    void addAuthorityToUser(String userId, String authority);
 
     /**
      * Removes an authority from a user
      *
-     * @param userName
+     * @param userId
      * @param authority
      */
-    void removeAuthorityFromUser(String userName, String authority);
+    void removeAuthorityFromUser(String userId, String authority);
 
     /**
-     * Finds an authentication object for this userName
+     * Finds an authentication object for this userId
      * 
-     * @param userName
+     * @param userId
      * @return authentication
      */
-    Authentication findAuthentication(String userName);
+    Authentication findAuthentication(String userId);
+
+    /**
+     * Finds an authentication id for this userId
+     * @param userId
+     * @return authenticationId
+     */ 
+       Long getAuthenticationIdForUserId(String userId);
 }


Index: AuthenticationHibernateService.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/services/community/security/AuthenticationHibernateService.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- AuthenticationHibernateService.java 25 Jan 2008 13:03:38 -0000      1.1
+++ AuthenticationHibernateService.java 29 Jan 2008 09:59:40 -0000      1.2
@@ -30,99 +30,107 @@
 
     /** [EMAIL PROTECTED] */
     @Transactional
-    public void createAuthentication(String userName, String password) {
+    public void createAuthentication(String userId, String password) {
         Authentication authentication = new Authentication();
-        authentication.setUserName(userName);
-        authentication.setPassword(encodePassword(password, userName));
+        authentication.setUserId(userId);
+        authentication.setPassword(encodePassword(password, userId));
         authentication.setEnabled(true);
         getSession().save(authentication);
     }
 
     /** [EMAIL PROTECTED] */
     @Transactional
-    public void updateAuthentication(String userName, String oldPassword, 
String newPassword) {
-        Authentication authentication = findAuthenticationByUserName(userName);
+    public void updateAuthentication(String userId, String oldPassword, String 
newPassword) {
+        Authentication authentication = findAuthenticationByUserId(userId);
         if (authentication.getPassword().equals(oldPassword)) {
-            authentication.setPassword(encodePassword(newPassword, userName));
+            authentication.setPassword(encodePassword(newPassword, userId));
             getSession().flush();
         }
     }
 
     /** [EMAIL PROTECTED] */
     @Transactional
-    public void updateAuthenticationPassword(String userName, String 
newPassword) {
-        Authentication authentication = findAuthenticationByUserName(userName);
-        authentication.setPassword(encodePassword(newPassword, userName));
+    public void updateAuthenticationPassword(String userId, String 
newPassword) {
+        Authentication authentication = findAuthenticationByUserId(userId);
+        authentication.setPassword(encodePassword(newPassword, userId));
         getSession().flush();
     }
 
     /** [EMAIL PROTECTED] */
     @Transactional
-    public void deleteAuthentication(String userName) {
-        Authentication authentication = findAuthenticationByUserName(userName);
+    public void deleteAuthentication(String userId) {
+        Authentication authentication = findAuthenticationByUserId(userId);
         getSession().delete(authentication);
     }
 
     /** [EMAIL PROTECTED] */
     @Transactional(readOnly = true)
-    public boolean authenticationExists(String userName) {
-        Authentication authentication = findAuthenticationByUserName(userName);
+    public boolean authenticationExists(String userId) {
+        Authentication authentication = findAuthenticationByUserId(userId);
         return authentication != null;
     }
 
     /** [EMAIL PROTECTED] */
     @Transactional
-    public void setAuthenticationEnabled(String userName, boolean enabled) {
-        Authentication authentication = findAuthenticationByUserName(userName);
+    public void setAuthenticationEnabled(String userId, boolean enabled) {
+        Authentication authentication = findAuthenticationByUserId(userId);
         authentication.setEnabled(enabled);
         getSession().flush();
     }
 
     /** [EMAIL PROTECTED] */
     @Transactional(readOnly = true)
-    public boolean isAuthenticationEnabled(String userName) {
-        Authentication authentication = findAuthenticationByUserName(userName);
+    public boolean isAuthenticationEnabled(String userId) {
+        Authentication authentication = findAuthenticationByUserId(userId);
         return authentication.isEnabled();
     }
 
     /** [EMAIL PROTECTED] */
     @Transactional(readOnly = true)
-    public boolean authenticate(String userName, String password) {
-        Authentication authentication = findAuthenticationByUserName(userName);
+    public boolean authenticate(String userId, String password) {
+        Authentication authentication = findAuthenticationByUserId(userId);
         return authentication.getPassword().equals(password);
     }
 
     /** [EMAIL PROTECTED] */
     @Transactional
-    public void addAuthorityToUser(String userName, String authorityName) {
-        Authentication authentication = findAuthenticationByUserName(userName);
-        Authority authority = 
authorityService.findAuthorityByAuthorityName(authorityName);
+    public void addAuthorityToUser(String userId, String authorityName) {
+        Authentication authentication = findAuthenticationByUserId(userId);
+        Authority authority = 
authorityService.findAuthorityByName(authorityName);
         authentication.addAuthority(authority);
         getSession().flush();
     }
     
     /** [EMAIL PROTECTED] */
     @Transactional
-    public void removeAuthorityFromUser(String userName, String authorityName) 
{
-        Authentication authentication = findAuthenticationByUserName(userName);
-        Authority authority = 
authorityService.findAuthorityByAuthorityName(authorityName);
+    public void removeAuthorityFromUser(String userId, String authorityName) {
+        Authentication authentication = findAuthenticationByUserId(userId);
+        Authority authority = 
authorityService.findAuthorityByName(authorityName);
         authentication.removeAuthority(authority);
         getSession().flush();
     }
 
     /** [EMAIL PROTECTED] */
     @Transactional(readOnly = true)
-    public Authentication findAuthentication(String userName) {
-        return findAuthenticationByUserName(userName);
+    public Authentication findAuthentication(String userId) {
+        return findAuthenticationByUserId(userId);
     }
     
-    private Authentication findAuthenticationByUserName(String userName) {
+    /** [EMAIL PROTECTED] */
+    @Transactional(readOnly = true)
+       public Long getAuthenticationIdForUserId(String userId) {
+       Authentication authentication = findAuthenticationByUserId(userId);
+       return authentication == null ? null : authentication.getId();
+       }
+
+       private Authentication findAuthenticationByUserId(String userId) {
         Criteria criteria = getSession()
                 .createCriteria(Authentication.class)
-                .add(Restrictions.eq("userName", userName));
+                .add(Restrictions.eq("userId", userId));
         return findAuthenticationByCriteria(criteria);
     }
 
+    @SuppressWarnings("unchecked")
     private Authentication findAuthenticationByCriteria(Criteria criteria) {
         List authenticationList = criteria.list();
         return authenticationList.size() == 1 ? (Authentication) 
authenticationList.get(0) : null;
@@ -137,5 +145,4 @@
     public void setAuthorityService(AuthorityService authorityService) {
         this.authorityService = authorityService;
     }
-
 }


Index: AuthorityHibernateService.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/services/community/security/AuthorityHibernateService.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- AuthorityHibernateService.java      25 Jan 2008 13:03:38 -0000      1.1
+++ AuthorityHibernateService.java      29 Jan 2008 09:59:40 -0000      1.2
@@ -30,32 +30,32 @@
 
     /** [EMAIL PROTECTED] */
     @Transactional
-    public void createAuthority(String parentName, String authorityName) {
+    public void createAuthority(String parentName, String name) {
         Authority authority = new Authority();
-        authority.setName(authorityName);
+        authority.setName(name);
         getSession().save(authority);
     }
 
     /** [EMAIL PROTECTED] */
     @Transactional
-    public void deleteAuthority(String authorityName) {
-        Authority authority = findAuthorityByAuthorityName(authorityName);
+    public void deleteAuthority(String name) {
+        Authority authority = findAuthorityByName(name);
         getSession().delete(authority);
     }
 
     /** [EMAIL PROTECTED] */
     @Transactional(readOnly = true)
-    public boolean authorityExists(String authorityName) {
-        Authority authority = findAuthorityByAuthorityName(authorityName);
+    public boolean authorityExists(String name) {
+        Authority authority = findAuthorityByName(name);
         return authority != null;
     }
 
     /** [EMAIL PROTECTED] */
     @Transactional(readOnly = true)
-    public Authority findAuthorityByAuthorityName(String authorityName) {
+    public Authority findAuthorityByName(String name) {
         Criteria criteria = getSession()
                 .createCriteria(Authority.class)
-                .add(Restrictions.eq("authorityName", authorityName));
+                .add(Restrictions.eq("name", name));
         return findAuthorityByCriteria(criteria);
     }
 
@@ -68,19 +68,21 @@
 
     /** [EMAIL PROTECTED] */
     @Transactional(readOnly = true)
-    public Set<String> getAuthorityNamesForUser(String userName) {
+    public Set<String> getAuthorityNamesForUser(String userId) {
         Criteria criteria = getSession()
                 .createCriteria(Authority.class)
                 .createCriteria("authentications")
-                .add(Restrictions.eq("userName", userName));
+                .add(Restrictions.eq("userId", userId));
         return findAuthorityNamesByCriteria(criteria);
     }
 
+    @SuppressWarnings("unchecked")
     private Authority findAuthorityByCriteria(Criteria criteria) {
         List authorities = criteria.list();
         return authorities.size() == 1 ? (Authority) authorities.get(0) : null;
     }
 
+    @SuppressWarnings("unchecked")
     private Set<String> findAuthorityNamesByCriteria(Criteria criteria) {
         List authorityList = criteria.list();
         Set<String> result = new HashSet<String>();
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to