@Handle
public JSONObject handle(
HttpServletRequest request
) throws Exception {
final String username = UrlUtils.urlDecode(request.getParameter("username")).trim().toLowerCase();
User user = userRepository.findByUsername(username);
if (user == null) {
String randomPassword = UserRepository.createRandomPassword();
user = userRepository.findOrAddUser(
username,
username,
null,
randomPassword
);
}
AuthorizationContext authorizationContext = new UserNameAuthorizationContext(
username,
RemoteAddressUtil.getClientIpAddr(request)
);
userRepository.updateUser(user, authorizationContext);
CurrentUser.set(request, user.getUserId(), user.getUsername());
auditService.auditLogin(user);
JSONObject json = new JSONObject();
json.put("status", "OK");
return json;
}
}