use of com.haulmont.cuba.security.global.UserSession in project cuba by cuba-platform.
the class IpMaskUserAccessChecker method check.
@Override
public void check(Credentials credentials, AuthenticationDetails authenticationDetails) throws LoginException {
if (credentials instanceof AbstractClientCredentials) {
AbstractClientCredentials clientCredentials = (AbstractClientCredentials) credentials;
if (clientCredentials.isCheckClientPermissions() && clientCredentials.getIpAddress() != null) {
String ipAddress = clientCredentials.getIpAddress();
UserSession session = authenticationDetails.getSession();
if (session.getUser().getIpMask() != null) {
IpMatcher ipMatcher = new IpMatcher(session.getUser().getIpMask());
if (!ipMatcher.match(ipAddress)) {
log.info("IP address {} is not permitted for user {}", ipAddress, session.getUser());
throw new UserIpRestrictedException(messages.getMessage(MSG_PACK, "LoginException.invalidIP"));
}
}
}
}
}
use of com.haulmont.cuba.security.global.UserSession in project cuba by cuba-platform.
the class AnonymousAuthenticationProvider method authenticate.
@Override
public AuthenticationDetails authenticate(Credentials credentials) throws LoginException {
AnonymousUserCredentials anonymous = (AnonymousUserCredentials) credentials;
String login = serverConfig.getAnonymousLogin();
Locale credentialsLocale = anonymous.getLocale() == null ? messages.getTools().trimLocale(messages.getTools().getDefaultLocale()) : anonymous.getLocale();
User user = loadUser(login);
if (user == null) {
throw new LoginException(getInvalidCredentialsMessage(login, credentialsLocale));
}
Locale userLocale = getUserLocale(anonymous, user);
UUID anonymousSessionId = globalConfig.getAnonymousSessionId();
UserSession session = createSession(anonymous, user, userLocale, anonymousSessionId);
session.setClientInfo("System anonymous session");
return new SimpleAuthenticationDetails(session);
}
use of com.haulmont.cuba.security.global.UserSession in project cuba by cuba-platform.
the class LoginPasswordAuthenticationProvider method authenticate.
@Override
public AuthenticationDetails authenticate(Credentials credentials) throws LoginException {
LoginPasswordCredentials loginAndPassword = (LoginPasswordCredentials) credentials;
String login = loginAndPassword.getLogin();
Locale credentialsLocale = loginAndPassword.getLocale() == null ? messages.getTools().getDefaultLocale() : loginAndPassword.getLocale();
if (Strings.isNullOrEmpty(login)) {
// empty login is not valid
throw new LoginException(getInvalidCredentialsMessage(login, credentialsLocale));
}
checkUserCredentials(credentials);
User user = loadUser(login);
if (user == null) {
throw new LoginException(getInvalidCredentialsMessage(login, credentialsLocale));
}
if (!passwordEncryption.checkPassword(user, loginAndPassword.getPassword())) {
throw new LoginException(getInvalidCredentialsMessage(login, credentialsLocale));
}
Locale userLocale = getUserLocale(loginAndPassword, user);
UserSession session = createSession(loginAndPassword, user, userLocale);
setClientSessionParams(loginAndPassword, session);
AuthenticationDetails authenticationDetails = new SimpleAuthenticationDetails(session);
checkUserAccess(loginAndPassword, authenticationDetails);
return authenticationDetails;
}
use of com.haulmont.cuba.security.global.UserSession in project cuba by cuba-platform.
the class SystemAuthenticationProvider method authenticate.
@Override
public AuthenticationDetails authenticate(Credentials credentials) throws LoginException {
SystemUserCredentials systemLogin = (SystemUserCredentials) credentials;
String login = systemLogin.getLogin();
Locale credentialsLocale = systemLogin.getLocale() == null ? messages.getTools().getDefaultLocale() : systemLogin.getLocale();
User user = loadUser(login);
if (user == null) {
throw new LoginException(getInvalidCredentialsMessage(login, credentialsLocale));
}
Locale userLocale = getUserLocale(systemLogin, user);
UserSession session = userSessionManager.createSession(user, userLocale, true);
return new SimpleAuthenticationDetails(session);
}
use of com.haulmont.cuba.security.global.UserSession in project cuba by cuba-platform.
the class TrustedClientAuthenticationProvider method authenticate.
@Override
public AuthenticationDetails authenticate(Credentials credentials) throws LoginException {
TrustedClientCredentials trustedClient = (TrustedClientCredentials) credentials;
String login = trustedClient.getLogin();
Locale credentialsLocale = trustedClient.getLocale() == null ? messages.getTools().getDefaultLocale() : trustedClient.getLocale();
if (Strings.isNullOrEmpty(login)) {
throw new LoginException(getInvalidCredentialsMessage(login, credentialsLocale));
}
User user = loadUser(login);
if (user == null) {
throw new LoginException(getInvalidCredentialsMessage(login, credentialsLocale));
}
if (trustedClient.getClientIpAddress() != null) {
// reject request from not permitted client IP
if (!trustedLoginHandler.checkAddress(trustedClient.getClientIpAddress())) {
log.warn("Attempt of trusted login from not permitted IP address: {} {}", login, trustedClient.getClientIpAddress());
throw new LoginException(getInvalidCredentialsMessage(login, credentialsLocale));
}
} else {
log.trace("Unable to check trusted client IP for user {}. It is OK in case of local service invocation mode", trustedClient.getLogin());
}
if (!trustedLoginHandler.checkPassword(trustedClient.getTrustedClientPassword())) {
throw new LoginException(getInvalidCredentialsMessage(login, credentialsLocale));
}
Locale userLocale = getUserLocale(trustedClient, user);
UserSession session = createSession(trustedClient, user, userLocale);
setClientSessionParams(trustedClient, session);
AuthenticationDetails authenticationDetails = new SimpleAuthenticationDetails(session);
checkUserAccess(trustedClient, authenticationDetails);
return authenticationDetails;
}
Aggregations