KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > security > bridge > AbstractRealmBridge


1 /**
2  *
3  * Copyright 2003-2004 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * 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
18 package org.apache.geronimo.security.bridge;
19
20 import javax.security.auth.Subject JavaDoc;
21 import javax.security.auth.callback.CallbackHandler JavaDoc;
22 import javax.security.auth.login.LoginContext JavaDoc;
23 import javax.security.auth.login.LoginException JavaDoc;
24
25 import org.apache.geronimo.gbean.GBeanInfo;
26 import org.apache.geronimo.gbean.GBeanInfoBuilder;
27 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
28
29
30 /**
31  * @version $Rev: 126313 $ $Date: 2005-01-24 13:03:52 -0800 (Mon, 24 Jan 2005) $
32  */

33 public abstract class AbstractRealmBridge implements RealmBridge {
34     private String JavaDoc targetRealm;
35
36     public AbstractRealmBridge() {
37     }
38
39     public AbstractRealmBridge(String JavaDoc targetRealm) {
40         this.targetRealm = targetRealm;
41     }
42
43     public Subject JavaDoc mapSubject(Subject JavaDoc sourceSubject) throws LoginException JavaDoc {
44         Subject JavaDoc targetSubject = new Subject JavaDoc();
45         LoginContext JavaDoc loginContext = new LoginContext JavaDoc(targetRealm, targetSubject, getCallbackHandler(sourceSubject));
46         loginContext.login();
47         return targetSubject;
48     }
49
50     protected abstract CallbackHandler JavaDoc getCallbackHandler(Subject JavaDoc sourceSubject);
51
52     public String JavaDoc getTargetRealm() {
53         return targetRealm;
54     }
55
56     public void setTargetRealm(String JavaDoc targetRealm) {
57         this.targetRealm = targetRealm;
58     }
59
60     public static final GBeanInfo GBEAN_INFO;
61
62     static {
63         GBeanInfoBuilder infoFactory = new GBeanInfoBuilder(AbstractRealmBridge.class, NameFactory.REALM_BRIDGE);
64         infoFactory.addAttribute("targetRealm", String JavaDoc.class, true);
65         infoFactory.setConstructor(new String JavaDoc[]{"targetRealm"});
66         infoFactory.addOperation("mapSubject", new Class JavaDoc[] {Subject JavaDoc.class});
67         GBEAN_INFO = infoFactory.getBeanInfo();
68     }
69
70     public static GBeanInfo getGBeanInfo() {
71         return GBEAN_INFO;
72     }
73
74 }
75
Popular Tags