ScimUtils { public static void validate(final ScimUser user) throws InvalidScimResourceException { Pattern usernamePattern = Pattern.compile("[\\p{L}+0-9+\\-_.@'!]+"); if (!hasText(user.getUserName())) { throw new InvalidScimResourceException("A username must be provided."); } if (OriginKeys.UAA.equals(user.getOrigin()) && !usernamePattern.matcher(user.getUserName()).matches()) { throw new InvalidScimResourceException("Username must match pattern: " + usernamePattern.pattern()); } if (user.getEmails() == null || user.getEmails().size() != 1) { throw new InvalidScimResourceException("Exactly one email must be provided."); } for (ScimUser.Email email : user.getEmails()) { if (email == null || email.getValue() == null || email.getValue().isEmpty()) { throw new InvalidScimResourceException("An email must be provided."); } } } private  ScimUtils(); static ExpiringCode getExpiringCode(
            ExpiringCodeStore codeStore,
            String userId,
            String email,
            String clientId,
            String redirectUri,
            ExpiringCodeType intent,
            String currentZoneId); static URL getVerificationURL(
            ExpiringCode expiringCode,
            IdentityZone currentIdentityZone); static void validate(final ScimUser user);  }
@Test void userWithEmptyandNonEmptyEmails() { ScimUser user = new ScimUser(null, "josephine", "Jo", "Jung"); List<ScimUser.Email> emails = new ArrayList<>(); ScimUser.Email email1 = new ScimUser.Email(); email1.setValue("sample@sample.com"); emails.add(email1); ScimUser.Email email2 = new ScimUser.Email(); email2.setValue(""); emails.add(email2); user.setEmails(emails); assertThrows(InvalidScimResourceException.class, () -> ScimUtils.validate(user)); }
@Test void userWithEmptyEmail() { ScimUser user = new ScimUser(null, "josephine", "Jo", "Jung"); List<ScimUser.Email> emails = new ArrayList<>(); ScimUser.Email email = new ScimUser.Email(); email.setValue(""); emails.add(email); user.setEmails(emails); assertThrows(InvalidScimResourceException.class, () -> ScimUtils.validate(user)); }
@Test void userWithNonAsciiUsername() { ScimUser user = new ScimUser(null, "joe$eph", "Jo", "User"); user.setOrigin(OriginKeys.UAA); user.addEmail("jo@blah.com"); assertThrows(InvalidScimResourceException.class, () -> ScimUtils.validate(user)); }