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);
}
}
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;
}
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());
}
}
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;
}
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;
}
Aggregations