Search in sources :

Example 11 with AnyType

use of org.apache.syncope.core.persistence.api.entity.AnyType in project syncope by apache.

the class ResourceLogic method removeSyncToken.

@PreAuthorize("hasRole('" + StandardEntitlement.RESOURCE_UPDATE + "')")
public void removeSyncToken(final String key, final String anyTypeKey) {
    ExternalResource resource = resourceDAO.authFind(key);
    if (resource == null) {
        throw new NotFoundException("Resource '" + key + "'");
    }
    if (SyncopeConstants.REALM_ANYTYPE.equals(anyTypeKey)) {
        if (resource.getOrgUnit() == null) {
            throw new NotFoundException("Realm provision not enabled for Resource '" + key + "'");
        }
        resource.getOrgUnit().setSyncToken(null);
    } else {
        AnyType anyType = anyTypeDAO.find(anyTypeKey);
        if (anyType == null) {
            throw new NotFoundException("AnyType '" + anyTypeKey + "'");
        }
        Optional<? extends Provision> provision = resource.getProvision(anyType);
        if (!provision.isPresent()) {
            throw new NotFoundException("Provision for AnyType '" + anyTypeKey + "' in Resource '" + key + "'");
        }
        provision.get().setSyncToken(null);
    }
    Set<String> effectiveRealms = RealmUtils.getEffective(AuthContextUtils.getAuthorizations().get(StandardEntitlement.RESOURCE_UPDATE), resource.getConnector().getAdminRealm().getFullPath());
    securityChecks(effectiveRealms, resource.getConnector().getAdminRealm().getFullPath(), resource.getKey());
    resourceDAO.save(resource);
}
Also used : NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 12 with AnyType

use of org.apache.syncope.core.persistence.api.entity.AnyType in project syncope by apache.

the class ResourceLogic method readConnObject.

