Search in sources :

Example 6 with HttpCallback

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;
}
Also used : RedirectCallback(com.sun.identity.authentication.spi.RedirectCallback) PagePropertiesCallback(com.sun.identity.authentication.spi.PagePropertiesCallback) HttpCallback(com.sun.identity.authentication.spi.HttpCallback) RedirectCallback(com.sun.identity.authentication.spi.RedirectCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) ChoiceCallback(javax.security.auth.callback.ChoiceCallback) NameCallback(javax.security.auth.callback.NameCallback) ConfirmationCallback(javax.security.auth.callback.ConfirmationCallback) Callback(javax.security.auth.callback.Callback) PagePropertiesCallback(com.sun.identity.authentication.spi.PagePropertiesCallback) HttpCallback(com.sun.identity.authentication.spi.HttpCallback)

Example 7 with HttpCallback

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;
}
Also used : HttpCallback(com.sun.identity.authentication.spi.HttpCallback)

Example 8 with HttpCallback

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());
}
Also used : RedirectCallback(com.sun.identity.authentication.spi.RedirectCallback) ConfirmationCallback(javax.security.auth.callback.ConfirmationCallback) PagePropertiesCallback(com.sun.identity.authentication.spi.PagePropertiesCallback) HiddenValueCallback(com.sun.identity.authentication.callbacks.HiddenValueCallback) HttpCallback(com.sun.identity.authentication.spi.HttpCallback) TextOutputCallback(javax.security.auth.callback.TextOutputCallback) ScriptTextOutputCallback(com.sun.identity.authentication.callbacks.ScriptTextOutputCallback) LanguageCallback(javax.security.auth.callback.LanguageCallback) TextInputCallback(javax.security.auth.callback.TextInputCallback) DSAMECallbackInterface(com.sun.identity.authentication.spi.DSAMECallbackInterface) ChoiceCallback(javax.security.auth.callback.ChoiceCallback) NameCallback(javax.security.auth.callback.NameCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) X509CertificateCallback(com.sun.identity.authentication.spi.X509CertificateCallback)

Example 9 with HttpCallback

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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpCallback(com.sun.identity.authentication.spi.HttpCallback) JsonValue(org.forgerock.json.JsonValue) HttpServletResponse(javax.servlet.http.HttpServletResponse) LinkedHashMap(java.util.LinkedHashMap) Test(org.testng.annotations.Test)

Example 10 with HttpCallback

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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) JsonValue(org.forgerock.json.JsonValue) HttpCallback(com.sun.identity.authentication.spi.HttpCallback) HttpServletResponse(javax.servlet.http.HttpServletResponse) Test(org.testng.annotations.Test)

Aggregations

HttpCallback (com.sun.identity.authentication.spi.HttpCallback)10 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 Test (org.testng.annotations.Test)5 RedirectCallback (com.sun.identity.authentication.spi.RedirectCallback)4 ChoiceCallback (javax.security.auth.callback.ChoiceCallback)4 ConfirmationCallback (javax.security.auth.callback.ConfirmationCallback)4 NameCallback (javax.security.auth.callback.NameCallback)4 PasswordCallback (javax.security.auth.callback.PasswordCallback)4 PagePropertiesCallback (com.sun.identity.authentication.spi.PagePropertiesCallback)3 ModelControlException (com.iplanet.jato.model.ModelControlException)2 SSOException (com.iplanet.sso.SSOException)2 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)2 L10NMessageImpl (com.sun.identity.shared.locale.L10NMessageImpl)2 IOException (java.io.IOException)2 Callback (javax.security.auth.callback.Callback)2 JsonValue (org.forgerock.json.JsonValue)2 RestAuthResponseException (org.forgerock.openam.core.rest.authn.exceptions.RestAuthResponseException)2 InternalSession (com.iplanet.dpro.session.service.InternalSession)1 HiddenValueCallback (com.sun.identity.authentication.callbacks.HiddenValueCallback)1