Search in sources :

Example 1 with User

use of io.gravitee.rest.api.model.providers.User in project gravitee-management-rest-api by gravitee-io.

the class MembershipServiceImpl method findUserMembershipMetadata.

@Override
public Metadata findUserMembershipMetadata(List<UserMembership> memberships, MembershipReferenceType type) {
    if (memberships == null || memberships.isEmpty() || type == null || (!type.equals(MembershipReferenceType.API) && !type.equals(MembershipReferenceType.APPLICATION) && !type.equals(MembershipReferenceType.GROUP))) {
        return new Metadata();
    }
    try {
        Metadata metadata = new Metadata();
        if (type.equals(MembershipReferenceType.API)) {
            ApiCriteria.Builder criteria = new ApiCriteria.Builder();
            ApiFieldExclusionFilter filter = (new ApiFieldExclusionFilter.Builder()).excludeDefinition().excludePicture().build();
            criteria.ids(memberships.stream().map(UserMembership::getReference).toArray(String[]::new));
            apiRepository.search(criteria.build(), filter).forEach(api -> {
                metadata.put(api.getId(), "name", api.getName());
                metadata.put(api.getId(), "version", api.getVersion());
                metadata.put(api.getId(), "visibility", api.getVisibility());
            });
        } else if (type.equals(MembershipReferenceType.APPLICATION)) {
            applicationRepository.findByIds(memberships.stream().map(UserMembership::getReference).collect(Collectors.toList())).forEach(application -> {
                metadata.put(application.getId(), "name", application.getName());
            });
        }
        return metadata;
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurs while trying to get user membership metadata", ex);
        throw new TechnicalManagementException("An error occurs while trying to get user membership metadata", ex);
    }
}
Also used : io.gravitee.rest.api.service(io.gravitee.rest.api.service) java.util(java.util) Pageable(io.gravitee.rest.api.model.common.Pageable) MEMBERSHIP_CREATED(io.gravitee.repository.management.model.Membership.AuditEvent.MEMBERSHIP_CREATED) Page(io.gravitee.common.data.domain.Page) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) LoggerFactory(org.slf4j.LoggerFactory) MembershipRepository(io.gravitee.repository.management.api.MembershipRepository) Autowired(org.springframework.beans.factory.annotation.Autowired) GraviteeContext(io.gravitee.rest.api.service.common.GraviteeContext) ApplicationAlertEventType(io.gravitee.rest.api.model.alert.ApplicationAlertEventType) RoleScope(io.gravitee.rest.api.model.permissions.RoleScope) ApiCriteria(io.gravitee.repository.management.api.search.ApiCriteria) ApplicationAlertMembershipEvent(io.gravitee.rest.api.model.alert.ApplicationAlertMembershipEvent) Collections.singleton(java.util.Collections.singleton) ApiRepository(io.gravitee.repository.management.api.ApiRepository) io.gravitee.rest.api.model(io.gravitee.rest.api.model) ApplicationRepository(io.gravitee.repository.management.api.ApplicationRepository) User(io.gravitee.rest.api.model.providers.User) Collectors.toSet(java.util.stream.Collectors.toSet) PageableImpl(io.gravitee.rest.api.model.common.PageableImpl) Collections.emptyMap(java.util.Collections.emptyMap) UuidString(io.gravitee.rest.api.service.common.UuidString) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Logger(org.slf4j.Logger) Audit(io.gravitee.repository.management.model.Audit) PRIMARY_OWNER(io.gravitee.rest.api.model.permissions.SystemRole.PRIMARY_OWNER) Metadata(io.gravitee.rest.api.model.pagedresult.Metadata) Collectors(java.util.stream.Collectors) ApiFieldExclusionFilter(io.gravitee.repository.management.api.search.ApiFieldExclusionFilter) TimeUnit(java.util.concurrent.TimeUnit) Collectors.toList(java.util.stream.Collectors.toList) Component(org.springframework.stereotype.Component) NotificationParamsBuilder(io.gravitee.rest.api.service.notification.NotificationParamsBuilder) EventManager(io.gravitee.common.event.EventManager) EmailNotificationBuilder(io.gravitee.rest.api.service.builder.EmailNotificationBuilder) io.gravitee.rest.api.service.exceptions(io.gravitee.rest.api.service.exceptions) MEMBERSHIP_DELETED(io.gravitee.repository.management.model.Membership.AuditEvent.MEMBERSHIP_DELETED) CacheBuilder(com.google.common.cache.CacheBuilder) Cache(com.google.common.cache.Cache) SystemRole(io.gravitee.rest.api.model.permissions.SystemRole) ApiCriteria(io.gravitee.repository.management.api.search.ApiCriteria) ApiFieldExclusionFilter(io.gravitee.repository.management.api.search.ApiFieldExclusionFilter) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) NotificationParamsBuilder(io.gravitee.rest.api.service.notification.NotificationParamsBuilder) EmailNotificationBuilder(io.gravitee.rest.api.service.builder.EmailNotificationBuilder) CacheBuilder(com.google.common.cache.CacheBuilder) Metadata(io.gravitee.rest.api.model.pagedresult.Metadata) UuidString(io.gravitee.rest.api.service.common.UuidString)

