protected boolean isUserLocked(UserEntity user) { ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration(); int maxAttempts = processEngineConfiguration.getLoginMaxAttempts(); int attempts = user.getAttempts(); if (attempts >= maxAttempts) { throw new AuthenticationException(user.getId()); } Date lockExpirationTime = user.getLockExpirationTime(); Date currentTime = ClockUtil.getCurrentTime(); return lockExpirationTime != null && lockExpirationTime.after(currentTime); }
public UserEntity createNewUser(String userId) { checkAuthorization(Permissions.CREATE, Resources.USER, null); return new UserEntity(userId); }
protected boolean matchPassword(String password, UserEntity user) { String saltedPassword = saltPassword(password, user.getSalt()); return Context.getProcessEngineConfiguration() .getPasswordManager() .check(saltedPassword, user.getPassword()); }
public void encryptPassword() { if (newPassword != null) { salt = generateSalt(); setDbPassword(encryptPassword(newPassword, salt)); } }
protected void unlockUser(UserEntity user) { if (user.getAttempts() > 0 || user.getLockExpirationTime() != null) { getIdentityInfoManager().updateUserLock(user, 0, null); } }
public String getUserId() { if (user != null) { return user.getId(); } else { return null; } }
protected UserEntity mapEntity(ResultSet rs) throws SQLException { // TODO Auto-generated method stub UserEntity user = null; if (rs != null) { user = new UserEntity(); user.setId(rs.getLong("USER_ID")); user.setFirstName(rs.getString("FIRST_NAME")); user.setMiddleName(rs.getString("MIDDLE_NAME")); user.setLastName(rs.getString("LAST_NAME")); user.setEmailAddress(rs.getString("EMAIL_ADDRESS")); String gender = rs.getString("GENDER"); if ("M".equals(gender)) { user.setGender(Gender.MALE); } else if ("F".equals(gender)) { user.setGender(Gender.FEMALE); } user.setBirthDate(rs.getDate("DOB")); user.setCreationDate(rs.getDate("CREATION_DATE")); user.setSearchable(rs.getBoolean("SEARCHABLE")); } return user; }
@Service @Transactional public class UserLoginService implements UserDetailsService { @Autowired private UserService userService; @Override public UserDetails loadUserByUsername(String userId) throws UsernameNotFoundException { UserEntity userEntity = this.userService.getUserByUserId(userId); if (userEntity == null) { throw new UsernameNotFoundException("User not found"); } UserLoginBean bean = new UserLoginBean(userEntity.getId(), userEntity.getUserId(), userEntity.getPassword(), userEntity.getEnabled()); bean.setFullname(userEntity.getFullname()); bean.setUserEntity(userEntity); Set<GrantedAuthority> roles = new HashSet<GrantedAuthority>(); roles.add( new SimpleGrantedAuthority( userEntity.getRole() ) ); bean.setAuthorities(roles); return bean; } }
EntityPersistor<UserEntity> entityPersistorMocked = mock(EntityPersistorStub.class); HashMap<String, Object> expectedParams = (HashMap<String, Object>) o; expectedParams.put("u", "hans"); UserEntity user = new UserEntity(); user.setUserId(1); user.setDisplayName("Dummy User"); user.setUsername("hans"); user.setPassword("pass"); return user; when(entityPersistorMocked.getSingleResultFromTypedQuery("SELECT u FROM UserEntity u where u.username = :u", expectedParams)).thenReturn(user);
@Override public UserEntity mapToEntity(ODocument doc, UserEntity entity, OPersistenceSession session) { UserEntity ret = super.mapToEntity(doc, entity, session); ret.setFirstName(ret.getId()); //TODO: Extend OUser return ret; }
public User saveUser(User user) { UserEntity userEntity = (UserEntity) user; // encrypt password userEntity.encryptPassword(); if(userEntity.getRevision() == 0) { checkAuthorization(Permissions.CREATE, Resources.USER, null); getDbEntityManager().insert(userEntity); createDefaultAuthorizations(userEntity); } else { checkAuthorization(Permissions.UPDATE, Resources.USER, user.getId()); getDbEntityManager().merge(userEntity); } return userEntity; }
protected void lockUser(UserEntity user) { ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration(); int max = processEngineConfiguration.getLoginDelayMaxTime(); int baseTime = processEngineConfiguration.getLoginDelayBase(); int factor = processEngineConfiguration.getLoginDelayFactor(); int attempts = user.getAttempts() + 1; long delay = (long) (baseTime * Math.pow(factor, attempts - 1)); delay = Math.min(delay, max) * 1000; long currentTime = ClockUtil.getCurrentTime().getTime(); Date lockExpirationTime = new Date(currentTime + delay); getIdentityInfoManager().updateUserLock(user, attempts, lockExpirationTime); }
public boolean checkPassword(String userId, String password) { UserEntity user = findUserById(userId); if (user == null || password == null) { return false; } if (isUserLocked(user)) { throw new AuthenticationException(userId, user.getLockExpirationTime()); } if (matchPassword(password, user)) { unlockUser(user); return true; } else { lockUser(user); return false; } }
public class CustomUser extends org.springframework.security.userdetails.User {.....} @Entity public class UserEntity {...} public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { UserEntity userEntity = this.customUserRepository.findByUsername(username); CustomUser customUser = new CustomUser( userEntity.getUsername(), userEntity.getPassword()........); return customUser; }
public String getUserId() { if (user != null) { return user.getId(); } else { return null; } }
public void encryptPassword() { if (newPassword != null) { salt = generateSalt(); setDbPassword(encryptPassword(newPassword, salt)); } }
protected void unlockUser(UserEntity user) { if (user.getAttempts() > 0 || user.getLockExpirationTime() != null) { getIdentityInfoManager().updateUserLock(user, 0, null); } }
public User saveUser(User user) { UserEntity userEntity = (UserEntity) user; // encrypt password userEntity.encryptPassword(); if(userEntity.getRevision() == 0) { checkAuthorization(Permissions.CREATE, Resources.USER, null); getDbEntityManager().insert(userEntity); createDefaultAuthorizations(userEntity); } else { checkAuthorization(Permissions.UPDATE, Resources.USER, user.getId()); getDbEntityManager().merge(userEntity); } return userEntity; }
protected void lockUser(UserEntity user) { ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration(); int max = processEngineConfiguration.getLoginDelayMaxTime(); int baseTime = processEngineConfiguration.getLoginDelayBase(); int factor = processEngineConfiguration.getLoginDelayFactor(); int attempts = user.getAttempts() + 1; long delay = (long) (baseTime * Math.pow(factor, attempts - 1)); delay = Math.min(delay, max) * 1000; long currentTime = ClockUtil.getCurrentTime().getTime(); Date lockExpirationTime = new Date(currentTime + delay); getIdentityInfoManager().updateUserLock(user, attempts, lockExpirationTime); }