Skip to content
Snippets Groups Projects
Commit f9d035e1 authored by Evgeny Bardin's avatar Evgeny Bardin
Browse files

OZG-7092 fix attribute filter

parent 6c64ce4f
No related branches found
No related tags found
1 merge request!1OZG-7092 Anpassung TokenChecker
...@@ -26,7 +26,6 @@ package de.ozgcloud.token.saml; ...@@ -26,7 +26,6 @@ package de.ozgcloud.token.saml;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Optional; import java.util.Optional;
...@@ -63,8 +62,6 @@ import net.shibboleth.utilities.java.support.resolver.CriteriaSet; ...@@ -63,8 +62,6 @@ import net.shibboleth.utilities.java.support.resolver.CriteriaSet;
@Builder @Builder
public class SamlAttributeService { public class SamlAttributeService {
private static final String ID_AS_POSTFACH_ID_KEY = "OZG_CLOUD_POSTFACH_ID";
private final SignatureTrustEngine signatureTrustEngine; private final SignatureTrustEngine signatureTrustEngine;
private final Decrypter decrypter; private final Decrypter decrypter;
private final SAMLSignatureProfileValidator profileValidator; private final SAMLSignatureProfileValidator profileValidator;
...@@ -152,26 +149,29 @@ public class SamlAttributeService { ...@@ -152,26 +149,29 @@ public class SamlAttributeService {
} }
TokenAttributes buildTokenAttributes(Map<String, String> tokenAttributes, Response token) { TokenAttributes buildTokenAttributes(Map<String, String> tokenAttributes, Response token) {
var result = TokenAttributes.builder().postfachId(getPostfachId(tokenAttributes, token)).trustLevel(getTrustLevel(tokenAttributes)); var tokenAttributesBuilder = TokenAttributes.builder().postfachId(getPostfachId(tokenAttributes, token))
tokenAttributes.entrySet().stream().filter(this::isNotMappedField).map(this::buildTokenAttribute).forEach(result::otherAttribute); .trustLevel(getTrustLevel(tokenAttributes));
return result.build(); tokenAttributes.entrySet().stream().filter(this::isNotMappedField).map(this::buildTokenAttribute)
.forEach(tokenAttributesBuilder::otherAttribute);
return tokenAttributesBuilder.build();
} }
String getPostfachId(Map<String, String> tokenAttributes, Response token) { String getPostfachId(Map<String, String> tokenAttributes, Response token) {
return tokenValidationProperty.isUseIdAsPostfachId() ? token.getID() : getMappedValue(tokenAttributes, TokenAttributes.POSTFACH_ID_KEY); return tokenValidationProperty.isUseIdAsPostfachId() ? token.getID() : getValue(tokenAttributes, TokenAttributes.POSTFACH_ID_KEY);
} }
String getTrustLevel(Map<String, String> tokenAttributes) { String getTrustLevel(Map<String, String> tokenAttributes) {
return getMappedValue(tokenAttributes, TokenAttributes.TRUST_LEVEL_KEY); return getValue(tokenAttributes, TokenAttributes.TRUST_LEVEL_KEY);
} }
String getMappedValue(Map<String, String> tokenAttributes, String key) { String getValue(Map<String, String> tokenAttributes, String key) {
var mappedKey = tokenValidationProperty.getMappings().getOrDefault(key, key); var mappedKey = tokenValidationProperty.getMappings().getOrDefault(key, key);
return tokenAttributes.get(mappedKey); return tokenAttributes.get(mappedKey);
} }
boolean isNotMappedField(Map.Entry<String, String> attributeEntry) { boolean isNotMappedField(Map.Entry<String, String> attributeEntry) {
return !tokenValidationProperty.getMappings().containsValue(attributeEntry.getKey()); var mappedKey = tokenValidationProperty.getMappings().get(attributeEntry.getKey());
return !StringUtils.equalsAny(mappedKey, TokenAttributes.POSTFACH_ID_KEY, TokenAttributes.TRUST_LEVEL_KEY);
} }
TokenAttribute buildTokenAttribute(Map.Entry<String, String> attribute) { TokenAttribute buildTokenAttribute(Map.Entry<String, String> attribute) {
......
...@@ -747,17 +747,19 @@ class SamlAttributeServiceTest { ...@@ -747,17 +747,19 @@ class SamlAttributeServiceTest {
assertThat(result).isTrue(); assertThat(result).isTrue();
} }
@Test @DisplayName("should return false when")
void shouldReturnFalseWhenMapped() { @ParameterizedTest(name = "key is {0}")
when(tokenValidationProperty.getMappings()).thenReturn(Map.of(KEY, TokenAttributeTestFactory.NAME)); @ValueSource(strings = { TokenAttributes.POSTFACH_ID_KEY, TokenAttributes.TRUST_LEVEL_KEY })
void shouldReturnFalseWhenMapped(String mappedKey) {
when(tokenValidationProperty.getMappings()).thenReturn(Map.of(KEY, mappedKey));
var result = service.isNotMappedField(Map.entry(TokenAttributeTestFactory.NAME, TokenAttributeTestFactory.VALUE)); var result = isNotMappedField();
assertThat(result).isFalse(); assertThat(result).isFalse();
} }
private boolean isNotMappedField() { private boolean isNotMappedField() {
return service.isNotMappedField(Map.entry(TokenAttributeTestFactory.NAME, TokenAttributeTestFactory.VALUE)); return service.isNotMappedField(Map.entry(KEY, TokenAttributeTestFactory.VALUE));
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment