blob: 08244064c2bd47bf26ba1f3ef55a0168c0ac386c [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2000-2004 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24import java.util.*;
25import java.io.IOException;
26import javax.security.auth.*;
27import javax.security.auth.callback.*;
28import javax.security.auth.login.*;
29import javax.security.auth.spi.*;
30
31public 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
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
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
66 public boolean commit() throws LoginException {
67 return true;
68 }
69
70 public boolean abort() throws LoginException {
71 return true;
72 }
73
74 public boolean logout() throws LoginException {
75 return true;
76 }
77}