Java Code Examples for org.keycloak.services.messages.Messages#INVALID_REQUEST

The following examples show how to use org.keycloak.services.messages.Messages#INVALID_REQUEST . 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: AuthorizationEndpointRequestParserProcessor.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public static String getClientId(EventBuilder event, KeycloakSession session, MultivaluedMap<String, String> requestParams) {
    List<String> clientParam = requestParams.get(OIDCLoginProtocol.CLIENT_ID_PARAM);
    if (clientParam != null && clientParam.size() == 1) {
        return clientParam.get(0);
    } else {
        event.error(Errors.INVALID_REQUEST);
        throw new ErrorPageException(session, Response.Status.BAD_REQUEST, Messages.INVALID_REQUEST);
    }
}
 
Example 2
Source File: AuthorizationEndpointRequestParserProcessor.java    From keycloak with Apache License 2.0 4 votes vote down vote up
public static AuthorizationEndpointRequest parseRequest(EventBuilder event, KeycloakSession session, ClientModel client, MultivaluedMap<String, String> requestParams) {
    try {
        AuthorizationEndpointRequest request = new AuthorizationEndpointRequest();

        AuthzEndpointQueryStringParser parser = new AuthzEndpointQueryStringParser(requestParams);
        parser.parseRequest(request);

        if (parser.getInvalidRequestMessage() != null) {
            request.invalidRequestMessage = parser.getInvalidRequestMessage();
            return request;
        }

        String requestParam = requestParams.getFirst(OIDCLoginProtocol.REQUEST_PARAM);
        String requestUriParam = requestParams.getFirst(OIDCLoginProtocol.REQUEST_URI_PARAM);

        if (requestParam != null && requestUriParam != null) {
            throw new RuntimeException("Illegal to use both 'request' and 'request_uri' parameters together");
        }

        String requestObjectRequired = OIDCAdvancedConfigWrapper.fromClientModel(client).getRequestObjectRequired();

        if (OIDCConfigAttributes.REQUEST_OBJECT_REQUIRED_REQUEST_OR_REQUEST_URI.equals(requestObjectRequired)
                && requestParam == null && requestUriParam == null) {
            throw new RuntimeException("Client is required to use 'request' or 'request_uri' parameter.");
        } else if (OIDCConfigAttributes.REQUEST_OBJECT_REQUIRED_REQUEST.equals(requestObjectRequired)
                && requestParam == null) {
            throw new RuntimeException("Client is required to use 'request' parameter.");
        } else if (OIDCConfigAttributes.REQUEST_OBJECT_REQUIRED_REQUEST_URI.equals(requestObjectRequired)
                && requestUriParam == null) {
            throw new RuntimeException("Client is required to use 'request_uri' parameter.");
        }

        if (requestParam != null) {
            new AuthzEndpointRequestObjectParser(session, requestParam, client).parseRequest(request);
        } else if (requestUriParam != null) {
            try (InputStream is = session.getProvider(HttpClientProvider.class).get(requestUriParam)) {
                String retrievedRequest = StreamUtil.readString(is);

                new AuthzEndpointRequestObjectParser(session, retrievedRequest, client).parseRequest(request);
            }
        }

        return request;

    } catch (Exception e) {
        ServicesLogger.LOGGER.invalidRequest(e);
        event.error(Errors.INVALID_REQUEST);
        throw new ErrorPageException(session, Response.Status.BAD_REQUEST, Messages.INVALID_REQUEST);
    }
}