use of com.sun.identity.authentication.spi.HttpCallback in project OpenAM by OpenRock.
the class OpenAMAuthHandler method isNextCallbackSetAvailable.
/**
* Obtains the next set of OpenAM authorization callbacks, updating our info set or sets the callbacks to null if
* unable to acquire and update the info set and sends an accessReject response in that case. Returns true if
* callback set was loaded into holder. Returns false if they couldn't be loaded or were empty which may be a valid
* state depending on the caller. Sets holder.authPhase = TERMINATED if something happened causing the
* authentication process to fail.
*
* @param context
* @param holder
* @return
*/
private boolean isNextCallbackSetAvailable(RadiusResponse response, ContextHolder holder) {
final boolean moreCallbacksAvailable = holder.getAuthContext().hasMoreRequirements();
if (!moreCallbacksAvailable) {
// cLog.warning("--- no callbacks available, set callbacks=null in isNextCallbackSetAvailable");
holder.setCallbacks(null);
return false;
}
// true means do NOT filter PagePropertiesCallbacks
final Callback[] callbacks = holder.getAuthContext().getRequirements(true);
holder.setCallbacks(callbacks);
if (holder.getCallbacks() == null) {
// cLog.warning("--- callbacks == null after ac.getReqs() called in isNextCallbackSetAvailable");
return false;
}
// process page properties piece
if (callbacks[0] instanceof PagePropertiesCallback) {
// not a formal callback, openam specific
final PagePropertiesCallback pp = (PagePropertiesCallback) callbacks[0];
holder.setCallbackSetProps(pp);
// since page properties cb is at zero index
holder.setIdxOfCurrentCallback(1);
final String moduleName = pp.getModuleName();
if (!moduleName.equals(holder.getModuleName())) {
// entering new module
holder.setModuleName(moduleName);
holder.incrementChainModuleIndex();
holder.setIdxOfCallbackSetInModule(0);
// cLog.warning("New Module Incurred: " + holder.moduleName + " with callbacks["
// + holder.callbacks.length + "]");
} else {
holder.incrementIdxOfCallbackSetInModule();
// cLog.warning("New Callback Set[" + holder.callbacks.length + "] Incurred in Module: "
// + holder.moduleName);
}
// update the
holder.setMillisExpiryForCurrentCallbacks(1000L * pp.getTimeOutValue());
holder.setMillisExpiryPoint(System.currentTimeMillis() + holder.getMillisExpiryForCurrentCallbacks());
} else {
LOG.error("Callback at index 0 is not of type PagePropertiesCallback!!!");
rejectAccessAndTerminateProcess(response, holder);
return false;
}
// now fail fast if we find unsupportable callback types
boolean httpCbIncurred = false;
boolean redirectCbIncurred = false;
for (int i = 1; i < callbacks.length; i++) {
final Callback cb = callbacks[i];
if (cb instanceof HttpCallback) {
httpCbIncurred = true;
break;
} else if (cb instanceof RedirectCallback) {
redirectCbIncurred = true;
break;
}
}
if (httpCbIncurred || redirectCbIncurred) {
LOG.error("Radius can not support " + (httpCbIncurred ? HttpCallback.class.getSimpleName() : RedirectCallback.class.getSimpleName()) + " used by module " + holder.getChainModuleIndex() + " with name " + holder.getModuleName() + " in chain '" + this.authChain + "'. Denying Access.");
rejectAccessAndTerminateProcess(response, holder);
return false;
}
return true;
}
use of com.sun.identity.authentication.spi.HttpCallback in project OpenAM by OpenRock.
the class AuthXMLUtils method createHttpCallback.
static HttpCallback createHttpCallback(Node childNode, Callback callback) {
HttpCallback hc = null;
if (callback != null && (callback instanceof HttpCallback)) {
hc = (HttpCallback) callback;
}
if (hc == null) {
String authRHeader = getValueOfChildNode(childNode, AuthXMLTags.HTTP_HEADER);
String negoHeader = getValueOfChildNode(childNode, AuthXMLTags.HTTP_NEGO);
String errorCode = getValueOfChildNode(childNode, AuthXMLTags.HTTP_CODE);
hc = new HttpCallback(authRHeader, negoHeader, errorCode);
}
String tokenValue = getValueOfChildNode(childNode, AuthXMLTags.HTTP_TOKEN);
if (tokenValue != null && tokenValue.length() > 0) {
hc.setAuthorization(tokenValue);
}
return hc;
}
use of com.sun.identity.authentication.spi.HttpCallback in project OpenAM by OpenRock.
the class AuthXMLUtils method getXMLForCallbacks.
/**
* TODO-JAVADOC
*/
public static String getXMLForCallbacks(Callback[] callbacks) {
if (callbacks == null) {
return ("");
}
// Construct the xml string
StringBuilder xmlString = new StringBuilder();
xmlString.append(AuthXMLTags.CALLBACKS_BEGIN).append(AuthXMLTags.SPACE).append(AuthXMLTags.LENGTH).append(AuthXMLTags.EQUAL).append(AuthXMLTags.QUOTE).append(callbacks.length).append(AuthXMLTags.QUOTE).append(AuthXMLTags.ELEMENT_END);
for (int i = 0; i < callbacks.length; i++) {
if (callbacks[i] instanceof HiddenValueCallback) {
HiddenValueCallback hiddenValueCallback = (HiddenValueCallback) callbacks[i];
xmlString.append(getHiddenValueCallbackXML(hiddenValueCallback));
} else if (callbacks[i] instanceof NameCallback) {
NameCallback nameCallback = (NameCallback) callbacks[i];
xmlString.append(getNameCallbackXML(nameCallback));
} else if (callbacks[i] instanceof PasswordCallback) {
PasswordCallback passwordCallback = (PasswordCallback) callbacks[i];
xmlString.append(getPasswordCallbackXML(passwordCallback));
} else if (callbacks[i] instanceof ChoiceCallback) {
ChoiceCallback choiceCallback = (ChoiceCallback) callbacks[i];
xmlString.append(getChoiceCallbackXML(choiceCallback));
} else if (callbacks[i] instanceof ConfirmationCallback) {
ConfirmationCallback conCallback = (ConfirmationCallback) callbacks[i];
xmlString.append(getConfirmationCallbackXML(conCallback));
} else if (callbacks[i] instanceof TextInputCallback) {
TextInputCallback textInputCallback = (TextInputCallback) callbacks[i];
xmlString.append(getTextInputCallbackXML(textInputCallback));
} else if (callbacks[i] instanceof TextOutputCallback) {
TextOutputCallback textOutputCallback = (TextOutputCallback) callbacks[i];
xmlString.append(getTextOutputCallbackXML(textOutputCallback));
} else if (callbacks[i] instanceof PagePropertiesCallback) {
PagePropertiesCallback pagePCallback = (PagePropertiesCallback) callbacks[i];
xmlString.append(getPagePropertiesCallbackXML(pagePCallback));
} else if (callbacks[i] instanceof LanguageCallback) {
LanguageCallback lc = (LanguageCallback) callbacks[i];
xmlString.append(getLanguageCallbackXML(lc));
} else if (callbacks[i] instanceof X509CertificateCallback) {
X509CertificateCallback xc = (X509CertificateCallback) callbacks[i];
xmlString.append(getX509CertificateCallbackXML(xc));
} else if (callbacks[i] instanceof HttpCallback) {
HttpCallback hc = (HttpCallback) callbacks[i];
xmlString.append(getHttpCallbackXML(hc));
} else if (callbacks[i] instanceof DSAMECallbackInterface) {
DSAMECallbackInterface dsameCallback = (DSAMECallbackInterface) callbacks[i];
xmlString.append(getCustomCallbackXML(dsameCallback));
} else if (callbacks[i] instanceof RedirectCallback) {
RedirectCallback redirectCallback = (RedirectCallback) callbacks[i];
xmlString.append(getRedirectCallbackXML(redirectCallback));
} else {
AuthenticationCallbackXMLHelper callbackXMLHelper = AuthenticationCallbackXMLHelperFactory.getCallbackXMLHelper();
if (callbackXMLHelper != null) {
xmlString.append(callbackXMLHelper.getAuthenticationCallbackXML(callbacks[i]));
}
}
}
xmlString.append(AuthXMLTags.CALLBACKS_END);
return (xmlString.toString());
}
use of com.sun.identity.authentication.spi.HttpCallback in project OpenAM by OpenRock.
the class RestAuthHttpCallbackHandlerTest method shouldHandleCallbackAndSetHttpAuthFailedIfReasonInPostBody.
@Test
public void shouldHandleCallbackAndSetHttpAuthFailedIfReasonInPostBody() {
//Given
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
HttpCallback originalHttpCallback = mock(HttpCallback.class);
Map<String, String> postBodyMap = new LinkedHashMap<String, String>();
postBodyMap.put("reason", "http-auth-failed");
JsonValue jsonPostBody = new JsonValue(postBodyMap);
//When
HttpCallback httpCallback = restAuthHttpCallbackHandler.handle(request, response, jsonPostBody, originalHttpCallback);
//Then
Assert.assertEquals(originalHttpCallback, httpCallback);
verify(request).setAttribute("http-auth-failed", true);
}
use of com.sun.identity.authentication.spi.HttpCallback in project OpenAM by OpenRock.
the class RestAuthHttpCallbackHandlerTest method shouldHandleCallbackWhereIWASuccessful.
@Test
public void shouldHandleCallbackWhereIWASuccessful() {
//Given
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
JsonValue jsonPostBody = new JsonValue(new HashMap<String, String>());
HttpCallback originalHttpCallback = mock(HttpCallback.class);
//When
HttpCallback httpCallback = restAuthHttpCallbackHandler.handle(request, response, jsonPostBody, originalHttpCallback);
//Then
Assert.assertEquals(originalHttpCallback, httpCallback);
verify(request, never()).setAttribute("http-auth-failed", true);
}
Aggregations