Search in sources :

Example 21 with CoreException

use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.

the class JwtAuthenticationMapper method writeToken.

/**
 * Writes authentication dto to token
 *
 * @param dto
 * @return
 * @throws IOException
 */
public String writeToken(IdmJwtAuthenticationDto dto) {
    try {
        Assert.notNull(dto, "Authentication is required to write token");
        // 
        String authenticationJson = mapper.writeValueAsString(dto);
        return JwtHelper.encode(authenticationJson, new MacSigner(getSecret().asString())).getEncoded();
    } catch (IOException ex) {
        throw new CoreException(String.format("Creating JWT token [%s] failed.", dto.getId()), ex);
    }
}
Also used : MacSigner(org.springframework.security.jwt.crypto.sign.MacSigner) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IOException(java.io.IOException)

Example 22 with CoreException

use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.

the class DefaultVsSystemService method createAttributeMapping.

/**
 * Creates attribute mapping for synchronization mapping
 *
 * @author Marek Klement
 *
 * @param foundMapping
 *            created mapping for sync
 * @param schemaId
 *            uuid of schema
 * @return new attribute mapping
 */
private SysSystemAttributeMappingDto createAttributeMapping(UUID foundMapping, UUID schemaId) {
    SysSchemaAttributeFilter filter = new SysSchemaAttributeFilter();
    filter.setObjectClassId(schemaId);
    List<SysSchemaAttributeDto> schemaAttributes = schemaAttributeService.find(filter, null).getContent();
    UUID idOfSchemaAttributeName = null;
    for (SysSchemaAttributeDto attribute : schemaAttributes) {
        if (attribute.getName().equals(Name.NAME)) {
            idOfSchemaAttributeName = attribute.getId();
            break;
        }
    }
    // 
    SysSystemAttributeMappingDto attributeMapping = systemAttributeMappingService.findBySystemMappingAndName(foundMapping, IDM_ATTRIBUTE_NAME);
    // 
    if (attributeMapping == null) {
        attributeMapping = new SysSystemAttributeMappingDto();
        attributeMapping.setEntityAttribute(true);
        Assert.notNull(idOfSchemaAttributeName, "Attribute uid name not found!");
        attributeMapping.setSchemaAttribute(idOfSchemaAttributeName);
        attributeMapping.setIdmPropertyName(IDM_ATTRIBUTE_NAME);
        attributeMapping.setSystemMapping(foundMapping);
        attributeMapping.setName(IDM_ATTRIBUTE_NAME);
        attributeMapping.setUid(true);
        attributeMapping = systemAttributeMappingService.save(attributeMapping);
    } else if (!attributeMapping.isUid()) {
        throw new CoreException("Attribute mapping with name was already set and is not IDENTIFIER!");
    }
    return attributeMapping;
}
Also used : CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSchemaAttributeFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter) UUID(java.util.UUID)

Example 23 with CoreException

use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.

the class DefaultAutomaticRoleManager method deleteAutomaticRole.

@Override
public void deleteAutomaticRole(AbstractIdmAutomaticRoleDto automaticRole, boolean executeImmediately) {
    Assert.notNull(automaticRole, "Automatic role is required.");
    Assert.notNull(automaticRole.getId(), "Automatic role must exists!");
    IdmAutomaticRoleRequestDto request = new IdmAutomaticRoleRequestDto();
    if (automaticRole instanceof IdmRoleTreeNodeDto) {
        request.setRequestType(AutomaticRoleRequestType.TREE);
        request.setTreeNode(((IdmRoleTreeNodeDto) automaticRole).getTreeNode());
    } else {
        request.setRequestType(AutomaticRoleRequestType.ATTRIBUTE);
    }
    request.setOperation(RequestOperationType.REMOVE);
    request.setExecuteImmediately(executeImmediately);
    request.setAutomaticRole(automaticRole.getId());
    request.setName(automaticRole.getName());
    request.setRole(automaticRole.getRole());
    request = roleRequestService.save(request);
    request = roleRequestService.startRequestInternal(request.getId(), true);
    if (RequestState.EXECUTED == request.getState()) {
        return;
    }
    if (RequestState.IN_PROGRESS == request.getState()) {
        throw new AcceptedException(request.getId().toString());
    }
    if (RequestState.EXCEPTION == request.getState()) {
        throw new CoreException(request.getResult().getCause());
    }
}
Also used : IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) IdmAutomaticRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException)

Example 24 with CoreException

use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.

the class DefaultAutomaticRoleManager method createAutomaticRoleByTree.

