8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The contents of this file are subject to the terms
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * of the Common Development and Distribution License
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (the License). You may not use this file except in
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * compliance with the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * You can obtain a copy of the License at
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * See the License for the specific language governing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * permission and limitations under the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * When distributing Covered Code, include this CDDL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Header Notice in each file and include the License file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * If applicable, add the following below the CDDL Header,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * with the fields enclosed by brackets [] replaced by
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * your own identifying information:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * "Portions Copyrighted [year] [name of copyright owner]"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * $Id: LoginContext.java,v 1.2 2008/06/25 05:41:53 qcheng Exp $
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpackage com.sun.identity.authentication.internal;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport javax.security.auth.callback.CallbackHandler;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport javax.security.auth.callback.NameCallback;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport javax.security.auth.callback.PasswordCallback;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport javax.security.auth.login.LoginException;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.authentication.util.ISAuthConstants;
7ffff39c9d3a5fc02ccf432e74d74418ee5b96fbSachiko Wallace private HashMap sharedState = new HashMap();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public final static String LDAP_AUTH_URL = "ldap://";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public final static String LDAPS_AUTH_URL = "ldaps://";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public final static String ORGNAME = "ORGANIZATION";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public final static String PASSWORD = "PASSWORD";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public final static String AUTH_MODULES = "admin.auth.classname";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public final static String DONOT_INCLUDE_SMS_MODULE =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "admin.auth.donotIncludeSMSModule";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* Pre-configured login modules */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private final static String LDAP_LOGIN_MODULE =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "com.sun.identity.authentication.internal.server.LocalLdapAuthModule";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "com.sun.identity.authentication.internal.server.SMSAuthModule";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected LoginContext(String name, CallbackHandler handler)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected LoginContext(String name, AuthSubject subject,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster CallbackHandler handler) throws LoginException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Check for DPro auth login module, unless
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // LDAP authenication is explicitly called
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AuthContext.authDebug.warning("LoginContext::login() "
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster + "Got exception while getting auth module", e);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AuthContext.authDebug.warning("LoginContext::login() "
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster + "Using default auth modules");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw (new LoginException(e.getMessage() + "\n"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Try each module, stop at first successful auth module
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster boolean success = false;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster module.initialize(subject, cbHandler, sharedState, map);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // None of the modules were successful
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Package protected method called by AuthLoginThread to set
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // variables in shared state
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster for (int i = 0; callbacks != null && i < callbacks.length; i++) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String username = ((NameCallback) callbacks[i]).getName();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster sharedState.put(ISAuthConstants.SHARED_STATE_USERNAME,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (callbacks[i] instanceof PasswordCallback) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster char[] passwd = ((PasswordCallback) callbacks[i]).getPassword();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster sharedState.put(ISAuthConstants.SHARED_STATE_PASSWORD,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Package protected method called by AuthContext to set
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // variables in shared state
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster void updateSharedState(String username, char[] passwd) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster sharedState.put(ISAuthConstants.SHARED_STATE_USERNAME, username);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster sharedState.put(ISAuthConstants.SHARED_STATE_PASSWORD, new String(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected LoginModule[] getLoginModules() throws Exception {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String modules = SystemProperties.get(AUTH_MODULES);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AuthContext.authDebug.message("LoginContext:getLoginModules() "
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster + "Using default modules");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster StringTokenizer st = new StringTokenizer(modules, "|");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String donotIncludeSMSModule = SystemProperties
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster && donotIncludeSMSModule.equalsIgnoreCase("true")) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster answer = new LoginModule[st.countTokens() + 1];
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster answer[answer.length - 1] = (LoginModule) Class.forName(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster answer[i] = (LoginModule) Class.forName(moduleClass)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected LoginModule[] getDefaultLoginModules() throws Exception {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster answer[0] = (LoginModule) Class.forName(SMS_LOGIN_MODULE).newInstance();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster answer[1] = (LoginModule) Class.forName(LDAP_LOGIN_MODULE)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected void logout() throws LoginException {