use of com.haulmont.cuba.security.auth.AbstractClientCredentials in project cuba by cuba-platform.
the class PortalConnection 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 ipAddress user IP address
* @param clientInfo client info
* @return created user session
* @throws LoginException in case of unsuccessful login
*/
protected UserSession doLogin(String login, String password, Locale locale, String ipAddress, String clientInfo, Map<String, Object> params) throws LoginException {
AbstractClientCredentials credentials = new LoginPasswordCredentials(login, password, locale);
credentials.setParams(params);
credentials.setClientType(ClientType.PORTAL);
credentials.setIpAddress(ipAddress);
credentials.setClientInfo(clientInfo);
return authenticationService.login(credentials).getSession();
}
use of com.haulmont.cuba.security.auth.AbstractClientCredentials in project cuba by cuba-platform.
the class BruteForceUserCredentialsChecker method onAuthenticationFailure.
@Order(Events.HIGHEST_PLATFORM_PRECEDENCE + 10)
@EventListener
protected void onAuthenticationFailure(AuthenticationFailureEvent event) throws LoginException {
if (bruteForceProtectionAPI.isBruteForceProtectionEnabled()) {
Credentials credentials = event.getCredentials();
if (credentials instanceof AbstractClientCredentials) {
AbstractClientCredentials clientCredentials = (AbstractClientCredentials) credentials;
if (clientCredentials.isCheckClientPermissions()) {
int loginAttemptsLeft = bruteForceProtectionAPI.registerUnsuccessfulLogin(clientCredentials.getUserIdentifier(), clientCredentials.getIpAddress());
String message;
if (loginAttemptsLeft > 0) {
message = messages.formatMessage(MSG_PACK, "LoginException.loginFailedAttemptsLeft", loginAttemptsLeft);
} else {
message = messages.formatMessage(MSG_PACK, "LoginException.loginAttemptsNumberExceeded", bruteForceProtectionAPI.getBruteForceBlockIntervalSec());
}
throw new LoginException(message);
}
}
}
}
use of com.haulmont.cuba.security.auth.AbstractClientCredentials in project cuba by cuba-platform.
the class ClientTypeUserAccessChecker method check.
@Override
public void check(Credentials credentials, AuthenticationDetails authenticationDetails) throws LoginException {
if (credentials instanceof AbstractClientCredentials) {
AbstractClientCredentials clientCredentials = (AbstractClientCredentials) credentials;
if (clientCredentials.isCheckClientPermissions()) {
ClientType clientType = clientCredentials.getClientType();
if (ClientType.DESKTOP == clientType || ClientType.WEB == clientType) {
if (!authenticationDetails.getSession().isSpecificPermitted("cuba.gui.loginToClient")) {
log.warn("Attempt of login to {} for user '{}' without cuba.gui.loginToClient permission", clientType, clientCredentials);
Locale userLocale;
if (clientCredentials.getLocale() != null) {
userLocale = clientCredentials.getLocale();
} else {
userLocale = messages.getTools().getDefaultLocale();
}
throw new LoginException(getInvalidCredentialsMessage(clientCredentials.getUserIdentifier(), userLocale));
}
}
}
}
}
use of com.haulmont.cuba.security.auth.AbstractClientCredentials 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.auth.AbstractClientCredentials 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();
}
Aggregations