diff --git a/server/common/common/src/main/java/io/holoinsight/server/common/springboot/ConditionalOnRole.java b/server/common/common/src/main/java/io/holoinsight/server/common/springboot/ConditionalOnRole.java index a82a05828..c58a916d0 100644 --- a/server/common/common/src/main/java/io/holoinsight/server/common/springboot/ConditionalOnRole.java +++ b/server/common/common/src/main/java/io/holoinsight/server/common/springboot/ConditionalOnRole.java @@ -30,4 +30,6 @@ * @return */ String[] value(); + + boolean any() default true; } diff --git a/server/common/common/src/main/java/io/holoinsight/server/common/springboot/ConditionalOnRoleCondition.java b/server/common/common/src/main/java/io/holoinsight/server/common/springboot/ConditionalOnRoleCondition.java index fa593c2e2..4b856b785 100644 --- a/server/common/common/src/main/java/io/holoinsight/server/common/springboot/ConditionalOnRoleCondition.java +++ b/server/common/common/src/main/java/io/holoinsight/server/common/springboot/ConditionalOnRoleCondition.java @@ -28,17 +28,25 @@ public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { Map attributes = metadata.getAnnotationAttributes(ConditionalOnRole.class.getName(), true); - String[] anyRole = (String[]) attributes.get("value"); - + String[] expectedRoles = (String[]) attributes.get("value"); + boolean any = (Boolean) attributes.get("any"); String roles = context.getEnvironment().getProperty("holoinsight.roles.active", ""); Iterable iter = Splitter.on(',').trimResults().omitEmptyStrings().split(roles); - for (String role : anyRole) { - if (Iterables.contains(iter, role)) { - return ConditionOutcome.match("match '" + role + "' role"); + if (any) { + for (String role : expectedRoles) { + if (Iterables.contains(iter, role)) { + return ConditionOutcome.match("match '" + role + "' role"); + } + } + } else { + for (String role : expectedRoles) { + if (!Iterables.contains(iter, role)) { + return ConditionOutcome.match("no match '" + role + "' role"); + } } } - return ConditionOutcome.noMatch("no any roles: " + Arrays.toString(anyRole)); + return ConditionOutcome.noMatch("no match roles: " + Arrays.toString(expectedRoles)); } }