View Javadoc

1   /*
2    * To change this template, choose Tools | Templates
3    * and open the template in the editor.
4    */
5   /*
6   jGuard is a security framework based on top of jaas (java authentication and authorization security).
7   it is written for web applications, to resolve simply, access control problems.
8   version $Name$
9   http://sourceforge.net/projects/jguard/
10  
11  Copyright (C) 2004  Charles GAY
12  
13  This library is free software; you can redistribute it and/or
14  modify it under the terms of the GNU Lesser General Public
15  License as published by the Free Software Foundation; either
16  version 2.1 of the License, or (at your option) any later version.
17  
18  This library is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21  Lesser General Public License for more details.
22  
23  You should have received a copy of the GNU Lesser General Public
24  License along with this library; if not, write to the Free Software
25  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26  
27  
28  jGuard project home page:
29  http://sourceforge.net/projects/jguard/
30  
31  */
32  package net.sf.jguard.ext.organization;
33  
34  
35  import net.sf.jguard.core.organization.Organization;
36  import net.sf.jguard.core.provisioning.SubjectTemplate;
37  import net.sf.jguard.ext.authentication.manager.HibernateConverterUtils;
38  import net.sf.jguard.ext.provisioning.PersistedSubjectTemplate;
39  
40  /**
41  *
42  * @author <a href="mailto:diabolo512@users.sourceforge.net">Charles Gay</a>
43  */
44  public class PersistedOrganization extends Organization{
45      
46      private PersistedSubjectTemplate persistedSubjectTemplate;
47      public PersistedOrganization(){
48          super();
49      }
50      
51      public PersistedOrganization(Organization organization){
52          super();
53          
54              this.id = organization.getId();
55              this.principals = HibernateConverterUtils.getPersistedPrincipals(organization.getPrincipals());
56              this.persistedSubjectTemplate = new PersistedSubjectTemplate(organization.getSubjectTemplate());
57              
58              this.credentials = organization.getCredentials();
59              this.users = organization.getUsers();
60          
61      }
62      
63       
64     
65          /** transform persistedOrganization into an organization with java.security.Principal subclasses instances
66           * and a SubjectTemplate containing also some java.security.Principal subclassses instances.
67           * so, in this method, Principal used for persistance (internal use) is transformed into a java.security.Principal subclass
68           * for external use.
69           * @param persistedOrganization
70           * @return
71           */
72           public Organization toOrganization(){
73          
74              Organization orga = new Organization();
75              orga.setId(getId());
76              orga.setPrincipals(HibernateConverterUtils.getjavaSecurityPrincipals(getPrincipals()));
77              orga.setCredentials(getCredentials());
78              SubjectTemplate st = persistedSubjectTemplate.toSubjectTemplate();
79              orga.setSubjectTemplate(st);
80              orga.setUsers(getUsers());
81              return orga;
82          }
83           
84           public boolean equals(Object other) {
85               if (this == other){
86                   return true;
87               }
88               if ( !(other instanceof PersistedOrganization) ){
89                    return false;
90               }
91  
92               final PersistedOrganization porganization = (PersistedOrganization)other;
93               if(getPersistedSubjectTemplate().equals(porganization.getPersistedSubjectTemplate())&&
94                  credentials.equals(porganization.getCredentials())&&
95                  principals.equals(porganization.getPrincipals())){
96                   return true;
97               }
98               return false;
99           }
100 
101     public int hashCode() {
102         int hash = 7;
103         hash = 23 * hash + (this.persistedSubjectTemplate != null ? this.persistedSubjectTemplate.hashCode() : 0);
104         hash = 23 * hash + (this.credentials != null ? this.credentials.hashCode() : 0);
105         hash = 23 * hash + (this.principals != null ? this.principals.hashCode() : 0);
106         return hash;
107     }
108 
109     public PersistedSubjectTemplate getPersistedSubjectTemplate() {
110         return persistedSubjectTemplate;
111     }
112 
113     public void setPersistedSubjectTemplate(PersistedSubjectTemplate persistedSubjectTemplate) {
114         this.persistedSubjectTemplate = persistedSubjectTemplate;
115     }
116 
117 } 
118