51 if (username == null) {
52 context.getEvent().error(Errors.USER_NOT_FOUND);
53 Response challengeResponse =
errorResponse(Response.Status.UNAUTHORIZED.getStatusCode(),
"invalid_request",
"Missing parameter: username");
54 context.failure(AuthenticationFlowError.INVALID_USER, challengeResponse);
57 context.getEvent().detail(Details.USERNAME, username);
58 context.getAuthenticationSession().setAuthNote(AbstractUsernameFormAuthenticator.ATTEMPTED_USERNAME, username);
60 UserModel user = null;
62 user = KeycloakModelUtils.findUserByNameOrEmail(context.getSession(), context.getRealm(), username);
63 }
catch (ModelDuplicateException mde) {
64 ServicesLogger.LOGGER.modelDuplicateException(mde);
65 Response challengeResponse =
errorResponse(Response.Status.UNAUTHORIZED.getStatusCode(),
"invalid_request",
"Invalid user credentials");
66 context.failure(AuthenticationFlowError.INVALID_USER, challengeResponse);
72 context.getEvent().error(Errors.INVALID_USER_CREDENTIALS);
73 Response challengeResponse =
errorResponse(Response.Status.UNAUTHORIZED.getStatusCode(),
"invalid_grant",
"Invalid user credentials");
74 context.failure(AuthenticationFlowError.INVALID_USER, challengeResponse);
77 if (!user.isEnabled()) {
78 context.getEvent().user(user);
79 context.getEvent().error(Errors.USER_DISABLED);
80 Response challengeResponse =
errorResponse(Response.Status.BAD_REQUEST.getStatusCode(),
"invalid_grant",
"Account disabled");
81 context.failure(AuthenticationFlowError.INVALID_USER, challengeResponse);
84 if (context.getRealm().isBruteForceProtected()) {
85 if (context.getProtector().isTemporarilyDisabled(context.getSession(), context.getRealm(), user)) {
86 context.getEvent().user(user);
87 context.getEvent().error(Errors.USER_TEMPORARILY_DISABLED);
88 Response challengeResponse =
errorResponse(Response.Status.UNAUTHORIZED.getStatusCode(),
"invalid_grant",
"Invalid user credentials");
89 context.failure(AuthenticationFlowError.INVALID_USER, challengeResponse);
93 context.setUser(user);
Response errorResponse(int status, String error, String errorDescription)
Definition: AbstractDirectGrantAuthenticator.java:36
String retrieveUsername(AuthenticationFlowContext context)
Definition: ValidateUsername.java:157