|
|
@@ -1363,19 +1363,17 @@ public class Users {
|
|
|
addAuthentication(userEntity,
|
|
|
UserAuthenticationType.JWT,
|
|
|
key,
|
|
|
- new Validator() {
|
|
|
- public void validate(UserEntity userEntity, String key) throws AmbariException {
|
|
|
- List<UserAuthenticationEntity> authenticationEntities = userEntity.getAuthenticationEntities();
|
|
|
-
|
|
|
- // Ensure only one UserAuthenticationEntity exists for JWT for the user...
|
|
|
- for (UserAuthenticationEntity entity : authenticationEntities) {
|
|
|
- if ((entity.getAuthenticationType() == UserAuthenticationType.JWT) &&
|
|
|
- ((key == null) ? (entity.getAuthenticationKey() == null) : key.equals(entity.getAuthenticationKey()))) {
|
|
|
- throw new AmbariException("The authentication type already exists for this user");
|
|
|
+ (user, authKey) -> {
|
|
|
+ List<UserAuthenticationEntity> authenticationEntities = user.getAuthenticationEntities();
|
|
|
+
|
|
|
+ // Ensure only one UserAuthenticationEntity exists for JWT for the user...
|
|
|
+ for (UserAuthenticationEntity entity : authenticationEntities) {
|
|
|
+ if ((entity.getAuthenticationType() == UserAuthenticationType.JWT) &&
|
|
|
+ ((authKey == null) ? (entity.getAuthenticationKey() == null) : authKey.equals(entity.getAuthenticationKey()))) {
|
|
|
+ throw new AmbariException("The authentication type already exists for this user");
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
+ },
|
|
|
persist);
|
|
|
}
|
|
|
|
|
|
@@ -1405,14 +1403,12 @@ public class Users {
|
|
|
addAuthentication(userEntity,
|
|
|
UserAuthenticationType.KERBEROS,
|
|
|
principalName,
|
|
|
- new Validator() {
|
|
|
- public void validate(UserEntity userEntity, String key) throws AmbariException {
|
|
|
- // Ensure no other authentication entries exist for the same principal...
|
|
|
- if (!CollectionUtils.isEmpty(userAuthenticationDAO.findByTypeAndKey(UserAuthenticationType.KERBEROS, key))) {
|
|
|
- throw new AmbariException("The authentication type already exists for this principal");
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
+ (user, key) -> {
|
|
|
+ // Ensure no other authentication entries exist for the same principal...
|
|
|
+ if (!CollectionUtils.isEmpty(userAuthenticationDAO.findByTypeAndKey(UserAuthenticationType.KERBEROS, key))) {
|
|
|
+ throw new AmbariException("The authentication type already exists for this principal");
|
|
|
+ }
|
|
|
+ },
|
|
|
persist);
|
|
|
}
|
|
|
|
|
|
@@ -1453,18 +1449,16 @@ public class Users {
|
|
|
addAuthentication(userEntity,
|
|
|
UserAuthenticationType.LOCAL,
|
|
|
encodedPassword,
|
|
|
- new Validator() {
|
|
|
- public void validate(UserEntity userEntity, String key) throws AmbariException {
|
|
|
- List<UserAuthenticationEntity> authenticationEntities = userEntity.getAuthenticationEntities();
|
|
|
-
|
|
|
- // Ensure only one UserAuthenticationEntity exists for LOCAL for the user...
|
|
|
- for (UserAuthenticationEntity entity : authenticationEntities) {
|
|
|
- if (entity.getAuthenticationType() == UserAuthenticationType.LOCAL) {
|
|
|
- throw new AmbariException("The authentication type already exists for this user");
|
|
|
+ (user, key) -> {
|
|
|
+ List<UserAuthenticationEntity> authenticationEntities = user.getAuthenticationEntities();
|
|
|
+
|
|
|
+ // Ensure only one UserAuthenticationEntity exists for LOCAL for the user...
|
|
|
+ for (UserAuthenticationEntity entity : authenticationEntities) {
|
|
|
+ if (entity.getAuthenticationType() == UserAuthenticationType.LOCAL) {
|
|
|
+ throw new AmbariException("The authentication type already exists for this user");
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
+ },
|
|
|
persist);
|
|
|
}
|
|
|
|
|
|
@@ -1494,18 +1488,16 @@ public class Users {
|
|
|
addAuthentication(userEntity,
|
|
|
UserAuthenticationType.PAM,
|
|
|
userName,
|
|
|
- new Validator() {
|
|
|
- public void validate(UserEntity userEntity, String key) throws AmbariException {
|
|
|
- List<UserAuthenticationEntity> authenticationEntities = userEntity.getAuthenticationEntities();
|
|
|
-
|
|
|
- // Ensure only one UserAuthenticationEntity exists for PAM for the user...
|
|
|
- for (UserAuthenticationEntity entity : authenticationEntities) {
|
|
|
- if (entity.getAuthenticationType() == UserAuthenticationType.PAM) {
|
|
|
- throw new AmbariException("The authentication type already exists for this user");
|
|
|
+ (user, key) -> {
|
|
|
+ List<UserAuthenticationEntity> authenticationEntities = user.getAuthenticationEntities();
|
|
|
+
|
|
|
+ // Ensure only one UserAuthenticationEntity exists for PAM for the user...
|
|
|
+ for (UserAuthenticationEntity entity : authenticationEntities) {
|
|
|
+ if (entity.getAuthenticationType() == UserAuthenticationType.PAM) {
|
|
|
+ throw new AmbariException("The authentication type already exists for this user");
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
+ },
|
|
|
persist);
|
|
|
}
|
|
|
|
|
|
@@ -1535,19 +1527,17 @@ public class Users {
|
|
|
addAuthentication(userEntity,
|
|
|
UserAuthenticationType.LDAP,
|
|
|
StringUtils.lowerCase(dn), // DNs are case-insensitive and are stored internally as the bytes of lowercase characters
|
|
|
- new Validator() {
|
|
|
- public void validate(UserEntity userEntity, String key) throws AmbariException {
|
|
|
- List<UserAuthenticationEntity> authenticationEntities = userEntity.getAuthenticationEntities();
|
|
|
-
|
|
|
- // Ensure only one UserAuthenticationEntity exists for LDAP for the user...
|
|
|
- for (UserAuthenticationEntity entity : authenticationEntities) {
|
|
|
- if ((entity.getAuthenticationType() == UserAuthenticationType.LDAP) &&
|
|
|
- ((key == null) ? (entity.getAuthenticationKey() == null) : key.equalsIgnoreCase(entity.getAuthenticationKey()))) {
|
|
|
- throw new AmbariException("The authentication type already exists for this user");
|
|
|
+ (user, key) -> {
|
|
|
+ List<UserAuthenticationEntity> authenticationEntities = user.getAuthenticationEntities();
|
|
|
+
|
|
|
+ // Ensure only one UserAuthenticationEntity exists for LDAP for the user...
|
|
|
+ for (UserAuthenticationEntity entity : authenticationEntities) {
|
|
|
+ if ((entity.getAuthenticationType() == UserAuthenticationType.LDAP) &&
|
|
|
+ ((key == null) ? (entity.getAuthenticationKey() == null) : key.equalsIgnoreCase(entity.getAuthenticationKey()))) {
|
|
|
+ throw new AmbariException("The authentication type already exists for this user");
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
+ },
|
|
|
persist);
|
|
|
}
|
|
|
|