Search in sources :

Example 16 with UserView

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;
}
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

UserView (com.synopsys.integration.blackduck.api.generated.view.UserView)16 IntegrationException (com.synopsys.integration.exception.IntegrationException)8 HttpUrl (com.synopsys.integration.rest.HttpUrl)7 ApiDiscovery (com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery)6 ProjectView (com.synopsys.integration.blackduck.api.generated.view.ProjectView)6 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)6 ProviderProject (com.synopsys.integration.alert.common.persistence.model.ProviderProject)5 ProviderUserModel (com.synopsys.integration.alert.common.persistence.model.ProviderUserModel)5 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)5 UserService (com.synopsys.integration.blackduck.service.dataservice.UserService)5 Test (org.junit.jupiter.api.Test)5 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)4 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)4 ProjectUsersService (com.synopsys.integration.blackduck.service.dataservice.ProjectUsersService)4 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)3 BlackDuckPropertiesFactory (com.synopsys.integration.alert.provider.blackduck.factory.BlackDuckPropertiesFactory)3 UrlMultipleResponses (com.synopsys.integration.blackduck.api.core.response.UrlMultipleResponses)3 BlackDuckPageResponse (com.synopsys.integration.blackduck.http.BlackDuckPageResponse)3 BlackDuckRequestBuilder (com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder)3 BlackDuckHttpClient (com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient)3