use of io.gravitee.am.common.utils.ConstantKeys.PASSWORD_PARAM_KEY in project gravitee-access-management by gravitee-io.
the class LoginFormHandler method handle.
@Override
public void handle(RoutingContext context) {
HttpServerRequest req = context.request();
if (req.method() != HttpMethod.POST) {
// Must be a POST
context.fail(405);
} else {
if (!req.isExpectMultipart()) {
throw new IllegalStateException("Form body not parsed - do you forget to include a BodyHandler?");
}
MultiMap params = req.formAttributes();
String username = params.get(USERNAME_PARAM_KEY);
String password = params.get(PASSWORD_PARAM_KEY);
String clientId = params.get(Parameters.CLIENT_ID);
if (username == null || password == null) {
logger.warn("No username or password provided in form - did you forget to include a BodyHandler?");
context.fail(400);
} else if (clientId == null) {
logger.warn("No client id in form - did you forget to include client_id query parameter ?");
context.fail(400);
} else {
// build authentication object with ip address and user agent
JsonObject authInfo = new JsonObject().put(USERNAME_PARAM_KEY, username).put(PASSWORD_PARAM_KEY, password).put(Claims.ip_address, RequestUtils.remoteAddress(req)).put(Claims.user_agent, RequestUtils.userAgent(req)).put(Parameters.CLIENT_ID, clientId);
authProvider.authenticate(context, authInfo, res -> {
if (res.failed()) {
logger.debug("An error has occurred during the authentication process", res.cause());
context.fail(res.cause());
return;
}
// authentication success
// set user into the context and continue
final User result = res.result();
context.getDelegate().setUser(result);
context.put(ConstantKeys.USER_CONTEXT_KEY, result.getUser());
context.next();
});
}
}
}
Aggregations