Replace equals with == when comparing SearchableFields in Jpa*ModelCriteriaBuilder and Ldap*ModelCriteriaBuilder

Closes #11843
This commit is contained in:
vramik 2022-05-11 17:36:58 +02:00 committed by Hynek Mlnařík
parent b86f205cda
commit e1eb9d6d64
8 changed files with 47 additions and 45 deletions

View file

@ -41,7 +41,7 @@ public class JpaRootAuthenticationSessionModelCriteriaBuilder extends JpaModelCr
public JpaRootAuthenticationSessionModelCriteriaBuilder compare(SearchableModelField<? super RootAuthenticationSessionModel> modelField, Operator op, Object... value) {
switch (op) {
case EQ:
if (modelField.equals(SearchableFields.REALM_ID)) {
if (modelField == SearchableFields.REALM_ID) {
validateValue(value, modelField, op, String.class);
@ -53,7 +53,7 @@ public class JpaRootAuthenticationSessionModelCriteriaBuilder extends JpaModelCr
}
case LT:
if (modelField.equals(SearchableFields.EXPIRATION)) {
if (modelField == SearchableFields.EXPIRATION) {
validateValue(value, modelField, op, Number.class);
Number expiration = (Number) value[0];

View file

@ -44,21 +44,21 @@ public class JpaClientModelCriteriaBuilder extends JpaModelCriteriaBuilder<JpaCl
public JpaClientModelCriteriaBuilder compare(SearchableModelField<? super ClientModel> modelField, Operator op, Object... value) {
switch (op) {
case EQ:
if (modelField.equals(SearchableFields.REALM_ID) ||
modelField.equals(SearchableFields.CLIENT_ID)) {
if (modelField == SearchableFields.REALM_ID ||
modelField == SearchableFields.CLIENT_ID) {
validateValue(value, modelField, op, String.class);
return new JpaClientModelCriteriaBuilder((cb, root) ->
cb.equal(root.get(modelField.getName()), value[0])
);
} else if (modelField.equals(SearchableFields.ENABLED)) {
} else if (modelField == SearchableFields.ENABLED) {
validateValue(value, modelField, op, Boolean.class);
return new JpaClientModelCriteriaBuilder((cb, root) ->
cb.equal(root.get(modelField.getName()), value[0])
);
} else if (modelField.equals(SearchableFields.SCOPE_MAPPING_ROLE)) {
} else if (modelField == SearchableFields.SCOPE_MAPPING_ROLE) {
validateValue(value, modelField, op, String.class);
return new JpaClientModelCriteriaBuilder((cb, root) ->
@ -67,7 +67,7 @@ public class JpaClientModelCriteriaBuilder extends JpaModelCriteriaBuilder<JpaCl
cb.function("->", JsonbType.class, root.get("metadata"), cb.literal("fScopeMappings")),
cb.literal(convertToJson(value[0]))))
);
} else if (modelField.equals(SearchableFields.ALWAYS_DISPLAY_IN_CONSOLE)) {
} else if (modelField == SearchableFields.ALWAYS_DISPLAY_IN_CONSOLE) {
validateValue(value, modelField, op, Boolean.class);
return new JpaClientModelCriteriaBuilder((cb, root) ->
@ -75,7 +75,7 @@ public class JpaClientModelCriteriaBuilder extends JpaModelCriteriaBuilder<JpaCl
cb.function("->", JsonbType.class, root.get("metadata"), cb.literal("fAlwaysDisplayInConsole")),
cb.literal(convertToJson(value[0])))
);
} else if (modelField.equals(SearchableFields.ATTRIBUTE)) {
} else if (modelField == SearchableFields.ATTRIBUTE) {
validateValue(value, modelField, op, String.class, String.class);
return new JpaClientModelCriteriaBuilder((cb, root) -> {
@ -90,7 +90,7 @@ public class JpaClientModelCriteriaBuilder extends JpaModelCriteriaBuilder<JpaCl
}
case ILIKE:
if (modelField.equals(SearchableFields.CLIENT_ID)) {
if (modelField == SearchableFields.CLIENT_ID) {
validateValue(value, modelField, op, String.class);
return new JpaClientModelCriteriaBuilder((cb, root) ->

View file

@ -41,8 +41,8 @@ public class JpaClientScopeModelCriteriaBuilder extends JpaModelCriteriaBuilder<
public JpaClientScopeModelCriteriaBuilder compare(SearchableModelField<? super ClientScopeModel> modelField, Operator op, Object... value) {
switch (op) {
case EQ:
if (modelField.equals(SearchableFields.REALM_ID) ||
modelField.equals(SearchableFields.NAME)) {
if (modelField == SearchableFields.REALM_ID ||
modelField == SearchableFields.NAME) {
validateValue(value, modelField, op, String.class);

View file

@ -52,14 +52,14 @@ public class JpaGroupModelCriteriaBuilder extends JpaModelCriteriaBuilder<JpaGro
public JpaGroupModelCriteriaBuilder compare(SearchableModelField<? super GroupModel> modelField, Operator op, Object... value) {
switch (op) {
case EQ:
if (modelField.equals(GroupModel.SearchableFields.REALM_ID) ||
modelField.equals(GroupModel.SearchableFields.NAME)) {
if (modelField == GroupModel.SearchableFields.REALM_ID ||
modelField == GroupModel.SearchableFields.NAME) {
validateValue(value, modelField, op, String.class);
return new JpaGroupModelCriteriaBuilder((cb, root) ->
cb.equal(root.get(modelField.getName()), value[0])
);
} else if (modelField.equals(GroupModel.SearchableFields.PARENT_ID)) {
} else if (modelField == GroupModel.SearchableFields.PARENT_ID) {
if (value.length == 1 && Objects.isNull(value[0])) {
return new JpaGroupModelCriteriaBuilder((cb, root) ->
cb.isNull(root.get("parentId"))
@ -71,7 +71,7 @@ public class JpaGroupModelCriteriaBuilder extends JpaModelCriteriaBuilder<JpaGro
return new JpaGroupModelCriteriaBuilder((cb, root) ->
cb.equal(root.get("parentId"), value[0])
);
} else if (modelField.equals(GroupModel.SearchableFields.ASSIGNED_ROLE)) {
} else if (modelField == GroupModel.SearchableFields.ASSIGNED_ROLE) {
validateValue(value, modelField, op, String.class);
return new JpaGroupModelCriteriaBuilder((cb, root) ->
@ -84,7 +84,7 @@ public class JpaGroupModelCriteriaBuilder extends JpaModelCriteriaBuilder<JpaGro
throw new CriterionNotSupportedException(modelField, op);
}
case IN:
if (modelField.equals(GroupModel.SearchableFields.ID)) {
if (modelField == GroupModel.SearchableFields.ID) {
if (value == null || value.length == 0) throw new CriterionNotSupportedException(modelField, op);
final Collection<?> collectionValues;
@ -125,7 +125,7 @@ public class JpaGroupModelCriteriaBuilder extends JpaModelCriteriaBuilder<JpaGro
throw new CriterionNotSupportedException(modelField, op);
}
case ILIKE:
if (modelField.equals(GroupModel.SearchableFields.NAME)) {
if (modelField == GroupModel.SearchableFields.NAME) {
validateValue(value, modelField, op, String.class);
@ -136,7 +136,7 @@ public class JpaGroupModelCriteriaBuilder extends JpaModelCriteriaBuilder<JpaGro
throw new CriterionNotSupportedException(modelField, op);
}
case NOT_EXISTS:
if (modelField.equals(GroupModel.SearchableFields.PARENT_ID)) {
if (modelField == GroupModel.SearchableFields.PARENT_ID) {
return new JpaGroupModelCriteriaBuilder((cb, root) ->
cb.isNull(root.get("parentId"))

View file

@ -47,8 +47,8 @@ public class JpaUserLoginFailureModelCriteriaBuilder extends JpaModelCriteriaBui
public JpaUserLoginFailureModelCriteriaBuilder compare(SearchableModelField<? super UserLoginFailureModel> modelField, Operator op, Object... value) {
switch (op) {
case EQ:
if (modelField.equals(UserLoginFailureModel.SearchableFields.REALM_ID) ||
modelField.equals(UserLoginFailureModel.SearchableFields.USER_ID)) {
if (modelField == UserLoginFailureModel.SearchableFields.REALM_ID ||
modelField == UserLoginFailureModel.SearchableFields.USER_ID) {
validateValue(value, modelField, op, String.class);

View file

@ -54,12 +54,12 @@ public class JpaRealmModelCriteriaBuilder extends JpaModelCriteriaBuilder<JpaRea
public JpaRealmModelCriteriaBuilder compare(SearchableModelField<? super RealmModel> modelField, Operator op, Object... value) {
switch(op) {
case EQ:
if (modelField.equals(RealmModel.SearchableFields.NAME)) {
if (modelField == RealmModel.SearchableFields.NAME) {
validateValue(value, modelField, op, String.class);
return new JpaRealmModelCriteriaBuilder((cb, root) ->
cb.equal(root.get(modelField.getName()), value[0])
);
} else if (modelField.equals(RealmModel.SearchableFields.COMPONENT_PROVIDER_TYPE)) {
} else if (modelField == RealmModel.SearchableFields.COMPONENT_PROVIDER_TYPE) {
validateValue(value, modelField, op, String.class);
return new JpaRealmModelCriteriaBuilder((cb, root) ->
cb.equal(root.join("components").get("providerType"), value[0]), true);
@ -67,7 +67,7 @@ public class JpaRealmModelCriteriaBuilder extends JpaModelCriteriaBuilder<JpaRea
throw new CriterionNotSupportedException(modelField, op);
}
case EXISTS:
if (modelField.equals(RealmModel.SearchableFields.CLIENT_INITIAL_ACCESS)) {
if (modelField == RealmModel.SearchableFields.CLIENT_INITIAL_ACCESS) {
return new JpaRealmModelCriteriaBuilder((cb, root) ->
cb.isTrue(cb.function("->", JsonbType.class, root.get("metadata"),
cb.literal("fClientInitialAccesses")).isNotNull())

View file

@ -54,15 +54,17 @@ public class JpaRoleModelCriteriaBuilder extends JpaModelCriteriaBuilder<JpaRole
public JpaRoleModelCriteriaBuilder compare(SearchableModelField<? super RoleModel> modelField, Operator op, Object... value) {
switch (op) {
case EQ:
if (modelField.equals(SearchableFields.REALM_ID) ||
modelField.equals(SearchableFields.CLIENT_ID) ||
modelField.equals(SearchableFields.NAME)) {
if (modelField == SearchableFields.REALM_ID ||
modelField == SearchableFields.CLIENT_ID ||
modelField == SearchableFields.NAME) {
validateValue(value, modelField, op, String.class);
return new JpaRoleModelCriteriaBuilder((cb, root) ->
cb.equal(root.get(modelField.getName()), value[0])
);
} else if (modelField == SearchableFields.COMPOSITE_ROLE){
} else if (modelField == SearchableFields.COMPOSITE_ROLE) {
validateValue(value, modelField, op, String.class);
return new JpaRoleModelCriteriaBuilder((cb, root) ->
@ -75,7 +77,7 @@ public class JpaRoleModelCriteriaBuilder extends JpaModelCriteriaBuilder<JpaRole
throw new CriterionNotSupportedException(modelField, op);
}
case NE:
if (modelField.equals(SearchableFields.IS_CLIENT_ROLE)) {
if (modelField == SearchableFields.IS_CLIENT_ROLE) {
validateValue(value, modelField, op, Boolean.class);
@ -86,7 +88,7 @@ public class JpaRoleModelCriteriaBuilder extends JpaModelCriteriaBuilder<JpaRole
throw new CriterionNotSupportedException(modelField, op);
}
case IN:
if (modelField.equals(SearchableFields.ID)) {
if (modelField == SearchableFields.ID) {
if (value == null || value.length == 0) throw new CriterionNotSupportedException(modelField, op);
final Collection<?> collectionValues;
@ -127,8 +129,8 @@ public class JpaRoleModelCriteriaBuilder extends JpaModelCriteriaBuilder<JpaRole
throw new CriterionNotSupportedException(modelField, op);
}
case ILIKE:
if (modelField.equals(SearchableFields.NAME) ||
modelField.equals(SearchableFields.DESCRIPTION)) {
if (modelField == SearchableFields.NAME ||
modelField == SearchableFields.DESCRIPTION) {
validateValue(value, modelField, op, String.class);

View file

@ -123,19 +123,19 @@ public class LdapRoleModelCriteriaBuilder extends LdapModelCriteriaBuilder<LdapR
public LdapRoleModelCriteriaBuilder compare(SearchableModelField<? super RoleModel> modelField, Operator op, Object... value) {
switch (op) {
case EQ:
if (modelField.equals(RoleModel.SearchableFields.IS_CLIENT_ROLE)) {
if (modelField == RoleModel.SearchableFields.IS_CLIENT_ROLE) {
LdapRoleModelCriteriaBuilder result = new LdapRoleModelCriteriaBuilder(roleMapperConfig, StringBuilder::new);
result.isClientRole = (boolean) value[0];
return result;
} else if (modelField.equals(RoleModel.SearchableFields.CLIENT_ID)) {
} else if (modelField == RoleModel.SearchableFields.CLIENT_ID) {
LdapRoleModelCriteriaBuilder result = new LdapRoleModelCriteriaBuilder(roleMapperConfig, StringBuilder::new);
result.clientId = (String) value[0];
return result;
} else if (modelField.equals(RoleModel.SearchableFields.REALM_ID)) {
} else if (modelField == RoleModel.SearchableFields.REALM_ID) {
LdapRoleModelCriteriaBuilder result = new LdapRoleModelCriteriaBuilder(roleMapperConfig, StringBuilder::new);
result.realmId = (String) value[0];
return result;
} else if (modelField.equals(RoleModel.SearchableFields.NAME)) {
} else if (modelField == RoleModel.SearchableFields.NAME) {
// validateValue(value, modelField, op, String.class);
String field = modelFieldNameToLdap(roleMapperConfig, modelField);
return new LdapRoleModelCriteriaBuilder(roleMapperConfig,
@ -148,11 +148,11 @@ public class LdapRoleModelCriteriaBuilder extends LdapModelCriteriaBuilder<LdapR
}
case NE:
if (modelField.equals(RoleModel.SearchableFields.IS_CLIENT_ROLE)) {
if (modelField == RoleModel.SearchableFields.IS_CLIENT_ROLE) {
LdapRoleModelCriteriaBuilder result = new LdapRoleModelCriteriaBuilder(roleMapperConfig, StringBuilder::new);
result.isClientRole = !((boolean) value[0]);
return result;
} else if (modelField.equals(RoleModel.SearchableFields.NAME)) {
} else if (modelField == RoleModel.SearchableFields.NAME) {
// validateValue(value, modelField, op, String.class);
String field = modelFieldNameToLdap(roleMapperConfig, modelField);
return not(new LdapRoleModelCriteriaBuilder(roleMapperConfig,
@ -163,8 +163,8 @@ public class LdapRoleModelCriteriaBuilder extends LdapModelCriteriaBuilder<LdapR
case ILIKE:
case LIKE:
if (modelField.equals(RoleModel.SearchableFields.NAME) ||
modelField.equals(RoleModel.SearchableFields.DESCRIPTION)) {
if (modelField == RoleModel.SearchableFields.NAME ||
modelField == RoleModel.SearchableFields.DESCRIPTION) {
// validateValue(value, modelField, op, String.class);
// first escape all elements of the string (which would not escape the percent sign)
// then replace percent sign with the wildcard character asterisk
@ -185,9 +185,9 @@ public class LdapRoleModelCriteriaBuilder extends LdapModelCriteriaBuilder<LdapR
}
case IN:
if (modelField.equals(RoleModel.SearchableFields.NAME) ||
modelField.equals(RoleModel.SearchableFields.DESCRIPTION) ||
modelField.equals(RoleModel.SearchableFields.ID)) {
if (modelField == RoleModel.SearchableFields.NAME ||
modelField == RoleModel.SearchableFields.DESCRIPTION ||
modelField == RoleModel.SearchableFields.ID) {
String field = modelFieldNameToLdap(roleMapperConfig, modelField);
return new LdapRoleModelCriteriaBuilder(roleMapperConfig, () -> {
Object[] v;
@ -208,11 +208,11 @@ public class LdapRoleModelCriteriaBuilder extends LdapModelCriteriaBuilder<LdapR
}
private String modelFieldNameToLdap(LdapMapRoleMapperConfig roleMapperConfig, SearchableModelField<? super RoleModel> modelField) {
if (modelField.equals(RoleModel.SearchableFields.NAME)) {
if (modelField == RoleModel.SearchableFields.NAME) {
return roleMapperConfig.getRoleNameLdapAttribute();
} else if (modelField.equals(RoleModel.SearchableFields.ID)) {
} else if (modelField == RoleModel.SearchableFields.ID) {
return roleMapperConfig.getLdapMapConfig().getUuidLDAPAttributeName();
} else if (modelField.equals(RoleModel.SearchableFields.DESCRIPTION)) {
} else if (modelField == RoleModel.SearchableFields.DESCRIPTION) {
return "description";
} else {
throw new CriterionNotSupportedException(modelField, null);