use of javax.security.auth.callback.Callback in project OpenAM by OpenRock.
the class AMLoginModule method clearInfoText.
/**
* Clears the info text for a given callback state
*
* @param state The state to clear all infotexts
* @throws AuthLoginException Invalid state
* @supported.api
*/
public void clearInfoText(int state) throws AuthLoginException {
if (debug.messageEnabled()) {
debug.message("clearInfoText : state=" + state);
}
// check state length
if (state > stateLength) {
throw new AuthLoginException(bundleName, "invalidState", new Object[] { new Integer(state) });
}
// check callback length for the state
Callback[] ext = getCallback(state);
if (ext.length <= 0) {
throw new AuthLoginException(bundleName, "invalidCallbackIndex", null);
}
// in internal, first Callback is always PagePropertiesCallback
PagePropertiesCallback pc = (PagePropertiesCallback) ((Callback[]) internal.get(state - 1))[0];
// clear info text
List<String> infoTexts = pc.getInfoText();
for (int i = 0; i < infoTexts.size(); i++) {
infoTexts.set(i, EMPTY_STRING);
}
pc.setInfoText(infoTexts);
}
use of javax.security.auth.callback.Callback in project OpenAM by OpenRock.
the class AMLoginModule method getInfoText.
/**
* Returns the info text associated with a specific callback
*
* @param state The state to fetch the info text
* @param index The callback to fetch the info text
* @return The info text
* @supported.api
*/
public String getInfoText(int state, int index) {
// check state
if (state > stateLength) {
// invalid state, return empty string now
return EMPTY_STRING;
}
// get internal callbacks for the state
Callback[] callbacks = (Callback[]) internal.get(state - 1);
if (callbacks == null || callbacks.length == 0) {
// no callbacks defined for this state, return empty string
return EMPTY_STRING;
}
// check first Callback
Callback callback = callbacks[0];
if (callback instanceof PagePropertiesCallback) {
List<String> infoText = ((PagePropertiesCallback) callback).getAttribute();
if (infoText == null || infoText.isEmpty() || index >= infoText.size()) {
return EMPTY_STRING;
} else {
return infoText.get(index);
}
} else {
return EMPTY_STRING;
}
}
use of javax.security.auth.callback.Callback in project OpenAM by OpenRock.
the class AMLoginModule method getLoginState.
/*
* Returns the Login State object
* @return com.sun.identity.authentication.service.LoginState
*/
private com.sun.identity.authentication.service.LoginState getLoginState() {
Callback[] callbacks = new Callback[1];
try {
callbacks[0] = new LoginStateCallback();
if (handler == null) {
return null;
}
handler.handle(callbacks);
return ((LoginStateCallback) callbacks[0]).getLoginState();
} catch (Exception e) {
debug.message("Error..", e);
return null;
}
}
use of javax.security.auth.callback.Callback in project OpenAM by OpenRock.
the class AMLoginModule method getAttribute.
/**
* Returns the attribute name for the specified callback in the
* specified login state.
*
* @param state Order of state
* @param index Order of the Callback in the Callback[], the index
* starts with 0.
* @return Name of the attribute, empty string will be returned
* if the attribute is not defined.
* @supported.api
*/
public String getAttribute(int state, int index) {
// check state
if (state > stateLength) {
// invalid state, return empty string now
return EMPTY_STRING;
}
// get internal callbacks for the state
Callback[] callbacks = (Callback[]) internal.get(state - 1);
if (callbacks == null || callbacks.length == 0) {
// no callbacks defined for this state, return empty string
return EMPTY_STRING;
}
// check first Callback
Callback callback = callbacks[0];
if (callback instanceof PagePropertiesCallback) {
List req = ((PagePropertiesCallback) callback).getAttribute();
if (req == null || req.isEmpty() || index >= req.size()) {
return EMPTY_STRING;
} else {
return (String) req.get(index);
}
} else {
return EMPTY_STRING;
}
}
use of javax.security.auth.callback.Callback in project alluxio by Alluxio.
the class PlainSaslServer method evaluateResponse.
@Override
public byte[] evaluateResponse(byte[] response) throws SaslException {
Preconditions.checkState(!mCompleted, "PLAIN authentication has completed");
Preconditions.checkArgument(response != null, "Received null response");
try {
// parse the response
// message = [authorizationId] UTF8NUL authenticationId UTF8NUL passwd'
// authorizationId may be empty,then the authorizationId = authenticationId
String payload;
try {
payload = new String(response, "UTF-8");
} catch (Exception e) {
throw new IllegalArgumentException("Received corrupt response", e);
}
String[] parts = payload.split("