@PreAuthorize("hasRole('" + StandardEntitlement.RESOURCE_GET_CONNOBJECT + "')")
@Transactional(readOnly = true)
public ConnObjectTO readConnObject(final String key, final String anyTypeKey, final String anyKey) {
    Triple<ExternalResource, AnyType, Provision> init = connObjectInit(key, anyTypeKey);
    // 1. find any
    Any<?> any = init.getMiddle().getKind() == AnyTypeKind.USER ? userDAO.find(anyKey) : init.getMiddle().getKind() == AnyTypeKind.ANY_OBJECT ? anyObjectDAO.find(anyKey) : groupDAO.find(anyKey);
    if (any == null) {
        throw new NotFoundException(init.getMiddle() + " " + anyKey);
    }
    // 2. build connObjectKeyItem
    Optional<MappingItem> connObjectKeyItem = MappingUtils.getConnObjectKeyItem(init.getRight());
    if (!connObjectKeyItem.isPresent()) {
        throw new NotFoundException("ConnObjectKey mapping for " + init.getMiddle() + " " + anyKey + " on resource '" + key + "'");
    }
    Optional<String> connObjectKeyValue = mappingManager.getConnObjectKeyValue(any, init.getRight());
    // 3. determine attributes to query
    Set<MappingItem> linkinMappingItems = virSchemaDAO.findByProvision(init.getRight()).stream().map(virSchema -> virSchema.asLinkingMappingItem()).collect(Collectors.toSet());
    Iterator<MappingItem> mapItems = new IteratorChain<>(init.getRight().getMapping().getItems().iterator(), linkinMappingItems.iterator());
    // 4. read from the underlying connector
    Connector connector = connFactory.getConnector(init.getLeft());
    ConnectorObject connectorObject = connector.getObject(init.getRight().getObjectClass(), AttributeBuilder.build(connObjectKeyItem.get().getExtAttrName(), connObjectKeyValue.get()), MappingUtils.buildOperationOptions(mapItems));
    if (connectorObject == null) {
        throw new NotFoundException("Object " + connObjectKeyValue.get() + " with class " + init.getRight().getObjectClass() + " not found on resource " + key);
    }
    // 5. build result
    Set<Attribute> attributes = connectorObject.getAttributes();
    if (AttributeUtil.find(Uid.NAME, attributes) == null) {
        attributes.add(connectorObject.getUid());
    }
    if (AttributeUtil.find(Name.NAME, attributes) == null) {
        attributes.add(connectorObject.getName());
    }
    return ConnObjectUtils.getConnObjectTO(connectorObject);
}
Also used : Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) Autowired(org.springframework.beans.factory.annotation.Autowired) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) StringUtils(org.apache.commons.lang3.StringUtils) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) Attribute(org.identityconnectors.framework.common.objects.Attribute) GroupDAO(org.apache.syncope.core.persistence.api.dao.GroupDAO) Pair(org.apache.commons.lang3.tuple.Pair) AnyObjectDAO(org.apache.syncope.core.persistence.api.dao.AnyObjectDAO) ConnObjectUtils(org.apache.syncope.core.provisioning.java.utils.ConnObjectUtils) OperationOptions(org.identityconnectors.framework.common.objects.OperationOptions) AuthContextUtils(org.apache.syncope.core.spring.security.AuthContextUtils) Method(java.lang.reflect.Method) Triple(org.apache.commons.lang3.tuple.Triple) ResultsHandler(org.identityconnectors.framework.common.objects.ResultsHandler) UserDAO(org.apache.syncope.core.persistence.api.dao.UserDAO) Set(java.util.Set) ConnInstanceDAO(org.apache.syncope.core.persistence.api.dao.ConnInstanceDAO) ResourceDataBinder(org.apache.syncope.core.provisioning.api.data.ResourceDataBinder) Collectors(java.util.stream.Collectors) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) AnyTypeDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeDAO) Connector(org.apache.syncope.core.provisioning.api.Connector) ConnectorObject(org.identityconnectors.framework.common.objects.ConnectorObject) List(java.util.List) Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) AttributeUtil(org.identityconnectors.framework.common.objects.AttributeUtil) AttributeBuilder(org.identityconnectors.framework.common.objects.AttributeBuilder) ObjectClass(org.identityconnectors.framework.common.objects.ObjectClass) ConnectorFactory(org.apache.syncope.core.provisioning.api.ConnectorFactory) Optional(java.util.Optional) ExternalResourceDAO(org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO) StandardEntitlement(org.apache.syncope.common.lib.types.StandardEntitlement) OrderByClause(org.apache.syncope.core.persistence.api.dao.search.OrderByClause) ArrayUtils(org.apache.commons.lang3.ArrayUtils) ConnInstanceDataBinder(org.apache.syncope.core.provisioning.api.data.ConnInstanceDataBinder) ArrayList(java.util.ArrayList) RealmUtils(org.apache.syncope.core.provisioning.api.utils.RealmUtils) DelegatedAdministrationException(org.apache.syncope.core.spring.security.DelegatedAdministrationException) DuplicateException(org.apache.syncope.core.persistence.api.dao.DuplicateException) MappingManager(org.apache.syncope.core.provisioning.api.MappingManager) ClientExceptionType(org.apache.syncope.common.lib.types.ClientExceptionType) SyncopeConstants(org.apache.syncope.common.lib.SyncopeConstants) ImmutableTriple(org.apache.commons.lang3.tuple.ImmutableTriple) Iterator(java.util.Iterator) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) Uid(org.identityconnectors.framework.common.objects.Uid) IteratorChain(org.apache.syncope.common.lib.collections.IteratorChain) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance) Name(org.identityconnectors.framework.common.objects.Name) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) MappingUtils(org.apache.syncope.core.provisioning.java.utils.MappingUtils) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) Component(org.springframework.stereotype.Component) VirSchemaDAO(org.apache.syncope.core.persistence.api.dao.VirSchemaDAO) SearchResult(org.identityconnectors.framework.common.objects.SearchResult) Any(org.apache.syncope.core.persistence.api.entity.Any) Transactional(org.springframework.transaction.annotation.Transactional) Connector(org.apache.syncope.core.provisioning.api.Connector) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) Attribute(org.identityconnectors.framework.common.objects.Attribute) ConnectorObject(org.identityconnectors.framework.common.objects.ConnectorObject) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) IteratorChain(org.apache.syncope.common.lib.collections.IteratorChain) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with AnyType

use of org.apache.syncope.core.persistence.api.entity.AnyType in project syncope by apache.

the class JPAAnyObjectDAO method countByRealm.

