KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sape > carbon > services > security > auth > weblogic7 > WeblogicJaasCarbonLoginModule


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.weblogic7;
19
20 import java.security.Principal JavaDoc;
21 import java.security.acl.Group JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.Set JavaDoc;
24
25 import javax.security.auth.login.LoginException JavaDoc;
26
27 import org.sape.carbon.core.exception.ExceptionUtility;
28
29 import org.sape.carbon.services.security.auth.jaas.JaasCarbonLoginModule;
30 import org.sape.carbon.services.security.management.SecurityManagementDataStoreException;
31 import org.sape.carbon.services.security.management.UnknownPrincipalException;
32
33 import weblogic.security.principal.WLSGroupImpl;
34 import weblogic.security.principal.WLSUserImpl;
35
36 /**
37  * Extension of the <code>JaasCarbonLoginModule</code> to use Weblogic
38  * specific implementations of the User and Group objects.
39  *
40  * <p>
41  * This object extends the base class and makes sure to return weblogic
42  * implementations of the user and group objects. Generic
43  * implementations will cause Weblogic to throw a
44  * "java.lang.SecurityException: Invalid Subject" exception.
45  * </p>
46  *
47  * @author $Author: dvoet $ $Date: 2003/10/28 19:02:00 $
48  * @version $Revision: 1.4 $
49  *
50  * @since carbon 1.2
51  */

52 public class WeblogicJaasCarbonLoginModule extends JaasCarbonLoginModule {
53     /**
54      * Retreives the user, wraps it in a <code>WLSUserImpl</code> object,
55      * and adds it to the <code>principalsForSubject</code> set.
56      *
57      * @param username the name of the user to get the principal for.
58      *
59      * @see weblogic.security.principal.WLSUserImpl
60      */

61     protected void addMainPrincipal(String JavaDoc username) throws LoginException JavaDoc {
62         try {
63             WLSUserImpl user =
64                 new WLSUserImpl(userManager.retreiveUser(username).getName());
65             
66             principalsForSubject.add(user);
67         } catch (SecurityManagementDataStoreException smdse) {
68             throw new LoginException JavaDoc(
69                 "Caught SecurityManagementDataStoreException retrieving user: " +
70                 ExceptionUtility.printStackTracesToString(smdse));
71         }
72     }
73
74     /**
75      * Retreives the containing groups, wraps them in a
76      * <code>WLSGroupImpl</code> object, and adds it to the
77      * <code>principalsForSubject</code> set.
78      *
79      * @param username the name of the user to get the containing groups
80      * for
81      *
82      * @throws LoginException DOCUMENT ME!
83      *
84      * @see weblogic.security.principal.WLSGroupImpl
85      */

86     protected void addContainingGroups(String JavaDoc username)
87         throws LoginException JavaDoc {
88
89         try {
90             Principal JavaDoc user = userManager.retreiveUser(username);
91
92             Set JavaDoc groups = userManager.retreiveGroups(user);
93             Iterator JavaDoc groupsIterator = groups.iterator();
94
95             while (groupsIterator.hasNext()) {
96                 Group JavaDoc nextGroup = (Group JavaDoc) groupsIterator.next();
97                 principalsForSubject.add(
98                     new WLSGroupImpl(nextGroup.getName()));
99             }
100         } catch (SecurityManagementDataStoreException smdse) {
101             throw new LoginException JavaDoc(
102                 "Caught SecurityManagementDataStoreException retrieving user or groups: " +
103                 ExceptionUtility.printStackTracesToString(smdse));
104         } catch (UnknownPrincipalException e) {
105             throw new LoginException JavaDoc("No CallbackHandler Specified");
106         }
107     }
108 }
109
Popular Tags