Author: jbonofre Date: Wed Dec 19 15:58:27 2012 New Revision: 1423908 URL: http://svn.apache.org/viewvc?rev=1423908&view=rev Log: [SYNCOPE-242] Move SyncopeUserValidator back into validation.entity as it is referenced from the @SyncopeUserCheck annotation
Added: syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/validation/entity/SyncopeUserValidator.java - copied, changed from r1423830, syncope/trunk/core/src/main/java/org/apache/syncope/core/validation/user/SyncopeUserValidator.java syncope/trunk/core/src/main/java/org/apache/syncope/core/policy/impl/ syncope/trunk/core/src/main/java/org/apache/syncope/core/policy/impl/AccountPolicyEnforcerImpl.java - copied, changed from r1423830, syncope/trunk/core/src/main/java/org/apache/syncope/core/policy/AccountPolicyEnforcer.java syncope/trunk/core/src/main/java/org/apache/syncope/core/policy/impl/PasswordPolicyEnforcerImpl.java - copied, changed from r1423830, syncope/trunk/core/src/main/java/org/apache/syncope/core/policy/PasswordPolicyEnforcer.java Removed: syncope/trunk/core/src/main/java/org/apache/syncope/core/validation/user/SyncopeUserValidator.java Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/validation/entity/SyncopeUserCheck.java syncope/trunk/core/src/main/java/org/apache/syncope/core/policy/AccountPolicyEnforcer.java syncope/trunk/core/src/main/java/org/apache/syncope/core/policy/PasswordPolicyEnforcer.java syncope/trunk/core/src/main/java/org/apache/syncope/core/policy/PolicyEnforceException.java syncope/trunk/core/src/main/resources/persistenceContext.xml Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/validation/entity/SyncopeUserCheck.java URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/validation/entity/SyncopeUserCheck.java?rev=1423908&r1=1423907&r2=1423908&view=diff ============================================================================== --- syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/validation/entity/SyncopeUserCheck.java (original) +++ syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/validation/entity/SyncopeUserCheck.java Wed Dec 19 15:58:27 2012 @@ -26,7 +26,6 @@ import java.lang.annotation.Target; import javax.validation.Constraint; import javax.validation.Payload; -import org.apache.syncope.core.validation.user.SyncopeUserValidator; @Target( { ElementType.TYPE }) @Retention(RetentionPolicy.RUNTIME) Copied: syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/validation/entity/SyncopeUserValidator.java (from r1423830, syncope/trunk/core/src/main/java/org/apache/syncope/core/validation/user/SyncopeUserValidator.java) URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/validation/entity/SyncopeUserValidator.java?p2=syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/validation/entity/SyncopeUserValidator.java&p1=syncope/trunk/core/src/main/java/org/apache/syncope/core/validation/user/SyncopeUserValidator.java&r1=1423830&r2=1423908&rev=1423908&view=diff ============================================================================== --- syncope/trunk/core/src/main/java/org/apache/syncope/core/validation/user/SyncopeUserValidator.java (original) +++ syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/validation/entity/SyncopeUserValidator.java Wed Dec 19 15:58:27 2012 @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.syncope.core.validation.user; +package org.apache.syncope.core.persistence.validation.entity; import java.util.ArrayList; import java.util.List; @@ -29,8 +29,6 @@ import org.apache.syncope.core.persisten import org.apache.syncope.core.persistence.beans.role.SyncopeRole; import org.apache.syncope.core.persistence.beans.user.SyncopeUser; import org.apache.syncope.core.persistence.dao.PolicyDAO; -import org.apache.syncope.core.persistence.validation.entity.AbstractValidator; -import org.apache.syncope.core.persistence.validation.entity.SyncopeUserCheck; import org.apache.syncope.core.policy.AccountPolicyEnforcer; import org.apache.syncope.core.policy.PasswordPolicyEnforcer; import org.apache.syncope.core.policy.PolicyEvaluator; Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/policy/AccountPolicyEnforcer.java URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/policy/AccountPolicyEnforcer.java?rev=1423908&r1=1423907&r2=1423908&view=diff ============================================================================== --- syncope/trunk/core/src/main/java/org/apache/syncope/core/policy/AccountPolicyEnforcer.java (original) +++ syncope/trunk/core/src/main/java/org/apache/syncope/core/policy/AccountPolicyEnforcer.java Wed Dec 19 15:58:27 2012 @@ -18,123 +18,14 @@ */ package org.apache.syncope.core.policy; -import java.util.List; -import java.util.Map; -import java.util.regex.Pattern; -import org.apache.commons.collections.keyvalue.DefaultMapEntry; -import org.apache.syncope.client.to.UserTO; -import org.apache.syncope.core.persistence.beans.PropagationTask; import org.apache.syncope.core.persistence.beans.user.SyncopeUser; -import org.apache.syncope.core.propagation.PropagationManager; -import org.apache.syncope.core.propagation.PropagationTaskExecutor; -import org.apache.syncope.core.rest.data.UserDataBinder; -import org.apache.syncope.core.workflow.user.UserWorkflowAdapter; -import org.apache.syncope.core.workflow.WorkflowResult; import org.apache.syncope.types.AccountPolicySpec; import org.apache.syncope.types.PolicyType; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; -@Component -public class AccountPolicyEnforcer extends PolicyEnforcer<AccountPolicySpec, SyncopeUser> { +public interface AccountPolicyEnforcer { - @Autowired - private UserWorkflowAdapter uwfAdapter; + public abstract void enforce(AccountPolicySpec policy, PolicyType type, + SyncopeUser user) throws AccountPolicyException, + PolicyEnforceException; - @Autowired - private PropagationManager propagationManager; - - @Autowired - private PropagationTaskExecutor taskExecutor; - - @Autowired - private UserDataBinder userDataBinder; - - private static final Pattern PATTERN = Pattern.compile("[a-zA-Z0-9-_@. ]+"); - - private static final Pattern LCPATTERN = Pattern.compile("[a-z0-9-_@. ]+"); - - private static final Pattern UCPATTERN = Pattern.compile("[A-Z0-9-_@. ]+"); - - @Override - public void enforce(final AccountPolicySpec policy, final PolicyType type, final SyncopeUser user) - throws AccountPolicyException, PolicyEnforceException { - - if (user.getUsername() == null) { - throw new PolicyEnforceException("Invalid account"); - } - - if (policy == null) { - throw new PolicyEnforceException("Invalid policy"); - } - - // check min length - if (policy.getMinLength() > 0 && policy.getMinLength() > user.getUsername().length()) { - throw new AccountPolicyException("Username too short"); - } - - // check max length - if (policy.getMaxLength() > 0 && policy.getMaxLength() < user.getUsername().length()) { - throw new AccountPolicyException("Username too long"); - } - - // check words not permitted - for (String word : policy.getWordsNotPermitted()) { - if (user.getUsername().contains(word)) { - throw new AccountPolicyException("Used word(s) not permitted"); - } - } - - // check syntax - if ((policy.isAllLowerCase() && !LCPATTERN.matcher(user.getUsername()).matches()) - || (policy.isAllUpperCase() && !UCPATTERN.matcher(user.getUsername()).matches()) - || !PATTERN.matcher(user.getUsername()).matches()) { - throw new AccountPolicyException("Invalid username syntax"); - } - - // check prefix - for (String prefix : policy.getPrefixesNotPermitted()) { - if (user.getUsername().startsWith(prefix)) { - throw new AccountPolicyException("Prefix not permitted"); - } - } - - // check suffix - for (String suffix : policy.getSuffixesNotPermitted()) { - if (user.getUsername().endsWith(suffix)) { - throw new AccountPolicyException("Suffix not permitted"); - } - } - - // check for subsequent failed logins - if (user.getFailedLogins() != null && policy.getPermittedLoginRetries() > 0 - && user.getFailedLogins() > policy.getPermittedLoginRetries() && !user.getSuspended()) { - try { - LOG.debug("User {}:{} is over to max failed logins", user.getId(), user.getUsername()); - - // reduce failed logins number to avoid multiple request - user.setFailedLogins(user.getFailedLogins() - 1); - - // disable user - final WorkflowResult<Long> updated = uwfAdapter.suspend(user); - - // propagate suspension if and only if it is required by policy - if (policy.isPropagateSuspension()) { - final List<PropagationTask> tasks = propagationManager.getUserUpdateTaskIds( - new WorkflowResult<Map.Entry<Long, Boolean>>( - new DefaultMapEntry(updated.getResult(), Boolean.FALSE), - updated.getPropByRes(), updated.getPerformedTasks())); - - taskExecutor.execute(tasks); - } - - if (LOG.isDebugEnabled()) { - final UserTO savedTO = userDataBinder.getUserTO(updated.getResult()); - LOG.debug("About to return suspended user\n{}", savedTO); - } - } catch (Exception e) { - LOG.error("Error during user suspension", e); - } - } - } -} +} \ No newline at end of file Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/policy/PasswordPolicyEnforcer.java URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/policy/PasswordPolicyEnforcer.java?rev=1423908&r1=1423907&r2=1423908&view=diff ============================================================================== --- syncope/trunk/core/src/main/java/org/apache/syncope/core/policy/PasswordPolicyEnforcer.java (original) +++ syncope/trunk/core/src/main/java/org/apache/syncope/core/policy/PasswordPolicyEnforcer.java Wed Dec 19 15:58:27 2012 @@ -20,174 +20,11 @@ package org.apache.syncope.core.policy; import org.apache.syncope.types.PasswordPolicySpec; import org.apache.syncope.types.PolicyType; -import org.springframework.stereotype.Component; -@Component -public class PasswordPolicyEnforcer extends PolicyEnforcer<PasswordPolicySpec, String> { +public interface PasswordPolicyEnforcer { - @Override - public void enforce(final PasswordPolicySpec policy, final PolicyType type, final String password) - throws PasswordPolicyException, PolicyEnforceException { + public abstract void enforce(PasswordPolicySpec policy, PolicyType type, + String password) throws PasswordPolicyException, + PolicyEnforceException; - if (password == null) { - throw new PolicyEnforceException("Invalid password"); - } - - if (policy == null) { - throw new PolicyEnforceException("Invalid policy"); - } - - // check length - if (policy.getMinLength() > 0 && policy.getMinLength() > password.length()) { - throw new PasswordPolicyException("Password too short"); - } - - if (policy.getMaxLength() > 0 && policy.getMaxLength() < password.length()) { - throw new PasswordPolicyException("Password too long"); - } - - // check words not permitted - for (String word : policy.getWordsNotPermitted()) { - if (password.contains(word)) { - throw new PasswordPolicyException("Used word(s) not permitted"); - } - } - - // check digits occurrence - if (policy.isDigitRequired() && !checkForDigit(password)) { - throw new PasswordPolicyException("Password must contain digit(s)"); - } - - // check lowercase alphabetic characters occurrence - if (policy.isLowercaseRequired() && !checkForLowercase(password)) { - throw new PasswordPolicyException("Password must contain lowercase alphabetic character(s)"); - } - - // check uppercase alphabetic characters occurrence - if (policy.isUppercaseRequired() && !checkForUppercase(password)) { - throw new PasswordPolicyException("Password must contain uppercase alphabetic character(s)"); - } - - // check prefix - for (String prefix : policy.getPrefixesNotPermitted()) { - if (password.startsWith(prefix)) { - throw new PasswordPolicyException("Prefix not permitted"); - } - } - - // check suffix - for (String suffix : policy.getSuffixesNotPermitted()) { - if (password.endsWith(suffix)) { - throw new PasswordPolicyException("Suffix not permitted"); - } - } - - // check digit first occurrence - if (policy.isMustStartWithDigit() && !checkForFirstDigit(password)) { - throw new PasswordPolicyException("Password must start with a digit"); - } - - if (policy.isMustntStartWithDigit() && checkForFirstDigit(password)) { - throw new PasswordPolicyException("Password mustn't start with a digit"); - } - - // check digit last occurrence - if (policy.isMustEndWithDigit() && !checkForLastDigit(password)) { - throw new PasswordPolicyException("Password must end with a digit"); - } - - if (policy.isMustntEndWithDigit() && checkForLastDigit(password)) { - throw new PasswordPolicyException("Password mustn't end with a digit"); - } - - // check alphanumeric characters occurence - if (policy.isAlphanumericRequired() && !checkForAlphanumeric(password)) { - throw new PasswordPolicyException("Password must contain alphanumeric character(s)"); - } - - // check non alphanumeric characters occurence - if (policy.isNonAlphanumericRequired() && !checkForNonAlphanumeric(password)) { - throw new PasswordPolicyException("Password must contain non-alphanumeric character(s)"); - } - - // check alphanumeric character first occurrence - if (policy.isMustStartWithAlpha() && !checkForFirstAlphanumeric(password)) { - throw new PasswordPolicyException("Password must start with an alphanumeric character"); - } - - if (policy.isMustntStartWithAlpha() && checkForFirstAlphanumeric(password)) { - throw new PasswordPolicyException("Password mustn't start with an alphanumeric character"); - } - - // check alphanumeric character last occurrence - if (policy.isMustEndWithAlpha() && !checkForLastAlphanumeric(password)) { - throw new PasswordPolicyException("Password must end with an alphanumeric character"); - } - - if (policy.isMustntEndWithAlpha() && checkForLastAlphanumeric(password)) { - throw new PasswordPolicyException("Password mustn't end with an alphanumeric character"); - } - - // check non alphanumeric character first occurrence - if (policy.isMustStartWithNonAlpha() && !checkForFirstNonAlphanumeric(password)) { - throw new PasswordPolicyException("Password must start with a non-alphanumeric character"); - } - - if (policy.isMustntStartWithNonAlpha() && checkForFirstNonAlphanumeric(password)) { - throw new PasswordPolicyException("Password mustn't start with a non-alphanumeric character"); - } - - // check non alphanumeric character last occurrence - if (policy.isMustEndWithNonAlpha() && !checkForLastNonAlphanumeric(password)) { - throw new PasswordPolicyException("Password must end with a non-alphanumeric character"); - } - - if (policy.isMustntEndWithNonAlpha() && checkForLastNonAlphanumeric(password)) { - throw new PasswordPolicyException("Password mustn't end with a non-alphanumeric character"); - } - } - - private boolean checkForDigit(final String str) { - return PolicyPattern.DIGIT.matcher(str).matches(); - } - - private boolean checkForLowercase(final String str) { - return PolicyPattern.ALPHA_LOWERCASE.matcher(str).matches(); - } - - private boolean checkForUppercase(final String str) { - return PolicyPattern.ALPHA_UPPERCASE.matcher(str).matches(); - } - - private boolean checkForFirstDigit(final String str) { - return PolicyPattern.FIRST_DIGIT.matcher(str).matches(); - } - - private boolean checkForLastDigit(final String str) { - return PolicyPattern.LAST_DIGIT.matcher(str).matches(); - } - - private boolean checkForAlphanumeric(final String str) { - return PolicyPattern.ALPHANUMERIC.matcher(str).matches(); - } - - private boolean checkForFirstAlphanumeric(final String str) { - return PolicyPattern.FIRST_ALPHANUMERIC.matcher(str).matches(); - } - - private boolean checkForLastAlphanumeric(final String str) { - return PolicyPattern.LAST_ALPHANUMERIC.matcher(str).matches(); - } - - private boolean checkForNonAlphanumeric(final String str) { - return PolicyPattern.NON_ALPHANUMERIC.matcher(str).matches(); - } - - private boolean checkForFirstNonAlphanumeric(final String str) { - return PolicyPattern.FIRST_NON_ALPHANUMERIC.matcher(str).matches(); - } - - private boolean checkForLastNonAlphanumeric(final String str) { - return PolicyPattern.LAST_NON_ALPHANUMERIC.matcher(str).matches(); - } -} +} \ No newline at end of file Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/policy/PolicyEnforceException.java URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/policy/PolicyEnforceException.java?rev=1423908&r1=1423907&r2=1423908&view=diff ============================================================================== --- syncope/trunk/core/src/main/java/org/apache/syncope/core/policy/PolicyEnforceException.java (original) +++ syncope/trunk/core/src/main/java/org/apache/syncope/core/policy/PolicyEnforceException.java Wed Dec 19 15:58:27 2012 @@ -18,7 +18,7 @@ */ package org.apache.syncope.core.policy; -class PolicyEnforceException extends Exception { +public class PolicyEnforceException extends Exception { private static final long serialVersionUID = 3247084727383061069L; Copied: syncope/trunk/core/src/main/java/org/apache/syncope/core/policy/impl/AccountPolicyEnforcerImpl.java (from r1423830, syncope/trunk/core/src/main/java/org/apache/syncope/core/policy/AccountPolicyEnforcer.java) URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/policy/impl/AccountPolicyEnforcerImpl.java?p2=syncope/trunk/core/src/main/java/org/apache/syncope/core/policy/impl/AccountPolicyEnforcerImpl.java&p1=syncope/trunk/core/src/main/java/org/apache/syncope/core/policy/AccountPolicyEnforcer.java&r1=1423830&r2=1423908&rev=1423908&view=diff ============================================================================== --- syncope/trunk/core/src/main/java/org/apache/syncope/core/policy/AccountPolicyEnforcer.java (original) +++ syncope/trunk/core/src/main/java/org/apache/syncope/core/policy/impl/AccountPolicyEnforcerImpl.java Wed Dec 19 15:58:27 2012 @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.syncope.core.policy; +package org.apache.syncope.core.policy.impl; import java.util.List; import java.util.Map; @@ -25,6 +25,10 @@ import org.apache.commons.collections.ke import org.apache.syncope.client.to.UserTO; import org.apache.syncope.core.persistence.beans.PropagationTask; import org.apache.syncope.core.persistence.beans.user.SyncopeUser; +import org.apache.syncope.core.policy.AccountPolicyEnforcer; +import org.apache.syncope.core.policy.AccountPolicyException; +import org.apache.syncope.core.policy.PolicyEnforceException; +import org.apache.syncope.core.policy.PolicyEnforcer; import org.apache.syncope.core.propagation.PropagationManager; import org.apache.syncope.core.propagation.PropagationTaskExecutor; import org.apache.syncope.core.rest.data.UserDataBinder; @@ -36,7 +40,7 @@ import org.springframework.beans.factory import org.springframework.stereotype.Component; @Component -public class AccountPolicyEnforcer extends PolicyEnforcer<AccountPolicySpec, SyncopeUser> { +public class AccountPolicyEnforcerImpl extends PolicyEnforcer<AccountPolicySpec, SyncopeUser> implements AccountPolicyEnforcer { @Autowired private UserWorkflowAdapter uwfAdapter; @@ -56,6 +60,9 @@ public class AccountPolicyEnforcer exten private static final Pattern UCPATTERN = Pattern.compile("[A-Z0-9-_@. ]+"); + /* (non-Javadoc) + * @see org.apache.syncope.core.policy.AccountPolicyEnforcer#enforce(org.apache.syncope.types.AccountPolicySpec, org.apache.syncope.types.PolicyType, org.apache.syncope.core.persistence.beans.user.SyncopeUser) + */ @Override public void enforce(final AccountPolicySpec policy, final PolicyType type, final SyncopeUser user) throws AccountPolicyException, PolicyEnforceException { Copied: syncope/trunk/core/src/main/java/org/apache/syncope/core/policy/impl/PasswordPolicyEnforcerImpl.java (from r1423830, syncope/trunk/core/src/main/java/org/apache/syncope/core/policy/PasswordPolicyEnforcer.java) URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/policy/impl/PasswordPolicyEnforcerImpl.java?p2=syncope/trunk/core/src/main/java/org/apache/syncope/core/policy/impl/PasswordPolicyEnforcerImpl.java&p1=syncope/trunk/core/src/main/java/org/apache/syncope/core/policy/PasswordPolicyEnforcer.java&r1=1423830&r2=1423908&rev=1423908&view=diff ============================================================================== --- syncope/trunk/core/src/main/java/org/apache/syncope/core/policy/PasswordPolicyEnforcer.java (original) +++ syncope/trunk/core/src/main/java/org/apache/syncope/core/policy/impl/PasswordPolicyEnforcerImpl.java Wed Dec 19 15:58:27 2012 @@ -16,16 +16,24 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.syncope.core.policy; +package org.apache.syncope.core.policy.impl; +import org.apache.syncope.core.policy.PasswordPolicyEnforcer; +import org.apache.syncope.core.policy.PasswordPolicyException; +import org.apache.syncope.core.policy.PolicyEnforceException; +import org.apache.syncope.core.policy.PolicyEnforcer; +import org.apache.syncope.core.policy.PolicyPattern; import org.apache.syncope.types.PasswordPolicySpec; import org.apache.syncope.types.PolicyType; import org.springframework.stereotype.Component; @Component -public class PasswordPolicyEnforcer extends PolicyEnforcer<PasswordPolicySpec, String> { +public class PasswordPolicyEnforcerImpl extends PolicyEnforcer<PasswordPolicySpec, String> implements PasswordPolicyEnforcer { - @Override + /* (non-Javadoc) + * @see org.apache.syncope.core.policy.PasswordPolicyEnforcer#enforce(org.apache.syncope.types.PasswordPolicySpec, org.apache.syncope.types.PolicyType, java.lang.String) + */ + @Override public void enforce(final PasswordPolicySpec policy, final PolicyType type, final String password) throws PasswordPolicyException, PolicyEnforceException { Modified: syncope/trunk/core/src/main/resources/persistenceContext.xml URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/resources/persistenceContext.xml?rev=1423908&r1=1423907&r2=1423908&view=diff ============================================================================== --- syncope/trunk/core/src/main/resources/persistenceContext.xml (original) +++ syncope/trunk/core/src/main/resources/persistenceContext.xml Wed Dec 19 15:58:27 2012 @@ -38,6 +38,7 @@ under the License. <context:component-scan base-package="org.apache.syncope.core.persistence"/> <context:component-scan base-package="org.apache.syncope.core.rest.data"/> <context:component-scan base-package="org.apache.syncope.core.policy"/> + <context:component-scan base-package="org.apache.syncope.core.policy.impl"/> <aop:aspectj-autoproxy/>