Search in sources :

Example 1 with UserGroupService

use of com.blackducksoftware.integration.hub.service.UserGroupService in project hub-alert by blackducksoftware.

the class LoginActions method isUserRoleValid.

public boolean isUserRoleValid(final String userName, final RestConnection restConnection) {
    final HubServicesFactory hubServicesFactory = new HubServicesFactory(restConnection);
    final UserGroupService userGroupService = hubServicesFactory.createUserGroupService();
    try {
        final List<RoleAssignmentView> userRoles = userGroupService.getRolesForUser(userName);
        for (final RoleAssignmentView roles : userRoles) {
            if ("System Administrator".equalsIgnoreCase(roles.name)) {
                return true;
            }
        }
    } catch (final IntegrationException e) {
        return false;
    }
    return false;
}
Also used : IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) UserGroupService(com.blackducksoftware.integration.hub.service.UserGroupService) RoleAssignmentView(com.blackducksoftware.integration.hub.api.generated.view.RoleAssignmentView) HubServicesFactory(com.blackducksoftware.integration.hub.service.HubServicesFactory)

Example 2 with UserGroupService

use of com.blackducksoftware.integration.hub.service.UserGroupService in project hub-alert by blackducksoftware.

the class EmailGroupChannel method getEmailAddressesForGroup.

private List<String> getEmailAddressesForGroup(final HubServicesFactory hubServicesFactory, final String hubGroup) throws IntegrationException {
    final UserGroupService groupService = hubServicesFactory.createUserGroupService();
    final UserGroupView userGroupView = groupService.getGroupByName(hubGroup);
    if (userGroupView == null) {
        throw new IntegrationException("Could not find the Hub group: " + hubGroup);
    }
    logger.info(userGroupView.toString());
    logger.info(userGroupView.json);
    final List<UserView> users = hubServicesFactory.createHubService().getAllResponses(userGroupView, UserGroupView.USERS_LINK_RESPONSE);
    return users.stream().map(user -> user.email).collect(Collectors.toList());
}
Also used : AuditEntryRepositoryWrapper(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper) TemplateException(freemarker.template.TemplateException) LoggerFactory(org.slf4j.LoggerFactory) MessagingException(javax.mail.MessagingException) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) GlobalEmailConfigEntity(com.blackducksoftware.integration.hub.alert.channel.email.repository.global.GlobalEmailConfigEntity) StringUtils(org.apache.commons.lang3.StringUtils) HubServicesFactory(com.blackducksoftware.integration.hub.service.HubServicesFactory) Gson(com.google.gson.Gson) TemplateNotFoundException(freemarker.template.TemplateNotFoundException) JmsListener(org.springframework.jms.annotation.JmsListener) GlobalProperties(com.blackducksoftware.integration.hub.alert.config.GlobalProperties) UserGroupService(com.blackducksoftware.integration.hub.service.UserGroupService) UserGroupView(com.blackducksoftware.integration.hub.api.generated.view.UserGroupView) EmailTarget(com.blackducksoftware.integration.hub.alert.channel.email.template.EmailTarget) Logger(org.slf4j.Logger) EmailGroupDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.channel.email.repository.distribution.EmailGroupDistributionConfigEntity) IOException(java.io.IOException) EmailGroupDistributionRepositoryWrapper(com.blackducksoftware.integration.hub.alert.channel.email.repository.distribution.EmailGroupDistributionRepositoryWrapper) Collectors(java.util.stream.Collectors) UserView(com.blackducksoftware.integration.hub.api.generated.view.UserView) MalformedTemplateNameException(freemarker.template.MalformedTemplateNameException) List(java.util.List) Component(org.springframework.stereotype.Component) CommonDistributionRepositoryWrapper(com.blackducksoftware.integration.hub.alert.datasource.entity.repository.CommonDistributionRepositoryWrapper) DistributionChannel(com.blackducksoftware.integration.hub.alert.channel.DistributionChannel) ParseException(freemarker.core.ParseException) GlobalEmailRepositoryWrapper(com.blackducksoftware.integration.hub.alert.channel.email.repository.global.GlobalEmailRepositoryWrapper) ProjectData(com.blackducksoftware.integration.hub.alert.digest.model.ProjectData) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) SupportedChannels(com.blackducksoftware.integration.hub.alert.channel.SupportedChannels) UserGroupView(com.blackducksoftware.integration.hub.api.generated.view.UserGroupView) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) UserGroupService(com.blackducksoftware.integration.hub.service.UserGroupService) UserView(com.blackducksoftware.integration.hub.api.generated.view.UserView)

Aggregations

IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)2 HubServicesFactory (com.blackducksoftware.integration.hub.service.HubServicesFactory)2 UserGroupService (com.blackducksoftware.integration.hub.service.UserGroupService)2 AuditEntryRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper)1 DistributionChannel (com.blackducksoftware.integration.hub.alert.channel.DistributionChannel)1 SupportedChannels (com.blackducksoftware.integration.hub.alert.channel.SupportedChannels)1 EmailGroupDistributionConfigEntity (com.blackducksoftware.integration.hub.alert.channel.email.repository.distribution.EmailGroupDistributionConfigEntity)1 EmailGroupDistributionRepositoryWrapper (com.blackducksoftware.integration.hub.alert.channel.email.repository.distribution.EmailGroupDistributionRepositoryWrapper)1 GlobalEmailConfigEntity (com.blackducksoftware.integration.hub.alert.channel.email.repository.global.GlobalEmailConfigEntity)1 GlobalEmailRepositoryWrapper (com.blackducksoftware.integration.hub.alert.channel.email.repository.global.GlobalEmailRepositoryWrapper)1 EmailTarget (com.blackducksoftware.integration.hub.alert.channel.email.template.EmailTarget)1 GlobalProperties (com.blackducksoftware.integration.hub.alert.config.GlobalProperties)1 CommonDistributionRepositoryWrapper (com.blackducksoftware.integration.hub.alert.datasource.entity.repository.CommonDistributionRepositoryWrapper)1 ProjectData (com.blackducksoftware.integration.hub.alert.digest.model.ProjectData)1 RoleAssignmentView (com.blackducksoftware.integration.hub.api.generated.view.RoleAssignmentView)1 UserGroupView (com.blackducksoftware.integration.hub.api.generated.view.UserGroupView)1 UserView (com.blackducksoftware.integration.hub.api.generated.view.UserView)1 Gson (com.google.gson.Gson)1 ParseException (freemarker.core.ParseException)1 MalformedTemplateNameException (freemarker.template.MalformedTemplateNameException)1