/** * 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 { LoginPasswordCredentials credentials = new LoginPasswordCredentials(login, password, locale); credentials.setParams(params); credentials.setClientType(ClientType.PORTAL); credentials.setIpAddress(ipAddress); credentials.setClientInfo(clientInfo); if (portalConfig.getCheckPasswordOnClient()) { return loginClient(credentials).getSession(); } else { return loginMiddleware(credentials).getSession(); } }
protected TrustedClientCredentials createTrustedCredentials(LoginPasswordCredentials credentials) { TrustedClientCredentials tcCredentials = new TrustedClientCredentials( credentials.getLogin(), webAuthConfig.getTrustedClientPassword(), credentials.getLocale(), credentials.getParams() ); tcCredentials.setClientInfo(credentials.getClientInfo()); tcCredentials.setClientType(ClientType.WEB); tcCredentials.setIpAddress(credentials.getIpAddress()); tcCredentials.setOverrideLocale(credentials.isOverrideLocale()); tcCredentials.setSyncNewUserSessionReplication(credentials.isSyncNewUserSessionReplication()); tcCredentials.setSessionAttributes(credentials.getSessionAttributes()); return tcCredentials; }
@SuppressWarnings("RedundantThrows") protected boolean authenticateInLdap(LoginPasswordCredentials credentials) throws LoginException { String login = credentials.getLogin(); String password = credentials.getPassword(); return ldapTemplate.authenticate(LdapUtils.emptyLdapName(), buildPersonFilter(login), password); }
protected AuthenticationDetails loginClient(LoginPasswordCredentials credentials) { String login = credentials.getLogin(); Locale credentialsLocale = credentials.getLocale() == null ? messages.getTools().getDefaultLocale() : credentials.getLocale(); if (Strings.isNullOrEmpty(login)) { // empty login is not valid throw new LoginException(getInvalidCredentialsMessage(login, credentialsLocale)); } UserSession systemSession = trustedClientService.getSystemSession(portalConfig.getTrustedClientPassword()); User user = AppContext.withSecurityContext(new SecurityContext(systemSession), () -> usersRepository.findUserByLogin(login)); if (user == null) { throw new LoginException(getInvalidCredentialsMessage(login, credentialsLocale)); } if (!passwordEncryption.checkPassword(user, credentials.getPassword())) { throw new LoginException(getInvalidCredentialsMessage(login, credentialsLocale)); } return authenticationService.login(createTrustedCredentials(credentials)); }
LoginPasswordCredentials credentials = new LoginPasswordCredentials(login, (String) token.getCredentials()); credentials.setIpAddress(ipAddress); credentials.setClientType(ClientType.REST_API); credentials.setClientInfo(makeClientInfo(request.getHeader(HttpHeaders.USER_AGENT))); credentials.setLocale(locale); credentials.setOverrideLocale(true); } else { credentials.setOverrideLocale(false);
/** * Log in to the system. * * @param login user login name * @param password encrypted user password * @param locale user locale * @throws LoginException in case of unsuccessful login due to wrong credentials or other issues */ @Deprecated default void login(String login, String password, Locale locale) throws LoginException { login(new LoginPasswordCredentials(login, password, locale)); }
LoginPasswordCredentials credentials = new LoginPasswordCredentials( auth.getUsername(), passwordEncryption.getPlainHash(auth.getPassword()), sessionLocale); credentials.setClientType(ClientType.WEB);
@Override public String getUserIdentifier() { return getLogin(); }
protected AuthenticationDetails loginClient(LoginPasswordCredentials credentials) { String login = credentials.getLogin(); Locale credentialsLocale = credentials.getLocale() == null ? messages.getTools().getDefaultLocale() : credentials.getLocale(); if (Strings.isNullOrEmpty(login)) { // empty login is not valid throw new LoginException(getInvalidCredentialsMessage(login, credentialsLocale)); } UserSession systemSession = trustedClientService.getSystemSession(restApiConfig.getTrustedClientPassword()); User user = AppContext.withSecurityContext(new SecurityContext(systemSession), () -> usersRepository.findUserByLogin(login)); if (user == null) { throw new LoginException(getInvalidCredentialsMessage(login, credentialsLocale)); } if (!passwordEncryption.checkPassword(user, credentials.getPassword())) { throw new LoginException(getInvalidCredentialsMessage(login, credentialsLocale)); } return authenticationService.login(createTrustedCredentials(credentials)); }
@Override public UserSession login(String login, String password, Locale locale, Map<String, Object> params) throws LoginException { return authenticationManager.login(new LoginPasswordCredentials(login, password, locale, params)).getSession(); }
protected TrustedClientCredentials createTrustedCredentials(LoginPasswordCredentials credentials) { TrustedClientCredentials tcCredentials = new TrustedClientCredentials( credentials.getLogin(), portalConfig.getTrustedClientPassword(), credentials.getLocale(), credentials.getParams() ); tcCredentials.setClientInfo(credentials.getClientInfo()); tcCredentials.setClientType(ClientType.PORTAL); tcCredentials.setIpAddress(credentials.getIpAddress()); tcCredentials.setOverrideLocale(credentials.isOverrideLocale()); tcCredentials.setSyncNewUserSessionReplication(credentials.isSyncNewUserSessionReplication()); tcCredentials.setSessionAttributes(credentials.getSessionAttributes()); return tcCredentials; }
protected AuthenticationDetails loginClient(LoginPasswordCredentials credentials) { String login = credentials.getLogin(); Locale credentialsLocale = credentials.getLocale() == null ? messages.getTools().getDefaultLocale() : credentials.getLocale(); if (Strings.isNullOrEmpty(login)) { // empty login is not valid throw new LoginException(getInvalidCredentialsMessage(login, credentialsLocale)); } UserSession systemSession = trustedClientService.getSystemSession(webAuthConfig.getTrustedClientPassword()); User user = AppContext.withSecurityContext(new SecurityContext(systemSession), () -> usersRepository.findUserByLogin(login)); if (user == null) { throw new LoginException(getInvalidCredentialsMessage(login, credentialsLocale)); } if (!passwordEncryption.checkPassword(user, credentials.getPassword())) { throw new LoginException(getInvalidCredentialsMessage(login, credentialsLocale)); } return authenticationService.login(createTrustedCredentials(credentials)); }
@Override public UserSession login(String login, String password, Locale locale, Map<String, Object> params) throws LoginException { LoginPasswordCredentials credentials = new LoginPasswordCredentials(login, password, locale, params); copyParamsToCredentials(params, credentials); return authenticationService.login(credentials).getSession(); }
protected TrustedClientCredentials createTrustedCredentials(LoginPasswordCredentials credentials) { TrustedClientCredentials tcCredentials = new TrustedClientCredentials( credentials.getLogin(), restApiConfig.getTrustedClientPassword(), credentials.getLocale(), credentials.getParams() ); tcCredentials.setClientInfo(credentials.getClientInfo()); tcCredentials.setClientType(ClientType.REST_API); tcCredentials.setIpAddress(credentials.getIpAddress()); tcCredentials.setOverrideLocale(credentials.isOverrideLocale()); tcCredentials.setSyncNewUserSessionReplication(credentials.isSyncNewUserSessionReplication()); tcCredentials.setSessionAttributes(credentials.getSessionAttributes()); return tcCredentials; }
@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; }
@Override public User authenticate(String login, String password, Locale locale, Map<String, Object> params) throws LoginException { LoginPasswordCredentials credentials = new LoginPasswordCredentials(login, password, locale, params); copyParamsToCredentials(params, credentials); AuthenticationDetails sessionDetails = authenticationManager.authenticate(credentials); return sessionDetails.getSession().getUser(); }
LoginPasswordCredentials loginPassword = (LoginPasswordCredentials) credentials; if (webAuthConfig.getStandardAuthenticationUsers().contains(loginPassword.getLogin())) { log.debug("User {} is not allowed to use external login"); return null; authProvider.authenticate(loginPassword.getLogin(), loginPassword.getPassword(), loginPassword.getLocale()); String systemLogin = convertLoginString(loginPassword.getLogin()); loginPassword.getLocale(), loginPassword.getParams() ); trustedClientCredentials.setClientInfo(loginPassword.getClientInfo()); trustedClientCredentials.setClientType(ClientType.WEB); trustedClientCredentials.setIpAddress(loginPassword.getIpAddress()); trustedClientCredentials.setOverrideLocale(loginPassword.isOverrideLocale()); trustedClientCredentials.setSyncNewUserSessionReplication(loginPassword.isSyncNewUserSessionReplication()); Map<String, Serializable> sessionAttributes = loginPassword.getSessionAttributes(); Map<String, Serializable> targetSessionAttributes; if (sessionAttributes != null
AbstractClientCredentials credentials = new LoginPasswordCredentials(username, password, locale); UserSession userSession = authenticationService.login(credentials).getSession();
LoginPasswordCredentials loginPasswordCredentials = (LoginPasswordCredentials) credentials; if (webAuthConfig.getStandardAuthenticationUsers().contains(loginPasswordCredentials.getLogin())) { log.debug("User {} is not allowed to use external login"); return null; Locale locale = loginPasswordCredentials.getLocale(); if (locale == null) { locale = messages.getTools().getDefaultLocale(); locale, loginPasswordCredentials.getLogin()) ); loginPasswordCredentials.getLogin(), webAuthConfig.getTrustedClientPassword(), loginPasswordCredentials.getLocale(), loginPasswordCredentials.getParams() ); tcCredentials.setClientInfo(loginPasswordCredentials.getClientInfo()); tcCredentials.setClientType(ClientType.WEB); tcCredentials.setIpAddress(loginPasswordCredentials.getIpAddress()); tcCredentials.setOverrideLocale(loginPasswordCredentials.isOverrideLocale()); tcCredentials.setSyncNewUserSessionReplication(loginPasswordCredentials.isSyncNewUserSessionReplication());
doLogin(new RememberMeCredentials(login, password, selectedLocale)); } else { doLogin(new LoginPasswordCredentials(login, password, selectedLocale));