KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.Map JavaDoc;
20 import javax.security.auth.Subject JavaDoc;
21 import javax.security.auth.callback.Callback JavaDoc;
22 import javax.security.auth.callback.CallbackHandler JavaDoc;
23 import javax.security.auth.login.LoginException JavaDoc;
24 import javax.security.auth.login.FailedLoginException JavaDoc;
25
26 import org.apache.geronimo.security.jaas.server.JaasSessionId;
27 import org.apache.geronimo.security.jaas.server.JaasLoginServiceMBean;
28 import org.apache.geronimo.security.jaas.LoginModuleControlFlag;
29
30
31 /**
32  * @version $Revision: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
33  */

34 public class ServerLoginProxy extends LoginModuleProxy {
35     CallbackHandler JavaDoc handler;
36     Callback JavaDoc[] callbacks;
37     private final int lmIndex;
38     private final JaasLoginServiceMBean service;
39     private final JaasSessionId sessionHandle;
40
41     public ServerLoginProxy(LoginModuleControlFlag controlFlag, Subject JavaDoc subject, int lmIndex,
42                             JaasLoginServiceMBean service, JaasSessionId sessionHandle)
43     {
44         super(controlFlag, subject);
45         this.lmIndex = lmIndex;
46         this.service = service;
47         this.sessionHandle = sessionHandle;
48     }
49
50     public void initialize(Subject JavaDoc subject, CallbackHandler JavaDoc handler, Map JavaDoc sharedState, Map JavaDoc options) {
51         this.handler = handler;
52     }
53
54     /**
55      * Perform a login on the server side.
56      * <p/>
57      * Here we get the Callbacks from the server side, pass them to the
58      * local handler so that they may be filled. We pass the resulting
59      * set of Callbacks back to the server.
60      *
61      * @return true if the authentication succeeded, or false if this
62      * <code>LoginModule</code> should be ignored.
63      * @throws javax.security.auth.login.LoginException
64      * if the authentication fails
65      */

66     public boolean login() throws LoginException JavaDoc {
67         try {
68             callbacks = service.getServerLoginCallbacks(sessionHandle, lmIndex);
69             if (handler != null) {
70                 handler.handle(callbacks);
71             } else if (callbacks != null && callbacks.length > 0) {
72                 System.err.println("No callback handler available for " + callbacks.length + " callbacks!");
73             }
74             return service.performLogin(sessionHandle, lmIndex, callbacks);
75         } catch (FailedLoginException JavaDoc e) {
76             throw e;
77         } catch (Exception JavaDoc e) {
78             LoginException JavaDoc le = new LoginException JavaDoc("Error filling callback list");
79             le.initCause(e);
80             throw le;
81         }
82     }
83
84     public boolean commit() throws LoginException JavaDoc {
85         return service.performCommit(sessionHandle, lmIndex);
86     }
87
88     public boolean abort() throws LoginException JavaDoc {
89         return service.performAbort(sessionHandle, lmIndex);
90     }
91
92     public boolean logout() throws LoginException JavaDoc {
93         return false; // taken care of with a single call to the server
94
}
95 }
Popular Tags