Skip to content

Commit 73ac554

Browse files
committed
support checking if exists only - bumps to 1.3.1
1 parent 1689fcc commit 73ac554

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.instipod</groupId>
88
<artifactId>KeycloakAuthenticators</artifactId>
9-
<version>1.3-SNAPSHOT</version>
9+
<version>1.3.1-SNAPSHOT</version>
1010
<packaging>jar</packaging>
1111
<description/>
1212

src/main/java/com/instipod/keycloakauthenticators/ConditionalAttributeAuthenticator.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@ public boolean matchCondition(AuthenticationFlowContext context) {
2727
attributeValue = AuthenticatorUtils.variableReplace(context, attributeValue);
2828

2929
List<String> values = context.getUser().getAttribute(attributeName);
30-
boolean hasAttribute = values.contains(attributeValue);
30+
boolean hasAttribute;
31+
if (attributeValue.isBlank()) {
32+
//check presence only
33+
hasAttribute = (values.size() > 0);
34+
} else {
35+
hasAttribute = values.contains(attributeValue);
36+
}
3137

3238
boolean check;
3339
if (not) {

src/main/java/com/instipod/keycloakauthenticators/ConditionalAttributeAuthenticatorFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class ConditionalAttributeAuthenticatorFactory implements org.keycloak.au
2121
static {
2222
commonConfig = Collections.unmodifiableList(ProviderConfigurationBuilder.create()
2323
.property().name(CONDITIONAL_ATTRIBUTE_NAME).label("User Attribute Name").helpText("Attribute name to check (supports variables)").type(ProviderConfigProperty.STRING_TYPE).add()
24-
.property().name(CONDITIONAL_ATTRIBUTE_VALUE).label("User Attribute Value").helpText("Attribute value (supports variables)").type(ProviderConfigProperty.STRING_TYPE).add()
24+
.property().name(CONDITIONAL_ATTRIBUTE_VALUE).label("User Attribute Value").helpText("Attribute value (supports variables) (leave blank to only check if present)").type(ProviderConfigProperty.STRING_TYPE).add()
2525
.property().name(CONDITIONAL_NOT).label("Not").helpText("If we should match on NOT having this attribute").type(ProviderConfigProperty.BOOLEAN_TYPE).add()
2626
.build()
2727
);

0 commit comments

Comments
 (0)