use of io.cryostat.net.security.ResourceType in project cryostat by cryostatio.
the class OpenShiftAuthManager method processResourceMapping.
static Map<ResourceType, Set<GroupResource>> processResourceMapping(ClassPropertiesLoader loader, Logger logger) {
Map<ResourceType, Set<GroupResource>> resourceMap = new HashMap<>();
Map<String, String> props;
try {
props = loader.loadAsMap(OpenShiftAuthManager.class);
} catch (IOException ioe) {
logger.error(ioe);
return Collections.unmodifiableMap(resourceMap);
}
props.entrySet().forEach(entry -> {
try {
ResourceType type = ResourceType.valueOf(entry.getKey());
Set<GroupResource> values = Arrays.asList(entry.getValue().split(",")).stream().map(String::strip).filter(StringUtils::isNotBlank).map(GroupResource::fromString).collect(Collectors.toSet());
resourceMap.put(type, values);
} catch (IllegalArgumentException iae) {
logger.error(iae);
}
});
return Collections.unmodifiableMap(resourceMap);
}
use of io.cryostat.net.security.ResourceType in project cryostat by cryostatio.
the class OpenShiftAuthManagerTest method testPropertiesResourceMapProcessing.
@ParameterizedTest
@MethodSource("getResourceMaps")
void testPropertiesResourceMapProcessing(Map<String, Object> map) throws IOException {
ClassPropertiesLoader loader = Mockito.mock(ClassPropertiesLoader.class);
Map<String, String> resourcesMap = new HashMap<>();
map.entrySet().stream().filter(e -> !e.getKey().equals("expected")).forEach(e -> resourcesMap.put((String) e.getKey(), (String) e.getValue()));
Map<ResourceType, Set<GroupResource>> expected = (Map<ResourceType, Set<GroupResource>>) map.get("expected");
Mockito.when(loader.loadAsMap(Mockito.any())).thenReturn(resourcesMap);
Map<ResourceType, Set<GroupResource>> result = OpenShiftAuthManager.processResourceMapping(loader, logger);
MatcherAssert.assertThat(result, Matchers.equalTo(expected));
}
Aggregations