services/src/main/java/org/keycloak/services/resources/LoginActionsService.java
/**
     * URL called after login page.  YOU SHOULD NEVER INVOKE THIS DIRECTLY!
     *
     * @param code
     * @param formData
     * @return
     */
URL called after login page.  YOU SHOULD NEVER INVOKE THIS DIRECTLY.
@param code
@param formData
@return
URL called after login page . YOU SHOULD NEVER INVOKE THIS DIRECTLY . @param code @param formData @return
@Path("request/login")
    @POST
    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
    public Response processLogin(@QueryParam("code") String code,
                                 final MultivaluedMap<String, String> formData) {
        event.event(EventType.LOGIN);
        if (!checkSsl()) {
            event.error(Errors.SSL_REQUIRED);
            return ErrorPage.error(session, Messages.HTTPS_REQUIRED);
        }
        if (!realm.isEnabled()) {
            event.error(Errors.REALM_DISABLED);
            return ErrorPage.error(session, Messages.REALM_NOT_ENABLED);
        }
        ClientSessionCode clientCode = ClientSessionCode.parse(code, session, realm);
        if (clientCode == null) {
            event.error(Errors.INVALID_CODE);
            return ErrorPage.error(session, Messages.INVALID_CODE);
        }
        ClientSessionModel clientSession = clientCode.getClientSession();
        event.detail(Details.CODE_ID, clientSession.getId());
        if (!clientCode.isValid(ClientSessionModel.Action.AUTHENTICATE) || clientSession.getUserSession() != null) {
            clientCode.setAction(ClientSessionModel.Action.AUTHENTICATE);
            event.client(clientSession.getClient()).error(Errors.EXPIRED_CODE);
            return session.getProvider(LoginFormsProvider.class)
                    .setError(Messages.EXPIRED_CODE)
                    .setClientSessionCode(clientCode.getCode())
                    .createLogin();
        }
        String username = formData.getFirst(AuthenticationManager.FORM_USERNAME);
        String rememberMe = formData.getFirst("rememberMe");
        boolean remember = rememberMe != null && rememberMe.equalsIgnoreCase("on");
        event.client(clientSession.getClient().getClientId())
                .detail(Details.REDIRECT_URI, clientSession.getRedirectUri())
                .detail(Details.RESPONSE_TYPE, "code")
                .detail(Details.AUTH_METHOD, "form")
                .detail(Details.USERNAME, username);
        if (remember) {
            event.detail(Details.REMEMBER_ME, "true");
        }
        ClientModel client = clientSession.getClient();
        if (client == null) {
            event.error(Errors.CLIENT_NOT_FOUND);
            return ErrorPage.error(session, Messages.UNKNOWN_LOGIN_REQUESTER);
        }
        if (!client.isEnabled()) {
            event.error(Errors.CLIENT_DISABLED);
            return ErrorPage.error(session, Messages.LOGIN_REQUESTER_NOT_ENABLED);
        }
        session.getContext().setClient(clientSession.getClient());
        if (formData.containsKey("cancel")) {
            event.error(Errors.REJECTED_BY_USER);
            LoginProtocol protocol = session.getProvider(LoginProtocol.class, clientSession.getAuthMethod());
            protocol.setRealm(realm)
                    .setHttpHeaders(headers)
                    .setUriInfo(uriInfo);
            return protocol.cancelLogin(clientSession);
        }
        AuthenticationManager.AuthenticationStatus status = authManager.authenticateForm(session, clientConnection, realm, formData);
        if (remember) {
            authManager.createRememberMeCookie(realm, username, uriInfo, clientConnection);
        } else {
            authManager.expireRememberMeCookie(realm, uriInfo, clientConnection);
        }
        UserModel user = KeycloakModelUtils.findUserByNameOrEmail(session, realm, username);
        if (user != null) {
            event.user(user);
        }
        switch (status) {
            case SUCCESS:
            case ACTIONS_REQUIRED:
                UserSessionModel userSession = session.sessions().createUserSession(realm, user, username, clientConnection.getRemoteAddr(), "form", remember, null, null);
                TokenManager.attachClientSession(userSession, clientSession);
                event.session(userSession);
                return authManager.nextActionAfterAuthentication(session, userSession, clientSession, clientConnection, request, uriInfo, event);
            case ACCOUNT_TEMPORARILY_DISABLED:
                event.error(Errors.USER_TEMPORARILY_DISABLED);
                return session.getProvider(LoginFormsProvider.class)
                        .setError(Messages.ACCOUNT_TEMPORARILY_DISABLED)
                        .setFormData(formData)
                        .setClientSessionCode(clientCode.getCode())
                        .createLogin();
            case ACCOUNT_DISABLED:
                event.error(Errors.USER_DISABLED);
                return session.getProvider(LoginFormsProvider.class)
                        .setError(Messages.ACCOUNT_DISABLED)
                        .setClientSessionCode(clientCode.getCode())
                        .setFormData(formData).createLogin();
            case MISSING_TOTP:
                formData.remove(CredentialRepresentation.PASSWORD);
                String passwordToken = new JWSBuilder().jsonContent(new PasswordToken(realm.getName(), user.getId())).rsa256(realm.getPrivateKey());
                formData.add(CredentialRepresentation.PASSWORD_TOKEN, passwordToken);
                return session.getProvider(LoginFormsProvider.class)
                        .setFormData(formData)
                        .setClientSessionCode(clientCode.getCode())
                        .createLoginTotp();
            case INVALID_USER:
                event.error(Errors.USER_NOT_FOUND);
                return session.getProvider(LoginFormsProvider.class)
                        .setError(Messages.INVALID_USER)
                        .setFormData(formData)
                        .setClientSessionCode(clientCode.getCode())
                        .createLogin();
            default:
                event.error(Errors.INVALID_USER_CREDENTIALS);
                return session.getProvider(LoginFormsProvider.class)
                        .setError(Messages.INVALID_USER)
                        .setFormData(formData)
                        .setClientSessionCode(clientCode.getCode())
                        .createLogin();
        }
    }
