KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sape > carbon > services > security > auth > weblogic61 > WeblogicCarbonGroup


1 /*
2  * The contents of this file are subject to the Sapient Public License
3  * Version 1.0 (the "License"); you may not use this file except in compliance
4  * with the License. You may obtain a copy of the License at
5  * http://carbon.sf.net/License.html.
6  *
7  * Software distributed under the License is distributed on an "AS IS" basis,
8  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
9  * the specific language governing rights and limitations under the License.
10  *
11  * The Original Code is The Carbon Component Framework.
12  *
13  * The Initial Developer of the Original Code is Sapient Corporation
14  *
15  * Copyright (C) 2003 Sapient Corporation. All Rights Reserved.
16  */

17
18 package org.sape.carbon.services.security.auth.weblogic61;
19
20 import java.security.Principal JavaDoc;
21 import java.security.acl.Group JavaDoc;
22 import java.util.Enumeration JavaDoc;
23 import java.util.Hashtable JavaDoc;
24
25 import weblogic.security.acl.BasicRealm;
26 import weblogic.security.acl.DefaultGroupImpl;
27
28 /**
29  * Weblogic Wrapper Object around a standard
30  * <code>java.security.acl.Group</code>.
31  *
32  * <p>
33  * The Weblogic SPI has it's own version of group that must be returned,
34  * so this object wraps the standard java implementation of group in the
35  * Weblogic specific API.
36  * </p>
37  *
38  * @author $Author: dvoet $ $Date: 2003/05/05 21:21:34 $
39  * @version $Revision: 1.3 $
40  *
41  * @see java.security.acl.Group
42  * @since carbon 1.2
43  */

44 public class WeblogicCarbonGroup extends DefaultGroupImpl {
45     /** Holds the realm this group is a part of. */
46     protected WeblogicCarbonRealm weblogicCarbonRealm;
47
48     /** Holds the group this is adapting to. */
49     protected Group JavaDoc group;
50
51     /**
52      * Constructs a new Weblogic specific group in a realm wrapping a
53      * standard group object.
54      *
55      * @param group the group to wrap
56      * @param realm the weblogic realm this group belongs to
57      */

58     WeblogicCarbonGroup(Group JavaDoc group, WeblogicCarbonRealm realm) {
59         super(group.getName());
60
61         this.weblogicCarbonRealm = realm;
62         this.group = group;
63     }
64
65     /**
66      * Returns the class that users in this group implement.
67      *
68      * @return the class users in this group implement
69      */

70     protected Class JavaDoc getUserClass() {
71         return WeblogicCarbonUser.class;
72     }
73
74     /**
75      * Passes through to underlying group object.
76      *
77      * @return name of the group
78      */

79     public String JavaDoc getName() {
80         return this.group.getName();
81     }
82
83     /**
84      * Passes through to underlying group object.
85      *
86      * @param user the principal to add to this group
87      *
88      * @return <code>true</code> if the user store changed as a result of
89      * the call
90      */

91     public boolean addMember(Principal JavaDoc user) {
92         return this.group.addMember(user);
93     }
94
95     /**
96      * Passes through to underlying group object.
97      *
98      * @param user the principal to remove to this group
99      *
100      * @return <code>true</code> if the user store changed as a result of
101      * the call
102      */

103     public boolean removeMember(Principal JavaDoc user) {
104         return this.group.removeMember(user);
105     }
106
107     /**
108      * Passes through to underlying group object.
109      *
110      * @param member the principal to check membership of.
111      *
112      * @return if the principal is a member of this group
113      */

114     public boolean isMember(Principal JavaDoc member) {
115         return this.group.isMember(member);
116     }
117
118     /**
119      * Converts all underlying principal objects into either
120      * <code>WeblogicCarbonGroup</code> or
121      * <code>WeblogicCarbonUser</code> objects.
122      *
123      * @return all members of this group
124      */

125     public Enumeration JavaDoc members() {
126         Hashtable JavaDoc groupMembers = new Hashtable JavaDoc();
127         Enumeration JavaDoc membersEnumeration = this.group.members();
128
129         while (membersEnumeration.hasMoreElements()) {
130             Principal JavaDoc currentMember =
131                 (Principal JavaDoc) membersEnumeration.nextElement();
132
133             if (currentMember instanceof Group JavaDoc) {
134                 groupMembers.put(
135                     currentMember.getName(),
136                     new WeblogicCarbonGroup(
137                         (Group JavaDoc) currentMember,
138                         (WeblogicCarbonRealm) getRealm()));
139             } else {
140                 groupMembers.put(
141                     currentMember.getName(),
142                     new WeblogicCarbonUser(
143                         currentMember, (WeblogicCarbonRealm) getRealm()));
144             }
145         }
146
147         return groupMembers.elements();
148     }
149
150     /**
151      * Returns the Realm associated with this group object.
152      *
153      * @return the realm associated with this objectfs
154      */

155     public BasicRealm getRealm() {
156         return weblogicCarbonRealm;
157     }
158 }
159
Popular Tags