public String getPolicyId() { if ( policy == null ) { return "<null>"; } return policy.getId(); }
/** * Add a violation to the underlying list. * * @param key the bundle/localization key for the message. */ public void addViolation( String key ) { addViolation(key, null); }
public void setPreviousPasswordCount( int previousPasswordCount ) { securityPolicy.setPreviousPasswordsCount( previousPasswordCount ); }
public void validatePassword( User user ) throws PasswordRuleViolationException if ( isEnabled() ) PasswordRuleViolations violations = new PasswordRuleViolations(); if ( rule.isEnabled() ) if ( rule.requiresSecurityPolicy() ) rule.setUserSecurityPolicy( this ); rule.testPassword( violations, user ); if ( violations.hasViolations() ) PasswordRuleViolationException exception = new PasswordRuleViolationException(); exception.setViolations( violations ); throw exception;
public void testPassword( PasswordRuleViolations violations, User user ) { String password = user.getPassword(); if ( hasReusedPassword( user, password ) ) { violations.addViolation( REUSE_VIOLATION, new Object[]{String.valueOf( getPreviousPasswordCount() )} ); //$NON-NLS-1$ } }
public User updateUser( User user ) { // If password is supplied, assume changing of password. // TODO: Consider adding a boolean to the updateUser indicating a password change or not. if ( StringUtils.isNotEmpty( user.getPassword() ) ) { userSecurityPolicy.extensionChangePassword( user ); } saveUser( user ); fireUserManagerUserUpdated( user ); return user; }
public boolean isEnabled() { Boolean bool = (Boolean) PolicyContext.getContext().get( ENABLEMENT_KEY ); return bool == null || bool.booleanValue(); }
public void setEnabled( boolean enabled ) { PolicyContext.getContext().put( ENABLEMENT_KEY, Boolean.valueOf( enabled ) ); }
public static PolicyContext getContext() { PolicyContext ctx = (PolicyContext) policyContext.get(); if ( ctx == null ) { ctx = new PolicyContext( new HashMap() ); setContext( ctx ); } return ctx; }
public void testPassword( PasswordRuleViolations violations, User user ) { if ( countAlphaCharacters( user.getPassword() ) < this.minimumCount ) { violations.addViolation( ALPHA_COUNT_VIOLATION, new Object[]{String.valueOf( minimumCount )} ); //$NON-NLS-1$ } }
public void testPassword( PasswordRuleViolations violations, User user ) { if ( countDigitCharacters( user.getPassword() ) < this.minimumCount ) { violations.addViolation( NUMERICAL_COUNT_VIOLATION, new Object[]{String.valueOf( minimumCount )} ); //$NON-NLS-1$ } }
public void extensionExcessiveLoginAttempts( User user ) throws AccountLockedException { int attempt = user.getCountFailedLoginAttempts(); attempt++; user.setCountFailedLoginAttempts( attempt ); if ( attempt >= loginAttemptCount ) { user.setLocked( true ); throw new AccountLockedException( "Account " + user.getUsername() + " is locked.", user ); } }
/** * Add a violation to the underlying list. * * @param key the bundle/localization key for the message. * @param args the arguments for the message. */ public void addViolation( String key, Object args[] ) { MessageReference mesgref = new MessageReference(); mesgref.key = key; mesgref.args = args; violations.add( mesgref ); }
public int getPreviousPasswordCount() { if ( securityPolicy == null ) { throw new IllegalStateException( "The security policy has not yet been set." ); } return securityPolicy.getPreviousPasswordsCount(); }
/** * Add a Specific Rule to the Password Rules List. * * @param rule the rule to add. */ public void addPasswordRule( PasswordRule rule ) { // TODO: check for duplicates? if so, check should only be based on Rule class name. rule.setUserSecurityPolicy( this ); this.rules.add( rule ); }
protected Object initialValue() { return new PolicyContext( new HashMap() ); } }
public void extensionPasswordExpiration( User user ) throws MustChangePasswordException { Calendar expirationDate = Calendar.getInstance(); expirationDate.setTime( user.getLastPasswordChange() ); expirationDate.add( Calendar.DAY_OF_MONTH, passwordExpirationDays ); Calendar now = Calendar.getInstance(); if ( now.after( expirationDate ) ) { user.setLocked( true ); user.setPasswordChangeRequired( true ); throw new MustChangePasswordException( "Password Expired, You must change your password." ); } }
public User addUser( User user ) { saveUser( user ); fireUserManagerUserAdded( user ); // If there exists no encoded password, then this is a new user setup if ( StringUtils.isEmpty( user.getEncodedPassword() ) ) { userSecurityPolicy.extensionChangePassword( user ); } return user; }
public void testPassword( PasswordRuleViolations violations, User user ) { if ( StringUtils.isEmpty( user.getPassword() ) ) { violations.addViolation( MISSING_PASSWORD_VIOLATION ); //$NON-NLS-1$ } }
public void testPassword( PasswordRuleViolations violations, User user ) { char[] password = user.getPassword().toCharArray(); for ( int i = 0; i < password.length; i++ ) { if ( !Character.isLetterOrDigit( password[i] ) ) { violations.addViolation( ALPHANUM_VIOLATION ); return; } } }