@ Path ( "request/login" ) @ POST @ Consumes ( MediaType . APPLICATION_FORM_URLENCODED ) public Response processLogin ( @ QueryParam ( "code" ) String code , final MultivaluedMap < String , String > formData ) { event . event ( EventType . LOGIN ) ; if ( ! checkSsl ( ) ) { event . error ( Errors . SSL_REQUIRED ) ; return ErrorPage . error ( session , Messages . HTTPS_REQUIRED ) ; } if ( ! realm . isEnabled ( ) ) { event . error ( Errors . REALM_DISABLED ) ; return ErrorPage . error ( session , Messages . REALM_NOT_ENABLED ) ; } ClientSessionCode clientCode = ClientSessionCode . parse ( code , session , realm ) ; if ( clientCode == null ) { event . error ( Errors . INVALID_CODE ) ; return ErrorPage . error ( session , Messages . INVALID_CODE ) ; } ClientSessionModel clientSession = clientCode . getClientSession ( ) ; event . detail ( Details . CODE_ID , clientSession . getId ( ) ) ; if ( ! clientCode . isValid ( ClientSessionModel . Action . AUTHENTICATE ) || clientSession . getUserSession ( ) != null ) { clientCode . setAction ( ClientSessionModel . Action . AUTHENTICATE ) ; event . client ( clientSession . getClient ( ) ) . error ( Errors . EXPIRED_CODE ) ; return session . getProvider ( LoginFormsProvider . class ) . setError ( Messages . EXPIRED_CODE ) . setClientSessionCode ( clientCode . getCode ( ) ) . createLogin ( ) ; } String username = formData . getFirst ( AuthenticationManager . FORM_USERNAME ) ; String rememberMe = formData . getFirst ( "rememberMe" ) ; boolean remember = rememberMe != null && rememberMe . equalsIgnoreCase ( "on" ) ; event . client ( clientSession . getClient ( ) . getClientId ( ) ) . detail ( Details . REDIRECT_URI , clientSession . getRedirectUri ( ) ) . detail ( Details . RESPONSE_TYPE , "code" ) . detail ( Details . AUTH_METHOD , "form" ) . detail ( Details . USERNAME , username ) ; if ( remember ) { event . detail ( Details . REMEMBER_ME , "true" ) ; } ClientModel client = clientSession . getClient ( ) ; if ( client == null ) { event . error ( Errors . CLIENT_NOT_FOUND ) ; return ErrorPage . error ( session , Messages . UNKNOWN_LOGIN_REQUESTER ) ; } if ( ! client . isEnabled ( ) ) { event . error ( Errors . CLIENT_DISABLED ) ; return ErrorPage . error ( session , Messages . LOGIN_REQUESTER_NOT_ENABLED ) ; } session . getContext ( ) . setClient ( clientSession . getClient ( ) ) ; if ( formData . containsKey ( "cancel" ) ) { event . error ( Errors . REJECTED_BY_USER ) ; LoginProtocol protocol = session . getProvider ( LoginProtocol . class , clientSession . getAuthMethod ( ) ) ; protocol . setRealm ( realm ) . setHttpHeaders ( headers ) . setUriInfo ( uriInfo ) ; return protocol . cancelLogin ( clientSession ) ; } AuthenticationManager . AuthenticationStatus status = authManager . authenticateForm ( session , clientConnection , realm , formData ) ; if ( remember ) { authManager . createRememberMeCookie ( realm , username , uriInfo , clientConnection ) ; } else { authManager . expireRememberMeCookie ( realm , uriInfo , clientConnection ) ; } UserModel user = KeycloakModelUtils . findUserByNameOrEmail ( session , realm , username ) ; if ( user != null ) { event . user ( user ) ; } switch ( status ) { case SUCCESS : case ACTIONS_REQUIRED : UserSessionModel userSession = session . sessions ( ) . createUserSession ( realm , user , username , clientConnection . getRemoteAddr ( ) , "form" , remember , null , null ) ; TokenManager . attachClientSession ( userSession , clientSession ) ; event . session ( userSession ) ; return authManager . nextActionAfterAuthentication ( session , userSession , clientSession , clientConnection , request , uriInfo , event ) ; case ACCOUNT_TEMPORARILY_DISABLED : event . error ( Errors . USER_TEMPORARILY_DISABLED ) ; return session . getProvider ( LoginFormsProvider . class ) . setError ( Messages . ACCOUNT_TEMPORARILY_DISABLED ) . setFormData ( formData ) . setClientSessionCode ( clientCode . getCode ( ) ) . createLogin ( ) ; case ACCOUNT_DISABLED : event . error ( Errors . USER_DISABLED ) ; return session . getProvider ( LoginFormsProvider . class ) . setError ( Messages . ACCOUNT_DISABLED ) . setClientSessionCode ( clientCode . getCode ( ) ) . setFormData ( formData ) . createLogin ( ) ; case MISSING_TOTP : formData . remove ( CredentialRepresentation . PASSWORD ) ; String passwordToken = new JWSBuilder ( ) . jsonContent ( new PasswordToken ( realm . getName ( ) , user . getId ( ) ) ) . rsa256 ( realm . getPrivateKey ( ) ) ; formData . add ( CredentialRepresentation . PASSWORD_TOKEN , passwordToken ) ; return session . getProvider ( LoginFormsProvider . class ) . setFormData ( formData ) . setClientSessionCode ( clientCode . getCode ( ) ) . createLoginTotp ( ) ; case INVALID_USER : event . error ( Errors . USER_NOT_FOUND ) ; return session . getProvider ( LoginFormsProvider . class ) . setError ( Messages . INVALID_USER ) . setFormData ( formData ) . setClientSessionCode ( clientCode . getCode ( ) ) . createLogin ( ) ; default : event . error ( Errors . INVALID_USER_CREDENTIALS ) ; return session . getProvider ( LoginFormsProvider . class ) . setError ( Messages . INVALID_USER ) . setFormData ( formData ) . setClientSessionCode ( clientCode . getCode ( ) ) . createLogin ( ) ; } }
URL called after login page.
URL called after login page .