private void checkIfTenantAlreadyExists(final STenant tenant) throws STenantAlreadyExistException { try { final String tenantName = tenant.getName(); final STenant existingTenant = getTenantByName(tenantName); if (existingTenant != null) { throw new STenantAlreadyExistException("Unable to create the tenant " + tenantName + " : it already exists."); } } catch (final STenantNotFoundException e) { if (isTraced) { logger.log(this.getClass(), TechnicalLogSeverity.TRACE, LogUtil.getLogOnExceptionMethod(this.getClass(), LOG_CREATE_TENANT, e)); } // OK } }
private void checkIfTenantAlreadyExists(final STenant tenant) throws STenantAlreadyExistException { try { final String tenantName = tenant.getName(); final STenant existingTenant = getTenantByName(tenantName); if (existingTenant != null) { throw new STenantAlreadyExistException("Unable to create the tenant " + tenantName + " : it already exists."); } } catch (final STenantNotFoundException e) { if (isTraced) { logger.log(this.getClass(), TechnicalLogSeverity.TRACE, LogUtil.getLogOnExceptionMethod(this.getClass(), LOG_CREATE_TENANT, e)); } // OK } }
protected void checkThatWeCanLogin(final String userName, final STenant sTenant, TechnicalUser technicalUser) throws LoginException { if (!sTenant.isActivated()) { throw new LoginException("Tenant " + sTenant.getName() + " is not activated !!"); } if (sTenant.isPaused()) { final String technicalUserName = technicalUser.getUserName(); if (!technicalUserName.equals(userName)) { throw new TenantStatusException("Tenant with ID " + sTenant.getId() + " is in pause, unable to login with other user than the technical user."); } } }
protected void checkThatWeCanLogin(final String userName, final STenant sTenant, TechnicalUser technicalUser) throws LoginException { if (!sTenant.isActivated()) { throw new LoginException("Tenant " + sTenant.getName() + " is not activated !!"); } if (sTenant.isPaused()) { final String technicalUserName = technicalUser.getUserName(); if (!technicalUserName.equals(userName)) { throw new TenantStatusException("Tenant with ID " + sTenant.getId() + " is in pause, unable to login with other user than the technical user."); } } }
protected APISession loginInternal(final Long tenantId, final Map<String, Serializable> credentials) throws Exception { final String userName = credentials.get(AuthenticationConstants.BASIC_USERNAME) != null ? String.valueOf(credentials .get(AuthenticationConstants.BASIC_USERNAME)) : null; final PlatformServiceAccessor platformServiceAccessor = ServiceAccessorFactory.getInstance().createPlatformServiceAccessor(); final STenant sTenant = getTenant(tenantId, platformServiceAccessor); final TenantServiceAccessor serviceAccessor = getTenantServiceAccessor(sTenant.getId()); checkThatWeCanLogin(userName, sTenant, serviceAccessor.getTechnicalUser()); final LoginService loginService = serviceAccessor.getLoginService(); final TransactionService transactionService = platformServiceAccessor.getTransactionService(); SessionAccessor sessionAccessor = serviceAccessor.getSessionAccessor(); final Map<String, Serializable> credentialsWithResolvedTenantId = new HashMap<>(credentials); credentialsWithResolvedTenantId.put(AuthenticationConstants.BASIC_TENANT_ID, sTenant.getId()); sessionAccessor.setTenantId(sTenant.getId()); try { final SSession sSession = transactionService.executeInTransaction(() -> loginService.login(credentialsWithResolvedTenantId)); return ModelConvertor.toAPISession(sSession, sTenant.getName()); } catch (Exception e) { //avoid brut force... (should be done differently, but it is the behavior since 6.0.0) Thread.sleep(3000); throw e; } }
protected APISession loginInternal(final Long tenantId, final Map<String, Serializable> credentials) throws Exception { final String userName = credentials.get(AuthenticationConstants.BASIC_USERNAME) != null ? String.valueOf(credentials .get(AuthenticationConstants.BASIC_USERNAME)) : null; final PlatformServiceAccessor platformServiceAccessor = ServiceAccessorFactory.getInstance().createPlatformServiceAccessor(); final STenant sTenant = getTenant(tenantId, platformServiceAccessor); final TenantServiceAccessor serviceAccessor = getTenantServiceAccessor(sTenant.getId()); checkThatWeCanLogin(userName, sTenant, serviceAccessor.getTechnicalUser()); final LoginService loginService = serviceAccessor.getLoginService(); final TransactionService transactionService = platformServiceAccessor.getTransactionService(); SessionAccessor sessionAccessor = serviceAccessor.getSessionAccessor(); final Map<String, Serializable> credentialsWithResolvedTenantId = new HashMap<>(credentials); credentialsWithResolvedTenantId.put(AuthenticationConstants.BASIC_TENANT_ID, sTenant.getId()); sessionAccessor.setTenantId(sTenant.getId()); try { final SSession sSession = transactionService.executeInTransaction(() -> loginService.login(credentialsWithResolvedTenantId)); return ModelConvertor.toAPISession(sSession, sTenant.getName()); } catch (Exception e) { //avoid brut force... (should be done differently, but it is the behavior since 6.0.0) Thread.sleep(3000); throw e; } }