Search in sources :

Example 1 with IdmScriptServiceType

use of eu.bcvsolutions.idm.core.model.jaxb.IdmScriptServiceType in project CzechIdMng by bcvsolutions.

the class DefaultIdmScriptService method authorityTypeToDto.

/**
 * Generate list of authorities from {@ IdmScriptType}
 *
 * @param type
 * @return
 */
private List<IdmScriptAuthorityDto> authorityTypeToDto(IdmScriptType type, IdmScriptDto scriptDto) {
    List<IdmScriptAuthorityDto> authorities = new ArrayList<>();
    if (type.getAllowClasses() != null && type.getAllowClasses().getAllowClasses() != null) {
        for (IdmScriptAllowClassType allowClass : type.getAllowClasses().getAllowClasses()) {
            try {
                Class.forName(allowClass.getClassName());
            } catch (ClassNotFoundException e) {
                LOG.error("Class [{}] isn't reachable, for script [{}] skip add this authority", allowClass.getClassName(), type.getCode(), e);
                continue;
            }
            IdmScriptAuthorityDto authDto = new IdmScriptAuthorityDto();
            authDto.setType(ScriptAuthorityType.CLASS_NAME);
            authDto.setClassName(allowClass.getClassName());
            authDto.setScript(scriptDto.getId());
            authorities.add(authDto);
        }
    }
    // 
    if (type.getServices() != null && type.getServices().getServices() != null) {
        for (IdmScriptServiceType service : type.getServices().getServices()) {
            if (scriptAuthorityService.isServiceReachable(service.getName(), service.getClassName())) {
                IdmScriptAuthorityDto authDto = new IdmScriptAuthorityDto();
                authDto.setType(ScriptAuthorityType.SERVICE);
                authDto.setClassName(service.getClassName());
                authDto.setService(service.getName());
                authDto.setScript(scriptDto.getId());
                authorities.add(authDto);
            } else {
                LOG.error("Service [{}] [{}] isn't reachable, for script [{}] skip add this authority", service.getName(), service.getClassName(), type.getCode());
                continue;
            }
        }
    }
    // 
    return authorities;
}
Also used : IdmScriptAllowClassType(eu.bcvsolutions.idm.core.model.jaxb.IdmScriptAllowClassType) IdmScriptAuthorityDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptAuthorityDto) IdmScriptServiceType(eu.bcvsolutions.idm.core.model.jaxb.IdmScriptServiceType) ArrayList(java.util.ArrayList)

Example 2 with IdmScriptServiceType

use of eu.bcvsolutions.idm.core.model.jaxb.IdmScriptServiceType in project CzechIdMng by bcvsolutions.

the class DefaultIdmScriptService method dtoToType.

/**
 * Transform dto to type.
 *
 * @param dto
 * @return
 */
private IdmScriptType dtoToType(IdmScriptDto dto, List<IdmScriptAuthorityDto> authorities) {
    IdmScriptType type = new IdmScriptType();
    if (dto == null) {
        return type;
    }
    // transform DTO to type
    type.setCode(dto.getCode());
    type.setName(dto.getName());
    // parameter isn't implemented yet
    // type.setParameters(dto.getParameter());
    type.setBody(dto.getScript());
    type.setCategory(dto.getCategory());
    type.setDescription(dto.getDescription());
    type.setType(SCRIPT_DEFAULT_TYPE);
    // 
    if (authorities != null && !authorities.isEmpty()) {
        List<IdmScriptAllowClassType> classes = new ArrayList<>();
        List<IdmScriptServiceType> services = new ArrayList<>();
        for (IdmScriptAuthorityDto auth : authorities) {
            if (auth.getType() == ScriptAuthorityType.CLASS_NAME) {
                IdmScriptAllowClassType classType = new IdmScriptAllowClassType();
                classType.setClassName(auth.getClassName());
                classes.add(classType);
            } else {
                IdmScriptServiceType service = new IdmScriptServiceType();
                service.setClassName(auth.getClassName());
                service.setName(auth.getService());
                services.add(service);
            }
        }
        if (!classes.isEmpty()) {
            type.setAllowClasses(new IdmScriptAllowClassesType());
            type.getAllowClasses().setAllowClasses(classes);
        }
        if (!services.isEmpty()) {
            type.setServices(new IdmScriptServicesType());
            type.getServices().setServices(services);
        }
    }
    return type;
}
Also used : IdmScriptType(eu.bcvsolutions.idm.core.model.jaxb.IdmScriptType) IdmScriptServicesType(eu.bcvsolutions.idm.core.model.jaxb.IdmScriptServicesType) IdmScriptAllowClassType(eu.bcvsolutions.idm.core.model.jaxb.IdmScriptAllowClassType) IdmScriptServiceType(eu.bcvsolutions.idm.core.model.jaxb.IdmScriptServiceType) IdmScriptAuthorityDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptAuthorityDto) ArrayList(java.util.ArrayList) IdmScriptAllowClassesType(eu.bcvsolutions.idm.core.model.jaxb.IdmScriptAllowClassesType)

Aggregations

IdmScriptAuthorityDto (eu.bcvsolutions.idm.core.api.dto.IdmScriptAuthorityDto)2 IdmScriptAllowClassType (eu.bcvsolutions.idm.core.model.jaxb.IdmScriptAllowClassType)2 IdmScriptServiceType (eu.bcvsolutions.idm.core.model.jaxb.IdmScriptServiceType)2 ArrayList (java.util.ArrayList)2 IdmScriptAllowClassesType (eu.bcvsolutions.idm.core.model.jaxb.IdmScriptAllowClassesType)1 IdmScriptServicesType (eu.bcvsolutions.idm.core.model.jaxb.IdmScriptServicesType)1 IdmScriptType (eu.bcvsolutions.idm.core.model.jaxb.IdmScriptType)1