Java Code Examples for org.keycloak.adapters.spi.HttpFacade#Response

The following examples show how to use org.keycloak.adapters.spi.HttpFacade#Response . 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: KeycloakAdapterPolicyEnforcer.java    From keycloak with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean challenge(PathConfig pathConfig, PolicyEnforcerConfig.MethodConfig methodConfig, OIDCHttpFacade httpFacade) {
    if (isBearerAuthorization(httpFacade)) {
        HttpFacade.Response response = httpFacade.getResponse();
        AuthzClient authzClient = getAuthzClient();
        String ticket = getPermissionTicket(pathConfig, methodConfig, authzClient, httpFacade);

        if (ticket != null) {
            response.setStatus(401);
            response.setHeader("WWW-Authenticate", new StringBuilder("UMA realm=\"").append(authzClient.getConfiguration().getRealm()).append("\"").append(",as_uri=\"")
                    .append(authzClient.getServerConfiguration().getIssuer()).append("\"").append(",ticket=\"").append(ticket).append("\"").toString());
        } else {
            response.setStatus(403);
        }

        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Sending challenge");
        }

        return true;
    }

    handleAccessDenied(httpFacade);

    return true;
}
 
Example 2
Source File: KeycloakAdapterPolicyEnforcer.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Override
protected void handleAccessDenied(OIDCHttpFacade facade) {
    String accessDeniedPath = getEnforcerConfig().getOnDenyRedirectTo();
    HttpFacade.Response response = facade.getResponse();

    if (accessDeniedPath != null) {
        response.setStatus(302);
        response.setHeader("Location", accessDeniedPath);
    } else {
        response.sendError(403);
    }
}
 
Example 3
Source File: JaxrsHttpFacade.java    From hammock with Apache License 2.0 4 votes vote down vote up
@Override
public HttpFacade.Response getResponse() {
    return responseFacade;
}