LoginContext.java revision deab5d0e23a609e0eb9c5915e6cd0f4e26aac38f
/**
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the License). You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* See the License for the specific language governing
* permission and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* Header Notice in each file and include the License file
* at opensso/legal/CDDLv1.0.txt.
* If applicable, add the following below the CDDL Header,
* with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* $Id: LoginContext.java,v 1.6 2008/09/22 23:19:42 manish_rustagi Exp $
*
*/
/*
* Portions Copyrighted 2010-2015 ForgeRock Inc.
*/
/**
* This class is pulled out from JDK1.4.
* Removed <code>doPrivileged()</code> on <code>invoke()</code> method so that
* Error and Runtime exceptions can be passed back to the caller. Otherwise
* any exception is converted to <code>LoginException</code>.
*/
public class LoginContext {
private ExceptionHolder optionalExceptionHolder;
private ExceptionHolder requiredExceptionHolder;
private boolean subjectProvided = false;
private boolean loginSucceeded = false;
private CallbackHandler callbackHandler;
private ModuleInfo[] moduleStack;
boolean success = false;
optionalExceptionHolder = new ExceptionHolder();
requiredExceptionHolder = new ExceptionHolder();
// clone returned array
entries[i].getLoginModuleName(),
entries[i].getControlFlag(),
entries[i].getOptions()),
null);
}
}
if (callbackHandler == null)
throw new LoginException("invalid null CallbackHandler provided");
this.callbackHandler = callbackHandler;
}
throw new LoginException("invalid null Subject provided");
subjectProvided = true;
if (callbackHandler == null)
throw new LoginException("invalid null CallbackHandler provided");
this.callbackHandler = callbackHandler;
}
public void login() throws LoginException {
loginSucceeded = false;
}
try {
// module invoked in doPrivileged
loginSucceeded = true;
} catch (LoginException le) {
try {
} catch (LoginException le2) {
throw le;
}
throw le;
}
}
public void logout() throws LoginException {
throw new LoginException("null subject - logout called " +
"before login");
}
// module invoked in doPrivileged
}
public ModuleInfo[] getModuleStack() {
return moduleStack;
}
public Subject getSubject() {
if (!loginSucceeded && !subjectProvided)
return null;
return subject;
}
/**
* Attempts to invoke the method described by methodName against each module within the stack.
*
* @param methodName
* String method name to be invoked on each module.
* @throws LoginException
* Throw in the case of some login failure.
*/
try {
int mIndex = 0;
} else {
// instantiate the LoginModule
// allow any object to be a LoginModule
// as long as it conforms to the interface
// call the LoginModule's initialize method
break;
}
// Invoke the LoginModule initialize method
}
// find the requested method in the LoginModule
break;
}
// set up the arguments to be passed to the LoginModule method
// invoke the LoginModule method
if (status) {
// if SUFFICIENT, return if no prior REQUIRED errors
if (debug.messageEnabled()) {
}
return;
}
if (debug.messageEnabled()) {
}
success = true;
} else {
if (debug.messageEnabled()) {
}
}
} catch (NoSuchMethodException nsme) {
throw new LoginException("unable to instantiate LoginModule, module, because it does " +
} catch (InstantiationException ie) {
} catch (ClassNotFoundException cnfe) {
} catch (IllegalAccessException iae) {
} catch (InvocationTargetException ite) {
if (debug.messageEnabled()) {
}
}
// failure cases
// do not want privacy leak
// (e.g., sensitive file path in exception msg)
// le.initCause(new SecurityException());
if (debug.messageEnabled()) {
"replaced by new exception with empty detail msg");
}
} else {
// capture an unexpected LoginModule exception
}
if (debug.messageEnabled()) {
}
if (controlFlag == LoginModuleControlFlag.OPTIONAL || controlFlag == LoginModuleControlFlag.SUFFICIENT) {
// mark down that an OPTIONAL module failed
} else {
// if REQUISITE, then immediately throw an exception
throw requiredExceptionHolder.getException();
}
}
} finally {
}
}
if (requiredExceptionHolder.hasException()) {
// a REQUIRED module failed -- return the error
throw requiredExceptionHolder.getException();
// no module succeeded -- return the first optional error
throw optionalExceptionHolder.getException();
} else if (success == false) {
// no module succeeded -- all modules were IGNORED
throw new LoginException("Login Failure: all modules ignored");
}
}
// Exception holder class. Prompts InvalidPasswordExceptions above other LoginException types.
private static class ExceptionHolder {
private LoginException exception;
/**
* The captured exception.
*
* @param exception
* Captured exception.
*/
(!(this.exception instanceof InvalidPasswordException) &&
exception instanceof InvalidPasswordException)) {
}
}
/**
* @return The captured exception.
*/
public LoginException getException() {
return exception;
}
/**
* @return Whether a valid exception has been captured.
*/
public boolean hasException() {
}
}
/**
* LoginModule information -
* encapsulates Configuration info and actual module instances.
*/
static class ModuleInfo {
private AppConfigurationEntry entry;
}
return module;
}
}
}