use of com.haulmont.cuba.security.auth.AbstractClientCredentials in project cuba by cuba-platform.
the class ConnectionImpl method preprocessCredentials.
protected void preprocessCredentials(Credentials credentials) {
if (credentials instanceof AbstractClientCredentials) {
AbstractClientCredentials clientCredentials = (AbstractClientCredentials) credentials;
clientCredentials.setClientType(ClientType.WEB);
clientCredentials.setClientInfo(makeClientInfo());
clientCredentials.setTimeZone(detectTimeZone());
String currentUserRemoteAddress = getUserRemoteAddress();
// update userRemoteAddress if current HTTP request is available
if (currentUserRemoteAddress != null) {
this.userRemoteAddress = currentUserRemoteAddress;
}
clientCredentials.setIpAddress(userRemoteAddress);
}
}
use of com.haulmont.cuba.security.auth.AbstractClientCredentials in project cuba by cuba-platform.
the class LoginServiceController method doLogin.
protected void doLogin(String username, String password, String localeStr, HttpServletRequest request, HttpServletResponse response) throws IOException, JSONException {
Locale locale = localeFromString(localeStr);
AuthenticationService authenticationService = AppBeans.get(AuthenticationService.NAME);
try {
AbstractClientCredentials credentials = new LoginPasswordCredentials(username, passwordEncryption.getPlainHash(password), locale);
UserSession userSession = authenticationService.login(credentials).getSession();
if (!userSession.isSpecificPermitted(Authentication.PERMISSION_NAME)) {
log.info(String.format("User %s is not allowed to use REST-API", username));
AppContext.setSecurityContext(new SecurityContext(userSession));
try {
authenticationService.logout();
} finally {
AppContext.setSecurityContext(null);
}
response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
return;
}
try {
AppContext.setSecurityContext(new SecurityContext(userSession));
setSessionInfo(request, userSession);
} finally {
AppContext.setSecurityContext(null);
}
response.setStatus(HttpServletResponse.SC_OK);
PrintWriter writer = new PrintWriter(new OutputStreamWriter(response.getOutputStream(), StandardCharsets.UTF_8));
writer.write(userSession.getId().toString());
writer.close();
log.debug(String.format("User %s logged in with REST-API, session id: %s", username, userSession.getId()));
} catch (LoginException e) {
response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
}
}
Aggregations