Apply review suggestions
This commit is contained in:
parent
5c12f1b53f
commit
420258ef9f
1 changed files with 12 additions and 20 deletions
|
@ -2,13 +2,12 @@ package com.provectus.kafka.ui.service.rbac.extractor;
|
||||||
|
|
||||||
import static com.provectus.kafka.ui.model.rbac.provider.Provider.Name.OAUTH;
|
import static com.provectus.kafka.ui.model.rbac.provider.Provider.Name.OAUTH;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import com.provectus.kafka.ui.config.auth.OAuthProperties;
|
import com.provectus.kafka.ui.config.auth.OAuthProperties;
|
||||||
import com.provectus.kafka.ui.model.rbac.Role;
|
import com.provectus.kafka.ui.model.rbac.Role;
|
||||||
import com.provectus.kafka.ui.model.rbac.provider.Provider;
|
import com.provectus.kafka.ui.model.rbac.provider.Provider;
|
||||||
import com.provectus.kafka.ui.service.rbac.AccessControlService;
|
import com.provectus.kafka.ui.service.rbac.AccessControlService;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -23,8 +22,6 @@ import reactor.core.publisher.Mono;
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class OauthAuthorityExtractor implements ProviderAuthorityExtractor {
|
public class OauthAuthorityExtractor implements ProviderAuthorityExtractor {
|
||||||
|
|
||||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
|
||||||
|
|
||||||
public static final String ROLES_FIELD_PARAM_NAME = "roles-field";
|
public static final String ROLES_FIELD_PARAM_NAME = "roles-field";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -97,25 +94,20 @@ public class OauthAuthorityExtractor implements ProviderAuthorityExtractor {
|
||||||
return Collections.emptySet();
|
return Collections.emptySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
if ((roles instanceof List<?>) || (roles instanceof Set<?>)) {
|
||||||
if ((roles instanceof List<?>) || (roles instanceof Set<?>)) {
|
log.trace("The field is either a set or a list, returning as is");
|
||||||
log.trace("The field is either a set or a list, returning as is");
|
return (Collection<String>) roles;
|
||||||
return (Collection<String>) roles;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!(roles instanceof String)) {
|
if (!(roles instanceof String)) {
|
||||||
log.debug("The field is not a string, skipping");
|
log.debug("The field is not a string, skipping");
|
||||||
return Collections.emptySet();
|
|
||||||
}
|
|
||||||
|
|
||||||
log.trace("Trying to deserialize the field");
|
|
||||||
//@formatter:off
|
|
||||||
return objectMapper.readValue((String) roles, new TypeReference<>() {});
|
|
||||||
//@formatter:on
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("Error deserializing field", e);
|
|
||||||
return Collections.emptySet();
|
return Collections.emptySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.trace("Trying to deserialize the field value [{}] as a string", roles);
|
||||||
|
|
||||||
|
return Arrays.stream(((String) roles).split(","))
|
||||||
|
.collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue