KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > security > jaas > client > WrappingClientLoginModuleProxy


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.geronimo.security.jaas.client;
18
19 import java.security.Principal JavaDoc;
20 import java.util.HashSet JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.Map JavaDoc;
23 import java.util.Set JavaDoc;
24 import javax.security.auth.Subject JavaDoc;
25 import javax.security.auth.callback.CallbackHandler JavaDoc;
26 import javax.security.auth.login.LoginException JavaDoc;
27 import javax.security.auth.spi.LoginModule JavaDoc;
28
29 import org.apache.geronimo.security.DomainPrincipal;
30 import org.apache.geronimo.security.RealmPrincipal;
31 import org.apache.geronimo.security.jaas.LoginModuleControlFlag;
32
33
34 /**
35  * @version $Revision: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
36  */

37 public class WrappingClientLoginModuleProxy extends ClientLoginModuleProxy {
38     private final String JavaDoc loginDomainName;
39     private final String JavaDoc realmName;
40     private final Subject JavaDoc localSubject = new Subject JavaDoc();
41
42     public WrappingClientLoginModuleProxy(LoginModuleControlFlag controlFlag, Subject JavaDoc subject, LoginModule JavaDoc source,
43                                           String JavaDoc loginDomainName, String JavaDoc realmName)
44     {
45         super(controlFlag, subject, source);
46         this.loginDomainName = loginDomainName;
47         this.realmName = realmName;
48     }
49
50     public void initialize(Subject JavaDoc subject, CallbackHandler JavaDoc callbackHandler, Map JavaDoc sharedState, Map JavaDoc options) {
51         super.initialize(localSubject, callbackHandler, sharedState, options);
52     }
53
54     public boolean commit() throws LoginException JavaDoc {
55         boolean result = super.commit();
56
57         Set JavaDoc wrapped = new HashSet JavaDoc();
58         for (Iterator JavaDoc iter = subject.getPrincipals().iterator(); iter.hasNext();) {
59             Principal JavaDoc principal = (Principal JavaDoc) iter.next();
60
61             wrapped.add(new DomainPrincipal(loginDomainName, principal));
62             wrapped.add(new RealmPrincipal(realmName, loginDomainName, principal));
63         }
64         localSubject.getPrincipals().addAll(wrapped);
65         subject.getPrincipals().addAll(localSubject.getPrincipals());
66
67         return result;
68     }
69
70     public boolean logout() throws LoginException JavaDoc {
71         boolean result = super.logout();
72
73         subject.getPrincipals().removeAll(localSubject.getPrincipals());
74         localSubject.getPrincipals().clear();
75
76         return result;
77     }
78 }
Popular Tags