@Override
public IdmRoleTreeNodeDto createAutomaticRoleByTree(IdmRoleTreeNodeDto automaticRole, boolean executeImmediately) {
    IdmAutomaticRoleRequestDto request = new IdmAutomaticRoleRequestDto();
    request.setOperation(RequestOperationType.ADD);
    request.setRequestType(AutomaticRoleRequestType.TREE);
    request.setExecuteImmediately(executeImmediately);
    request.setName(automaticRole.getName());
    request.setRole(automaticRole.getRole());
    request.setTreeNode(automaticRole.getTreeNode());
    request.setRecursionType(automaticRole.getRecursionType());
    request = roleRequestService.save(request);
    request = roleRequestService.startRequestInternal(request.getId(), true);
    if (RequestState.EXECUTED == request.getState()) {
        UUID createdAutomaticRoleId = request.getAutomaticRole();
        Assert.notNull(createdAutomaticRoleId, "Automatic role identifier is required.");
        return roleTreeNodeService.get(request.getAutomaticRole());
    }
    if (RequestState.IN_PROGRESS == request.getState()) {
        throw new AcceptedException(request.getId().toString());
    }
    if (RequestState.EXCEPTION == request.getState()) {
        throw new CoreException(request.getResult().getCause());
    }
    return null;
}
Also used : CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) IdmAutomaticRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) UUID(java.util.UUID)

Example 25 with CoreException

use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.

the class DefaultAutomaticRoleManager method createAutomaticRoleByAttribute.

@Override
public IdmAutomaticRoleAttributeDto createAutomaticRoleByAttribute(IdmAutomaticRoleAttributeDto automaticRole, boolean executeImmediately, IdmAutomaticRoleAttributeRuleDto... rules) {
    IdmAutomaticRoleRequestDto request = new IdmAutomaticRoleRequestDto();
    request.setOperation(RequestOperationType.ADD);
    request.setRequestType(AutomaticRoleRequestType.ATTRIBUTE);
    request.setExecuteImmediately(executeImmediately);
    request.setName(automaticRole.getName());
    request.setRole(automaticRole.getRole());
    request = roleRequestService.save(request);
    if (rules != null) {
        for (IdmAutomaticRoleAttributeRuleDto rule : rules) {
            IdmAutomaticRoleAttributeRuleRequestDto ruleRequest = new IdmAutomaticRoleAttributeRuleRequestDto();
            ruleRequest.setRequest(request.getId());
            ruleRequest.setOperation(RequestOperationType.ADD);
            ruleRequest.setAttributeName(rule.getAttributeName());
            ruleRequest.setComparison(rule.getComparison());
            ruleRequest.setType(rule.getType());
            ruleRequest.setFormAttribute(rule.getFormAttribute());
            ruleRequest.setValue(rule.getValue());
            ruleRequest.setRule(rule.getId());
            ruleRequest = ruleRequestService.save(ruleRequest);
        }
    }
    request = roleRequestService.startRequestInternal(request.getId(), true);
    if (RequestState.EXECUTED == request.getState()) {
        UUID createdAutomaticRoleId = request.getAutomaticRole();
        Assert.notNull(createdAutomaticRoleId, "Automatic role identifier is required.");
        return automaticRoleAttributeService.get(request.getAutomaticRole());
    }
    if (RequestState.IN_PROGRESS == request.getState()) {
        throw new AcceptedException(request.getId().toString());
    }
    if (RequestState.EXCEPTION == request.getState()) {
        throw new CoreException(request.getResult().getCause());
    }
    return null;
}
Also used : IdmAutomaticRoleAttributeRuleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleRequestDto) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) IdmAutomaticRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) UUID(java.util.UUID)

Aggregations

CoreException (eu.bcvsolutions.idm.core.api.exception.CoreException)64 UUID (java.util.UUID)16 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)15 Test (org.junit.Test)14 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)13 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)11 AcceptedException (eu.bcvsolutions.idm.core.api.exception.AcceptedException)10 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)9 Field (java.lang.reflect.Field)9 Embedded (eu.bcvsolutions.idm.core.api.domain.Embedded)8 AbstractDto (eu.bcvsolutions.idm.core.api.dto.AbstractDto)8 BaseEntity (eu.bcvsolutions.idm.core.api.entity.BaseEntity)8 List (java.util.List)8 Requestable (eu.bcvsolutions.idm.core.api.domain.Requestable)7 BaseDto (eu.bcvsolutions.idm.core.api.dto.BaseDto)7 IdmRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestDto)7 IdmLongRunningTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto)7 RequestOperationType (eu.bcvsolutions.idm.core.api.domain.RequestOperationType)6 IntrospectionException (java.beans.IntrospectionException)6