@Override
public Map<String, Integer> countByRealm(final AnyType anyType) {
    Query query = entityManager().createQuery("SELECT e.realm, COUNT(e) FROM  " + JPAAnyObject.class.getSimpleName() + " e " + "WHERE e.type=:type GROUP BY e.realm");
    query.setParameter("type", anyType);
    @SuppressWarnings("unchecked") List<Object[]> results = query.getResultList();
    return results.stream().collect(Collectors.toMap(result -> ((Realm) result[0]).getFullPath(), result -> ((Number) result[1]).intValue()));
}
Also used : Date(java.util.Date) Realm(org.apache.syncope.core.persistence.api.entity.Realm) NoResultException(javax.persistence.NoResultException) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) JPAAnyObject(org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAAnyObject) URelationship(org.apache.syncope.core.persistence.api.entity.user.URelationship) TypedQuery(javax.persistence.TypedQuery) AnyDeletedEvent(org.apache.syncope.core.provisioning.api.event.AnyDeletedEvent) JPAAnyUtilsFactory(org.apache.syncope.core.persistence.jpa.entity.JPAAnyUtilsFactory) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) AnyCreatedUpdatedEvent(org.apache.syncope.core.provisioning.api.event.AnyCreatedUpdatedEvent) DelegatedAdministrationException(org.apache.syncope.core.spring.security.DelegatedAdministrationException) GroupDAO(org.apache.syncope.core.persistence.api.dao.GroupDAO) Pair(org.apache.commons.lang3.tuple.Pair) AnyObjectDAO(org.apache.syncope.core.persistence.api.dao.AnyObjectDAO) Propagation(org.springframework.transaction.annotation.Propagation) Map(java.util.Map) AnyEntitlement(org.apache.syncope.common.lib.types.AnyEntitlement) JPAARelationship(org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAARelationship) AuthContextUtils(org.apache.syncope.core.spring.security.AuthContextUtils) Repository(org.springframework.stereotype.Repository) UserDAO(org.apache.syncope.core.persistence.api.dao.UserDAO) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) Collection(java.util.Collection) Set(java.util.Set) JPAURelationship(org.apache.syncope.core.persistence.jpa.entity.user.JPAURelationship) Collectors(java.util.stream.Collectors) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) List(java.util.List) Query(javax.persistence.Query) ARelationship(org.apache.syncope.core.persistence.api.entity.anyobject.ARelationship) Relationship(org.apache.syncope.core.persistence.api.entity.Relationship) Group(org.apache.syncope.core.persistence.api.entity.group.Group) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils) ApplicationContextProvider(org.apache.syncope.core.spring.ApplicationContextProvider) Collections(java.util.Collections) Any(org.apache.syncope.core.persistence.api.entity.Any) Transactional(org.springframework.transaction.annotation.Transactional) TypedQuery(javax.persistence.TypedQuery) Query(javax.persistence.Query) Realm(org.apache.syncope.core.persistence.api.entity.Realm)

Example 14 with AnyType

use of org.apache.syncope.core.persistence.api.entity.AnyType in project syncope by apache.

the class JPAAnyObjectDAO method countByType.

@Override
public Map<AnyType, Integer> countByType() {
    Query query = entityManager().createQuery("SELECT e.type, COUNT(e) AS countByType FROM  " + JPAAnyObject.class.getSimpleName() + " e " + "GROUP BY e.type ORDER BY countByType DESC");
    @SuppressWarnings("unchecked") List<Object[]> results = query.getResultList();
    Map<AnyType, Integer> countByRealm = new LinkedHashMap<>(results.size());
    for (Object[] result : results) {
        countByRealm.put((AnyType) result[0], ((Number) result[1]).intValue());
    }
    return Collections.unmodifiableMap(countByRealm);
}
Also used : TypedQuery(javax.persistence.TypedQuery) Query(javax.persistence.Query) JPAAnyObject(org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAAnyObject) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) LinkedHashMap(java.util.LinkedHashMap)

Example 15 with AnyType

use of org.apache.syncope.core.persistence.api.entity.AnyType in project syncope by apache.

the class JPAAnyTypeDAO method delete.

@Override
public void delete(final String key) {
    AnyType anyType = find(key);
    if (anyType == null) {
        return;
    }
    if (anyType.equals(findUser()) || anyType.equals(findGroup())) {
        throw new IllegalArgumentException(key + " cannot be deleted");
    }
    remediationDAO.findByAnyType(anyType).forEach(remediation -> {
        remediation.setAnyType(null);
        remediationDAO.delete(remediation);
    });
    entityManager().remove(anyType);
}
Also used : AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) JPAAnyType(org.apache.syncope.core.persistence.jpa.entity.JPAAnyType)

Aggregations

AnyType (org.apache.syncope.core.persistence.api.entity.AnyType)35 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)13 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)9 ExternalResource (org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)9 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)7 Collectors (java.util.stream.Collectors)6 AnyTypeDAO (org.apache.syncope.core.persistence.api.dao.AnyTypeDAO)6 AnyTypeClass (org.apache.syncope.core.persistence.api.entity.AnyTypeClass)6 Autowired (org.springframework.beans.factory.annotation.Autowired)6 Component (org.springframework.stereotype.Component)6 ArrayList (java.util.ArrayList)5 StringUtils (org.apache.commons.lang3.StringUtils)5 AnyTypeKind (org.apache.syncope.common.lib.types.AnyTypeKind)5 Realm (org.apache.syncope.core.persistence.api.entity.Realm)5 AnyObject (org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject)5 Group (org.apache.syncope.core.persistence.api.entity.group.Group)5 Provision (org.apache.syncope.core.persistence.api.entity.resource.Provision)5 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)5 Test (org.junit.jupiter.api.Test)5 Map (java.util.Map)4