KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > security > realm > providers > GeronimoPasswordCredentialLoginModule


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
18 package org.apache.geronimo.security.realm.providers;
19
20 import java.util.Map JavaDoc;
21 import javax.security.auth.Subject JavaDoc;
22 import javax.security.auth.callback.Callback JavaDoc;
23 import javax.security.auth.callback.CallbackHandler JavaDoc;
24 import javax.security.auth.callback.NameCallback JavaDoc;
25 import javax.security.auth.callback.PasswordCallback JavaDoc;
26 import javax.security.auth.callback.UnsupportedCallbackException JavaDoc;
27 import javax.security.auth.login.LoginException JavaDoc;
28 import javax.security.auth.spi.LoginModule JavaDoc;
29
30
31 /**
32  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
33  */

34 public class GeronimoPasswordCredentialLoginModule implements LoginModule JavaDoc {
35
36     private Subject JavaDoc subject;
37     private CallbackHandler JavaDoc callbackHandler;
38
39     private GeronimoPasswordCredential geronimoPasswordCredential;
40
41     public void initialize(Subject JavaDoc subject, CallbackHandler JavaDoc callbackHandler,
42                            Map JavaDoc sharedState, Map JavaDoc options) {
43         this.subject = subject;
44         this.callbackHandler = callbackHandler;
45     }
46
47     public boolean login() throws LoginException JavaDoc {
48         Callback JavaDoc[] callbacks = new Callback JavaDoc[2];
49         callbacks[0] = new NameCallback JavaDoc("");
50         callbacks[1] = new PasswordCallback JavaDoc("", false);
51         try {
52             callbackHandler.handle(callbacks);
53         } catch (java.io.IOException JavaDoc e) {
54         } catch (UnsupportedCallbackException JavaDoc e) {
55             throw (LoginException JavaDoc) new LoginException JavaDoc("Unlikely UnsupportedCallbackException").initCause(e);
56         }
57         geronimoPasswordCredential = new GeronimoPasswordCredential(((NameCallback JavaDoc) callbacks[0]).getName(),
58                                                                     ((PasswordCallback JavaDoc) callbacks[1]).getPassword());
59         return true;
60     }
61
62     public boolean commit() throws LoginException JavaDoc {
63         subject.getPrivateCredentials().add(geronimoPasswordCredential);
64         return true;
65     }
66
67     public boolean abort() throws LoginException JavaDoc {
68         geronimoPasswordCredential = null;
69         return true;
70     }
71
72     public boolean logout() throws LoginException JavaDoc {
73         geronimoPasswordCredential = null;
74         return true;
75     }
76 }
77
Popular Tags