Example 2 with User

use of io.gravitee.rest.api.model.providers.User in project gravitee-management-rest-api by gravitee-io.

the class MembershipServiceImpl method findUserFromMembershipMember.

private UserEntity findUserFromMembershipMember(MembershipMember member) {
    UserEntity userEntity;
    if (member.getMemberId() != null) {
        userEntity = userService.findById(member.getMemberId());
    } else {
        // We have a user reference, meaning that the user is coming from an external system
        // User does not exist so we are looking into defined providers
        Optional<io.gravitee.rest.api.model.providers.User> providerUser = identityService.findByReference(member.getReference());
        if (providerUser.isPresent()) {
            User identityUser = providerUser.get();
            userEntity = findOrCreateUser(identityUser);
        } else {
            throw new UserNotFoundException(member.getReference());
        }
    }
    return userEntity;
}
Also used : User(io.gravitee.rest.api.model.providers.User) io.gravitee.rest.api.model(io.gravitee.rest.api.model)

Example 3 with User

use of io.gravitee.rest.api.model.providers.User in project gravitee-management-rest-api by gravitee-io.

the class IdentityServiceImpl method convert.

private User convert(io.gravitee.rest.api.idp.api.identity.User identity) {
    User user = new User();
    user.setId(identity.getId());
    user.setSourceId(identity.getReference());
    user.setSource(identity.getSource());
    user.setEmail(identity.getEmail());
    user.setFirstname(identity.getFirstname());
    user.setLastname(identity.getLastname());
    user.setDisplayName(identity.getDisplayName());
    user.setPicture(identity.getPicture());
    user.setRoles(identity.getRoles());
    return user;
}
Also used : SearchableUser(io.gravitee.rest.api.idp.api.identity.SearchableUser) User(io.gravitee.rest.api.model.providers.User)

Aggregations

User (io.gravitee.rest.api.model.providers.User)3 io.gravitee.rest.api.model (io.gravitee.rest.api.model)2 Cache (com.google.common.cache.Cache)1 CacheBuilder (com.google.common.cache.CacheBuilder)1 Page (io.gravitee.common.data.domain.Page)1 EventManager (io.gravitee.common.event.EventManager)1 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)1 ApiRepository (io.gravitee.repository.management.api.ApiRepository)1 ApplicationRepository (io.gravitee.repository.management.api.ApplicationRepository)1 MembershipRepository (io.gravitee.repository.management.api.MembershipRepository)1 ApiCriteria (io.gravitee.repository.management.api.search.ApiCriteria)1 ApiFieldExclusionFilter (io.gravitee.repository.management.api.search.ApiFieldExclusionFilter)1 Audit (io.gravitee.repository.management.model.Audit)1 MEMBERSHIP_CREATED (io.gravitee.repository.management.model.Membership.AuditEvent.MEMBERSHIP_CREATED)1 MEMBERSHIP_DELETED (io.gravitee.repository.management.model.Membership.AuditEvent.MEMBERSHIP_DELETED)1 SearchableUser (io.gravitee.rest.api.idp.api.identity.SearchableUser)1 ApplicationAlertEventType (io.gravitee.rest.api.model.alert.ApplicationAlertEventType)1 ApplicationAlertMembershipEvent (io.gravitee.rest.api.model.alert.ApplicationAlertMembershipEvent)1 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)1 Pageable (io.gravitee.rest.api.model.common.Pageable)1