public static Set<User> getMentionedUsers( String text, UserService userService ) { Set<User> users = new HashSet<>(); Matcher matcher = Pattern.compile( "(?:\\s|^)@([\\w+._-]+)" ).matcher( text ); while ( matcher.find() ) { String username = matcher.group( 1 ); UserCredentials userCredentials = userService.getUserCredentialsByUsername( username ); if ( userCredentials != null ) { users.add( userCredentials.getUserInfo() ); } } return users; }
@Override @Transactional public void saveUserSetting( UserSettingKey key, Serializable value, String username ) { UserCredentials credentials = userService.getUserCredentialsByUsername( username ); if ( credentials != null ) { saveUserSetting( key, value, credentials.getUserInfo() ); } }
@Override public String validateInvite( UserCredentials credentials ) { if ( credentials == null ) { log.warn( "Could not send invite message as user does not exist" ); return "no_user_credentials"; } if ( credentials.getUsername() != null && userService.getUserCredentialsByUsername( credentials.getUsername() ) != null ) { log.warn( "Could not send invite message as username is already taken: " + credentials ); return "username_taken"; } return validateRestore( credentials ); }
@Override public DirContextOperations authenticate( Authentication authentication ) { UserCredentials userCredentials = userService.getUserCredentialsByUsername( authentication.getName() ); if ( userCredentials == null ) { throw new BadCredentialsException( "Incorrect user credentials" ); } if ( userCredentials.hasLdapId() ) { authentication = new UsernamePasswordAuthenticationToken( userCredentials.getLdapId(), authentication.getCredentials() ); } return super.authenticate( authentication ); } }
/** * Get user setting optional. The database call is executed in a * programmatic transaction. If the user setting exists and has a value, * the value is returned. If not, the default value for the key is returned, * if not present, an empty optional is returned. * * @param key the user setting key. * @param username the username of the user. * @return an optional user setting value. */ private Optional<Serializable> getUserSettingOptional( UserSettingKey key, String username ) { UserCredentials userCredentials = userService.getUserCredentialsByUsername( username ); if ( userCredentials == null ) { return Optional.empty(); } UserSetting setting = transactionTemplate.execute( new TransactionCallback<UserSetting>() { public UserSetting doInTransaction( TransactionStatus status ) { return userSettingStore.getUserSetting( userCredentials.getUserInfo(), key.getName() ); } } ); Serializable value = setting != null && setting.hasValue() ? setting.getValue() : key.getDefaultValue(); return Optional.ofNullable( value ); }
@Override public boolean isRuleApplicable( CredentialsInfo credentialsInfo ) { UserCredentials userCredentials = userService.getUserCredentialsByUsername( credentialsInfo.getUsername() ); if ( !userService.credentialsNonExpired( userCredentials ) ) { return true; } return ( credentialsInfo.isNewUser() || !currentUserService.getCurrentUsername().equals( credentialsInfo.getUsername() ) ) ? false : true; } }
UserCredentials userCredentials = userService.getUserCredentialsByUsername( username );
throws UsernameNotFoundException, DataAccessException UserCredentials credentials = userService.getUserCredentialsByUsername( username );
@Override public PasswordValidationResult validate( CredentialsInfo credentialsInfo ) { boolean match; UserCredentials userCredentials = userService.getUserCredentialsByUsername( credentialsInfo.getUsername() ); List<String> previousPasswords = userCredentials.getPreviousPasswords(); for ( String encodedPassword : previousPasswords ) { match = passwordEncoder.matches( credentialsInfo.getPassword(), encodedPassword ); if ( match ) { return new PasswordValidationResult( String.format( "Password must not be one of the previous %d passwords", HISTORY_LIMIT ), "password_history_validation", false ); } } if ( previousPasswords.size() == HISTORY_LIMIT ) { userCredentials.getPreviousPasswords().remove( 0 ); userService.updateUserCredentials( userCredentials ); } return new PasswordValidationResult( true ); }
if ( userService.getUserCredentialsByUsername( value ) == null )
UserCredentials anonymousUser = userService.getUserCredentialsByUsername( userName ); userService.addUser( user ); anonymousUser = userService.getUserCredentialsByUsername( userName );