Search in sources :

Example 1 with RoleAssignmentView

use of com.synopsys.integration.blackduck.api.generated.view.RoleAssignmentView 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;
}
Also used : IntegrationException(com.synopsys.integration.exception.IntegrationException) RoleAssignmentView(com.synopsys.integration.blackduck.api.generated.view.RoleAssignmentView) ApiDiscovery(com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView)

Aggregations

ApiDiscovery (com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery)1 RoleAssignmentView (com.synopsys.integration.blackduck.api.generated.view.RoleAssignmentView)1 UserView (com.synopsys.integration.blackduck.api.generated.view.UserView)1 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)1 IntegrationException (com.synopsys.integration.exception.IntegrationException)1