[SYNCOPE-894] Enhancement provided
Project: http://git-wip-us.apache.org/repos/asf/syncope/repo Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/0656bc07 Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/0656bc07 Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/0656bc07 Branch: refs/heads/2_0_NO_JAXB Commit: 0656bc07fc99d8fa9d87bf407f7641c4fa221ad8 Parents: a9bd3ce Author: Francesco Chicchiriccò <[email protected]> Authored: Wed Jul 6 18:05:23 2016 +0200 Committer: Francesco Chicchiriccò <[email protected]> Committed: Wed Jul 6 18:05:23 2016 +0200 ---------------------------------------------------------------------- .../org/apache/syncope/common/lib/SyncopeConstants.java | 2 +- .../syncope/core/persistence/jpa/dao/JPAUserDAO.java | 9 +++++++++ .../persistence/jpa/entity/AbstractAnnotatedEntity.java | 5 ----- .../syncope/core/persistence/jpa/outer/GroupTest.java | 11 +++++++++++ .../java/org/apache/syncope/fit/core/GroupITCase.java | 8 ++++++++ 5 files changed, 29 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/syncope/blob/0656bc07/common/lib/src/main/java/org/apache/syncope/common/lib/SyncopeConstants.java ---------------------------------------------------------------------- diff --git a/common/lib/src/main/java/org/apache/syncope/common/lib/SyncopeConstants.java b/common/lib/src/main/java/org/apache/syncope/common/lib/SyncopeConstants.java index 1f2febd..81f93a0 100644 --- a/common/lib/src/main/java/org/apache/syncope/common/lib/SyncopeConstants.java +++ b/common/lib/src/main/java/org/apache/syncope/common/lib/SyncopeConstants.java @@ -37,7 +37,7 @@ public final class SyncopeConstants { public static final String ENUM_VALUES_SEPARATOR = ";"; - public static final String NAME_PATTERN = "[\\w \\-@.]+"; + public static final String NAME_PATTERN = "[\\p{L}\\p{gc=Mn}\\p{gc=Me}\\p{gc=Mc}\\p{Digit}\\p{gc=Pc} \\-@.]+"; public static final String[] DATE_PATTERNS = { "yyyy-MM-dd'T'HH:mm:ssZ", http://git-wip-us.apache.org/repos/asf/syncope/blob/0656bc07/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAUserDAO.java ---------------------------------------------------------------------- diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAUserDAO.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAUserDAO.java index a33e29e..d4f93ed 100644 --- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAUserDAO.java +++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAUserDAO.java @@ -26,6 +26,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.regex.Pattern; import javax.annotation.Resource; import javax.persistence.NoResultException; import javax.persistence.Query; @@ -36,6 +37,7 @@ import org.apache.commons.collections4.Predicate; import org.apache.commons.collections4.Transformer; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; +import org.apache.syncope.common.lib.SyncopeConstants; import org.apache.syncope.common.lib.policy.AccountRuleConf; import org.apache.syncope.common.lib.policy.PasswordRuleConf; import org.apache.syncope.common.lib.types.AnyTypeKind; @@ -81,6 +83,9 @@ import org.springframework.transaction.annotation.Transactional; @Repository public class JPAUserDAO extends AbstractAnyDAO<User> implements UserDAO { + private static final Pattern USERNAME_PATTERN = + Pattern.compile("^" + SyncopeConstants.NAME_PATTERN, Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE); + @Autowired private RealmDAO realmDAO; @@ -343,6 +348,10 @@ public class JPAUserDAO extends AbstractAnyDAO<User> implements UserDAO { throw new AccountPolicyException("Not allowed: " + user.getUsername()); } + if (!USERNAME_PATTERN.matcher(user.getUsername()).matches()) { + throw new AccountPolicyException("Character(s) not allowed"); + } + for (AccountPolicy policy : getAccountPolicies(user)) { for (AccountRuleConf ruleConf : policy.getRuleConfs()) { Class<? extends AccountRule> ruleClass = http://git-wip-us.apache.org/repos/asf/syncope/blob/0656bc07/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/AbstractAnnotatedEntity.java ---------------------------------------------------------------------- diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/AbstractAnnotatedEntity.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/AbstractAnnotatedEntity.java index e9e71fa..bf7ec39 100644 --- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/AbstractAnnotatedEntity.java +++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/AbstractAnnotatedEntity.java @@ -19,7 +19,6 @@ package org.apache.syncope.core.persistence.jpa.entity; import java.util.Date; -import javax.persistence.Column; import javax.persistence.EntityListeners; import javax.persistence.MappedSuperclass; import javax.persistence.Temporal; @@ -39,13 +38,11 @@ public abstract class AbstractAnnotatedEntity extends AbstractGeneratedKeyEntity * Username of the user that has created this profile. * Reference to existing user cannot be used: the creator can either be <tt>admin</tt> or was deleted. */ - @Column(nullable = false) private String creator; /** * Creation date. */ - @Column(nullable = false) @Temporal(TemporalType.TIMESTAMP) private Date creationDate; @@ -55,14 +52,12 @@ public abstract class AbstractAnnotatedEntity extends AbstractGeneratedKeyEntity * The modifier can be the user itself if the last performed change was a self-modification. * Reference to existing user cannot be used: the creator can either be <tt>admin</tt> or was deleted. */ - @Column(nullable = false) private String lastModifier; /** * Last change date. * This field cannot be null: at creation time it needs to be initialized with <tt>creationDate</tt> field value. */ - @Column(nullable = false) @Temporal(TemporalType.TIMESTAMP) private Date lastChangeDate; http://git-wip-us.apache.org/repos/asf/syncope/blob/0656bc07/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/outer/GroupTest.java ---------------------------------------------------------------------- diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/outer/GroupTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/outer/GroupTest.java index 8037a2b..39eb25e 100644 --- a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/outer/GroupTest.java +++ b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/outer/GroupTest.java @@ -30,6 +30,7 @@ import java.util.HashSet; import java.util.List; import javax.persistence.TypedQuery; import org.apache.commons.collections4.CollectionUtils; +import org.apache.syncope.common.lib.SyncopeConstants; import org.apache.syncope.common.lib.types.AnyTypeKind; import org.apache.syncope.core.provisioning.api.utils.EntityUtils; import org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException; @@ -147,6 +148,16 @@ public class GroupTest extends AbstractTest { } @Test + public void createWithInternationalCharacters() { + Group group = entityFactory.newEntity(Group.class); + group.setName("räksmörgås"); + group.setRealm(realmDAO.findByFullPath(SyncopeConstants.ROOT_REALM)); + + groupDAO.save(group); + groupDAO.flush(); + } + + @Test public void delete() { groupDAO.delete("b1f7c12d-ec83-441f-a50e-1691daaedf3b"); http://git-wip-us.apache.org/repos/asf/syncope/blob/0656bc07/fit/core-reference/src/test/java/org/apache/syncope/fit/core/GroupITCase.java ---------------------------------------------------------------------- diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/GroupITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/GroupITCase.java index 00959a0..939e1f8 100644 --- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/GroupITCase.java +++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/GroupITCase.java @@ -141,6 +141,14 @@ public class GroupITCase extends AbstractITCase { } @Test + public void createWithInternationalCharacters() { + GroupTO groupTO = getSampleTO("räksmörgås"); + + groupTO = createGroup(groupTO).getEntity(); + assertNotNull(groupTO); + } + + @Test public void delete() { try { groupService.delete(UUID.randomUUID().toString());
