Search in sources :

Example 6 with SyncopeGrantedAuthority

use of org.apache.syncope.core.spring.security.SyncopeGrantedAuthority in project syncope by apache.

the class AnyTypeDataBinderImpl method create.

@Override
public AnyType create(final AnyTypeTO anyTypeTO) {
    AnyType anyType = entityFactory.newEntity(AnyType.class);
    update(anyType, anyTypeTO);
    Set<String> added = EntitlementsHolder.getInstance().addFor(anyType.getKey());
    if (!adminUser.equals(AuthContextUtils.getUsername())) {
        AccessToken accessToken = accessTokenDAO.findByOwner(AuthContextUtils.getUsername());
        try {
            Set<SyncopeGrantedAuthority> authorities = new HashSet<>(POJOHelper.deserialize(ENCRYPTOR.decode(new String(accessToken.getAuthorities()), CipherAlgorithm.AES), new TypeReference<Set<SyncopeGrantedAuthority>>() {
            }));
            added.forEach(entitlement -> {
                authorities.add(new SyncopeGrantedAuthority(entitlement, SyncopeConstants.ROOT_REALM));
            });
            accessToken.setAuthorities(ENCRYPTOR.encode(POJOHelper.serialize(authorities), CipherAlgorithm.AES).getBytes());
            accessTokenDAO.save(accessToken);
        } catch (Exception e) {
            LOG.error("Could not fetch or store authorities", e);
        }
    }
    return anyType;
}
Also used : SyncopeGrantedAuthority(org.apache.syncope.core.spring.security.SyncopeGrantedAuthority) AccessToken(org.apache.syncope.core.persistence.api.entity.AccessToken) TypeReference(com.fasterxml.jackson.core.type.TypeReference) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) HashSet(java.util.HashSet)

Example 7 with SyncopeGrantedAuthority

use of org.apache.syncope.core.spring.security.SyncopeGrantedAuthority in project syncope by apache.

the class AnyTypeDataBinderImpl method delete.

@Override
public AnyTypeTO delete(final AnyType anyType) {
    AnyTypeTO deleted = getAnyTypeTO(anyType);
    anyTypeDAO.delete(anyType.getKey());
    final Set<String> removed = EntitlementsHolder.getInstance().removeFor(deleted.getKey());
    if (!adminUser.equals(AuthContextUtils.getUsername())) {
        AccessToken accessToken = accessTokenDAO.findByOwner(AuthContextUtils.getUsername());
        try {
            Set<SyncopeGrantedAuthority> authorities = new HashSet<>(POJOHelper.deserialize(ENCRYPTOR.decode(new String(accessToken.getAuthorities()), CipherAlgorithm.AES), new TypeReference<Set<SyncopeGrantedAuthority>>() {
            }));
            authorities.removeAll(authorities.stream().filter(authority -> removed.contains(authority.getAuthority())).collect(Collectors.toList()));
            accessToken.setAuthorities(ENCRYPTOR.encode(POJOHelper.serialize(authorities), CipherAlgorithm.AES).getBytes());
            accessTokenDAO.save(accessToken);
        } catch (Exception e) {
            LOG.error("Could not fetch or store authorities", e);
        }
    }
    return deleted;
}
Also used : SyncopeGrantedAuthority(org.apache.syncope.core.spring.security.SyncopeGrantedAuthority) AccessToken(org.apache.syncope.core.persistence.api.entity.AccessToken) AnyTypeTO(org.apache.syncope.common.lib.to.AnyTypeTO) TypeReference(com.fasterxml.jackson.core.type.TypeReference) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) HashSet(java.util.HashSet)

Example 8 with SyncopeGrantedAuthority

use of org.apache.syncope.core.spring.security.SyncopeGrantedAuthority in project syncope by apache.

the class ResourceDataBinderTest method setAuthContext.

@BeforeAll
public static void setAuthContext() {
    List<GrantedAuthority> authorities = StandardEntitlement.values().stream().map(entitlement -> new SyncopeGrantedAuthority(entitlement, SyncopeConstants.ROOT_REALM)).collect(Collectors.toList());
    UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(new org.springframework.security.core.userdetails.User("admin", "FAKE_PASSWORD", authorities), "FAKE_PASSWORD", authorities);
    auth.setDetails(new SyncopeAuthenticationDetails("Master"));
    SecurityContextHolder.getContext().setAuthentication(auth);
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) StandardEntitlement(org.apache.syncope.common.lib.types.StandardEntitlement) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) Autowired(org.springframework.beans.factory.annotation.Autowired) HashSet(java.util.HashSet) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) AfterAll(org.junit.jupiter.api.AfterAll) SyncopeGrantedAuthority(org.apache.syncope.core.spring.security.SyncopeGrantedAuthority) BeforeAll(org.junit.jupiter.api.BeforeAll) ItemTO(org.apache.syncope.common.lib.to.ItemTO) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) SyncopeConstants(org.apache.syncope.common.lib.SyncopeConstants) SyncopeAuthenticationDetails(org.apache.syncope.core.spring.security.SyncopeAuthenticationDetails) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) MappingTO(org.apache.syncope.common.lib.to.MappingTO) PlainSchemaDAO(org.apache.syncope.core.persistence.api.dao.PlainSchemaDAO) Set(java.util.Set) ResourceDataBinder(org.apache.syncope.core.provisioning.api.data.ResourceDataBinder) Collectors(java.util.stream.Collectors) AnyTypeDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeDAO) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) GrantedAuthority(org.springframework.security.core.GrantedAuthority) Test(org.junit.jupiter.api.Test) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) List(java.util.List) MappingPurpose(org.apache.syncope.common.lib.types.MappingPurpose) ObjectClass(org.identityconnectors.framework.common.objects.ObjectClass) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) ExternalResourceDAO(org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO) Transactional(org.springframework.transaction.annotation.Transactional) SyncopeGrantedAuthority(org.apache.syncope.core.spring.security.SyncopeGrantedAuthority) SyncopeGrantedAuthority(org.apache.syncope.core.spring.security.SyncopeGrantedAuthority) GrantedAuthority(org.springframework.security.core.GrantedAuthority) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) SyncopeAuthenticationDetails(org.apache.syncope.core.spring.security.SyncopeAuthenticationDetails) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

SyncopeGrantedAuthority (org.apache.syncope.core.spring.security.SyncopeGrantedAuthority)8 Transactional (org.springframework.transaction.annotation.Transactional)6 HashSet (java.util.HashSet)5 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 SyncopeConstants (org.apache.syncope.common.lib.SyncopeConstants)5 StandardEntitlement (org.apache.syncope.common.lib.types.StandardEntitlement)5 SyncopeAuthenticationDetails (org.apache.syncope.core.spring.security.SyncopeAuthenticationDetails)5 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)5 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)5 Test (org.junit.jupiter.api.Test)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)5 GrantedAuthority (org.springframework.security.core.GrantedAuthority)5 SecurityContextHolder (org.springframework.security.core.context.SecurityContextHolder)5 Set (java.util.Set)3 AnyTypeDAO (org.apache.syncope.core.persistence.api.dao.AnyTypeDAO)3 ExternalResourceDAO (org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO)3 PlainSchemaDAO (org.apache.syncope.core.persistence.api.dao.PlainSchemaDAO)3 ExternalResource (org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)3