use of javax.security.auth.callback.ChoiceCallback in project OpenAM by OpenRock.
the class LoginProcessTest method shouldRestartLoginProcessWhenLevelUsedToChooseAuthModuleWithAuthTypeModule.
@Test
public void shouldRestartLoginProcessWhenLevelUsedToChooseAuthModuleWithAuthTypeModule() throws AuthLoginException {
//Given
Callback callbackOne = mock(Callback.class);
ChoiceCallback callbackTwo = mock(ChoiceCallback.class);
Callback callbackThree = mock(Callback.class);
Callback[] callbacks = new Callback[] { callbackOne, callbackTwo, callbackThree };
given(authContext.getIndexType()).willReturn(AuthIndexType.LEVEL);
given(callbackTwo.getSelectedIndexes()).willReturn(new int[] { 0 });
given(callbackTwo.getChoices()).willReturn(new String[] { "CHOICE_ONE" });
given(coreServicesWrapper.getDataFromRealmQualifiedData("CHOICE_ONE")).willReturn("INDEX_VALUE");
given(coreServicesWrapper.getRealmFromRealmQualifiedData("CHOICE_ONE")).willReturn("QUALIFIED_REALM");
given(coreServicesWrapper.orgNameToDN("QUALIFIED_REALM")).willReturn("ORG_DN");
given(coreServicesWrapper.getCompositeAdviceType(authContext)).willReturn(AuthUtils.MODULE);
//When
LoginProcess loginP = loginProcess.next(callbacks);
//Then
verify(authContext, never()).submitRequirements(callbacks);
verify(authContext).setOrgDN("ORG_DN");
verify(loginConfiguration).indexType(AuthIndexType.MODULE);
verify(loginConfiguration).indexValue("INDEX_VALUE");
verify(loginAuthenticator).startLoginProcess(loginProcess);
assertNotEquals(loginP, loginProcess);
}
use of javax.security.auth.callback.ChoiceCallback in project OpenAM by OpenRock.
the class OpenAMAuthHandler method getNextCallbackReplyMsg.
/**
* Generates reply message for the current callback to be embedded in a challenge response to gather an answer for
* that callback. If an unknown/unexpected callback type is incurred the process is terminated with a reject
* response.
*
* @param respHandler
* @param holder
* @return
*/
private ReplyMessageAttribute getNextCallbackReplyMsg(RadiusResponse response, ContextHolder holder) {
LOG.message("Entering getNextCallbackReplyMsg()");
ReplyMessageAttribute msg = null;
final Callback[] callbacks = holder.getCallbacks();
if (callbacks == null) {
return null;
}
final Callback cb = callbacks[holder.getIdxOfCurrentCallback()];
String header = "";
final PagePropertiesCallback pagePropCallback = holder.getCallbackSetProps();
if (pagePropCallback != null && !"".equals(pagePropCallback.getHeader())) {
header = pagePropCallback.getHeader() + " ";
}
if (cb instanceof NameCallback) {
LOG.message("getNextCallbackReplyMsg(); - processing NameCallback.");
msg = new ReplyMessageAttribute(header + ((NameCallback) cb).getPrompt());
} else if (cb instanceof PasswordCallback) {
LOG.message("getNextCallbackReplyMsg(); - processing PasswordCallback.");
msg = new ReplyMessageAttribute(header + ((PasswordCallback) cb).getPrompt());
} else if (cb instanceof ChoiceCallback) {
LOG.message("getNextCallbackReplyMsg(); - processing ChoiceCallback.");
final ChoiceCallback cc = (ChoiceCallback) cb;
final StringBuilder sb = new StringBuilder();
sb.append(header);
sb.append(cc.getPrompt());
if (cc.allowMultipleSelections()) {
// ugh. we'll have to figure out how to translate this suitably in view of sentence structure for
// a given locale.
// TODO: LOCALIZE
sb.append(" (Separate Selected Numbers by Spaces");
if (cc.getDefaultChoice() >= 0) {
sb.append(". Default is " + cc.getDefaultChoice());
}
sb.append(".)");
}
sb.append('\n');
final String[] choices = cc.getChoices();
for (int j = 0; j < choices.length; j++) {
final String choice = choices[j];
if (j != 0) {
sb.append(",\n");
}
sb.append(j);
sb.append(" = ");
sb.append(choice);
}
msg = new ReplyMessageAttribute(sb.toString());
} else if (cb instanceof ConfirmationCallback) {
LOG.message("getNextCallbackReplyMsg(); - processing ConformationCallback.");
final ConfirmationCallback cc = (ConfirmationCallback) cb;
final StringBuilder sb = new StringBuilder();
sb.append(header);
sb.append(cc.getPrompt());
if (cc.getDefaultOption() >= 0) {
// ugh. ditto on above translation concern
sb.append(" (Default is ");
sb.append(cc.getDefaultOption());
sb.append(".)");
}
sb.append('\n');
final String[] options = cc.getOptions();
for (int j = 0; j < options.length; j++) {
final String option = options[j];
if (j != 0) {
sb.append(",\n");
}
sb.append(j);
sb.append(" = ");
sb.append(option);
}
msg = new ReplyMessageAttribute(sb.toString());
} else {
// unknown and unexpected type
LOG.error("Radius can not support " + cb.getClass().getSimpleName() + " used by module " + holder.getChainModuleIndex() + " with name " + holder.getModuleName() + " in chain '" + this.authChain + "'. Denying Access.");
rejectAccessAndTerminateProcess(response, holder);
}
LOG.message("Entering getNextCallbackReplyMsg() returning '" + msg + "'");
return msg;
}
Aggregations