1 /*
2  * Copyright (c) 2000, 2004, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 
24 import java.util.*;
25 import java.io.IOException;
26 import javax.security.auth.*;
27 import javax.security.auth.callback.*;
28 import javax.security.auth.login.*;
29 import javax.security.auth.spi.*;
30 
31 public class DefaultHandlerModule implements LoginModule {
32 
33     // initial state
34     private Subject subject;
35     private CallbackHandler callbackHandler;
36     private Map sharedState;
37     private Map options;
38 
39     // username and password
40     private String username;
41     private char[] password;
42 
initialize(Subject subject, CallbackHandler callbackHandler, Map<String,?> sharedState, Map<String,?> options)43     public void initialize(Subject subject, CallbackHandler callbackHandler,
44                         Map<String,?> sharedState, Map<String,?> options) {
45 
46         this.subject = subject;
47         this.callbackHandler = callbackHandler;
48         this.sharedState = sharedState;
49         this.options = options;
50     }
51 
login()52     public boolean login() throws LoginException {
53 
54         // prompt for a username and password
55         if (callbackHandler == null) {
56             throw new LoginException("Error: no CallbackHandler available " +
57                         "to garner authentication information from the user");
58         } else {
59             System.out.println("DefaultHandlerModule got CallbackHandler: " +
60                         callbackHandler.toString());
61         }
62 
63         return true;
64     }
65 
commit()66     public boolean commit() throws LoginException {
67         return true;
68     }
69 
abort()70     public boolean abort() throws LoginException {
71         return true;
72     }
73 
logout()74     public boolean logout() throws LoginException {
75         return true;
76     }
77 }
78