KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > connectors > authentication > PrincipalAuthKey


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.connectors.authentication;
25
26 import com.sun.logging.LogDomains;
27
28 import java.util.logging.*;
29 import java.io.Serializable JavaDoc;
30
31
32 /**
33  * This class represents the key for security Maps.
34  * This is used as key in storing the backend principals as value in the
35  * security map in ConnectorRegistry
36  * @author Srikanth P
37  */

38
39 public class PrincipalAuthKey implements Serializable JavaDoc {
40
41     private String JavaDoc rarName_ = null;
42     private String JavaDoc poolName_ = null;
43     private String JavaDoc principalName_ = null;
44     private String JavaDoc userGroup_ = null;
45
46     static Logger _logger = LogDomains.getLogger(LogDomains.RSR_LOGGER);
47
48     /**
49      * Constructor
50      * @param rarName Name of the rar
51      * @param poolName Nmae of the pool
52      * @param principalName Name of the principal to which security mapping
53      * is to be done.
54      * @param userGroupName Name of the userGroup to which security mapping
55      * is to be done.
56      */

57
58     public PrincipalAuthKey(String JavaDoc rarName,String JavaDoc poolName,
59                         String JavaDoc principalName,String JavaDoc userGroupName){
60         rarName_ = rarName;
61         poolName_ = poolName;
62         principalName_ = principalName;
63         userGroup_ = userGroupName;
64         _logger.log(Level.FINE,"Constructor: PrincipalAuthKey");
65     }
66
67     /**
68      * Generates Hashcode . Overloaded method from "Object" class.
69      * @return hashCode
70      */

71
72     public int hashCode() {
73         return (rarName_+poolName_+principalName_+userGroup_).hashCode();
74     }
75
76     /** Checks whether two strings are equal including the null string
77      * cases.
78      */

79
80     private boolean isEqual(String JavaDoc in, String JavaDoc out) {
81         if(in == null && out == null) {
82             return true;
83         }
84         if(in == null || out == null) {
85             return false;
86         }
87         return (out.equals(in));
88     }
89
90     /**
91      * Checks for equality.
92      * Overloaded equals() from Object class. Used when comparing strings
93      * for equality.
94      * @param other Object to compare
95      * @return true if the objects are equal
96      * false if not so.
97      */

98
99     public boolean equals(Object JavaDoc other) {
100         if( other == null || !(other instanceof PrincipalAuthKey)) {
101             if ( _logger.isLoggable(Level.FINE) ) {
102                 String JavaDoc msg = "equals method PrincipalAuthKey: parameter not ";
103                 String JavaDoc msg1= "PrincipalAuthKey. Equals fails";
104                 _logger.log(Level.FINE,msg+msg1);
105             }
106         return false;
107         }
108         PrincipalAuthKey otherkey = (PrincipalAuthKey)other;
109
110         if(isEqual(this.rarName_,otherkey.rarName_) &&
111                  isEqual(this.poolName_,otherkey.poolName_) &&
112                  isEqual(this.principalName_,otherkey.principalName_) &&
113                  isEqual(this.userGroup_,otherkey.userGroup_)) {
114             _logger.log(Level.FINE,"equal method of PrincipalAuthKey succeeds");
115             return true;
116         } else {
117             _logger.log(Level.FINE,"equals method of PrincipalAuthKey fails");
118             return false;
119         }
120     }
121 }
122
Popular Tags