Java Code Examples for org.keycloak.authentication.AuthenticationFlowContext#generateAccessCode()

The following examples show how to use org.keycloak.authentication.AuthenticationFlowContext#generateAccessCode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PushButtonAuthenticator.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Override
    public void authenticate(AuthenticationFlowContext context) {
        String accessCode = context.generateAccessCode();
        String actionUrl = context.getActionUrl(accessCode).toString();

        StringBuilder response = new StringBuilder("<html><head><title>PushTheButton</title></head><body>");

        UserModel user = context.getUser();
        if (user == null) {
            response.append("No authenticated user<br>");
        } else {
            response.append("Authenticated user: " + user.getUsername() + "<br>");
        }

        response.append("<form method='POST' action='" + actionUrl + "'>");
        response.append(" This is the Test Approver. Press login to continue.<br>");
        response.append(" <input type='submit' name='submit1' value='Submit' />");
        response.append("</form></body></html>");
        String html = response.toString();

        Response jaxrsResponse = Response
                .status(Response.Status.OK)
                .type("text/html")
                .entity(html)
                .build();

        context.challenge(jaxrsResponse);

//        Response challenge = context.form().createForm("login-approve.ftl");
//        context.challenge(challenge);
    }
 
Example 2
Source File: SpnegoAuthenticator.java    From keycloak with Apache License 2.0 5 votes vote down vote up
/**
 * 401 challenge sent back that bypasses
 * @param context
 * @param negotiateHeader
 * @return
 */
protected Response optionalChallengeRedirect(AuthenticationFlowContext context, String negotiateHeader) {
    String accessCode = context.generateAccessCode();
    URI action = context.getActionUrl(accessCode);

    StringBuilder builder = new StringBuilder();

    builder.append("<HTML>");
    builder.append("<HEAD>");

    builder.append("<TITLE>Kerberos Unsupported</TITLE>");
    builder.append("</HEAD>");
    if (bypassChallengeJavascript) {
        builder.append("<BODY>");

    } else {
        builder.append("<BODY Onload=\"document.forms[0].submit()\">");
    }
    builder.append("<FORM METHOD=\"POST\" ACTION=\"" + action.toString() + "\">");
    builder.append("<NOSCRIPT>");
    builder.append("<P>JavaScript is disabled. We strongly recommend to enable it. You were unable to login via Kerberos.  Click the button below to login via an alternative method .</P>");
    builder.append("<INPUT name=\"continue\" TYPE=\"SUBMIT\" VALUE=\"CONTINUE\" />");
    builder.append("</NOSCRIPT>");

    builder.append("</FORM></BODY></HTML>");
    return Response.status(Response.Status.UNAUTHORIZED)
            .header(HttpHeaders.WWW_AUTHENTICATE, negotiateHeader)
            .type(MediaType.TEXT_HTML_TYPE)
            .entity(builder.toString()).build();
}
 
Example 3
Source File: IdpEmailVerificationAuthenticator.java    From keycloak with Apache License 2.0 5 votes vote down vote up
protected void showEmailSentPage(AuthenticationFlowContext context, BrokeredIdentityContext brokerContext) {
    String accessCode = context.generateAccessCode();
    URI action = context.getActionUrl(accessCode);

    Response challenge = context.form()
            .setStatus(Response.Status.OK)
            .setAttribute(LoginFormsProvider.IDENTITY_PROVIDER_BROKER_CONTEXT, brokerContext)
            .setActionUri(action)
            .setExecution(context.getExecution().getId())
            .createIdpLinkEmailPage();
    context.forceChallenge(challenge);
}