use of com.haulmont.cuba.security.auth.AuthenticationService in project cuba by cuba-platform.
the class Connection method logout.
public void logout() {
try {
AuthenticationService authenticationService = AppBeans.get(AuthenticationService.NAME);
authenticationService.logout();
AppContext.setSecurityContext(null);
log.info("Logged out: " + session);
} catch (Exception e) {
log.warn("Error on logout", e);
}
connected = false;
try {
fireConnectionListeners();
} catch (LoginException e) {
log.warn("Error on logout", e);
}
session = null;
}
use of com.haulmont.cuba.security.auth.AuthenticationService in project cuba by cuba-platform.
the class Connection method doLogin.
/**
* Forward login logic to {@link com.haulmont.cuba.security.auth.AuthenticationService}.
* Can be overridden to change login logic.
*
* @param login login name
* @param password encrypted password
* @param locale client locale
* @param loginParams login parameters
* @return created user session
* @throws LoginException in case of unsuccessful login
*/
protected UserSession doLogin(String login, String password, Locale locale, Map<String, Object> loginParams) throws LoginException {
AbstractClientCredentials credentials = new LoginPasswordCredentials(login, password, locale);
setCredentialsParams(credentials, loginParams);
AuthenticationService authenticationService = AppBeans.get(AuthenticationService.NAME);
return authenticationService.login(credentials).getSession();
}
use of com.haulmont.cuba.security.auth.AuthenticationService in project cuba by cuba-platform.
the class LoginServiceController method doLogout.
protected void doLogout(String sessionUUID, HttpServletResponse response) throws IOException, JSONException {
try {
if (authentication.begin(sessionUUID)) {
AuthenticationService authenticationService = AppBeans.get(AuthenticationService.NAME);
authenticationService.logout();
}
} catch (Throwable e) {
log.error("Error processing logout request", e);
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
}
use of com.haulmont.cuba.security.auth.AuthenticationService 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