use of com.synopsys.integration.blackduck.api.generated.view.UserView in project hub-alert by blackducksoftware.
the class BlackDuckApiTokenValidator method hasPermittedRole.
private boolean hasPermittedRole(BlackDuckServicesFactory blackDuckServicesFactory) {
BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();
ApiDiscovery apiDiscovery = blackDuckServicesFactory.getApiDiscovery();
UserView currentUser;
try {
currentUser = blackDuckApiClient.getResponse(apiDiscovery.metaCurrentUserLink());
} catch (IntegrationException integrationException) {
logger.error("Failed to GET the currently authenticated Black Duck user", integrationException);
return false;
}
try {
List<RoleAssignmentView> allRolesForCurrentUser = blackDuckApiClient.getAllResponses(currentUser.metaRolesLink());
return allRolesForCurrentUser.stream().anyMatch(this::isPermittedRole);
} catch (IntegrationException integrationException) {
logger.error("Failed to GET the currently authenticated Black Duck user's roles", integrationException);
}
return false;
}
Aggregations