use of eu.bcvsolutions.idm.ic.exception.IcRemoteServerException in project CzechIdMng by bcvsolutions.
the class ConnIdIcConfigurationService method findRemoteConnectorManager.
private ConnectorInfoManager findRemoteConnectorManager(IcConnectorServer server) {
// get all saved remote connector servers
ConnectorInfoManager manager = null;
try {
GuardedString pass = server.getPassword();
if (pass == null) {
throw new InvalidCredentialException();
}
RemoteFrameworkConnectionInfo info = new RemoteFrameworkConnectionInfo(server.getHost(), server.getPort(), new org.identityconnectors.common.security.GuardedString(pass.asString().toCharArray()), server.isUseSsl(), null, server.getTimeout());
// flush remote cache
ConnectorInfoManagerFactory instance = ConnectorInfoManagerFactory.getInstance();
instance.clearRemoteCache();
manager = instance.getRemoteManager(info);
} catch (InvalidCredentialException e) {
throw new IcInvalidCredentialException(server.getHost(), server.getPort(), e);
} catch (ConnectorIOException e) {
throw new IcServerNotFoundException(server.getHost(), server.getPort(), e);
} catch (ConnectorException e) {
throw new IcCantConnectException(server.getHost(), server.getPort(), e);
} catch (Exception e) {
throw new IcRemoteServerException(server.getHost(), server.getPort(), e);
}
return manager;
}
use of eu.bcvsolutions.idm.ic.exception.IcRemoteServerException in project CzechIdMng by bcvsolutions.
the class SysSystemController method getAvailableRemoteConnectors.
/**
* Rest endpoints return available remote connectors.
* If entity hasn't set for remote or isn't exists return empty map of connectors
*
* @param backendId
* @return
*/
@RequestMapping(method = RequestMethod.GET, value = "{backendId}/search/remote")
@PreAuthorize("hasAuthority('" + AccGroupPermission.SYSTEM_READ + "')")
@ApiOperation(value = "Get available remote connectors", nickname = "getAvailableRemoteConnectors", tags = { SysSystemController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = AccGroupPermission.SYSTEM_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = AccGroupPermission.SYSTEM_READ, description = "") }) }, notes = "Supported remote conectors (by remote server configuration).")
public ResponseEntity<Map<String, Set<IcConnectorInfo>>> getAvailableRemoteConnectors(@ApiParam(value = "System's uuid identifier or code.", required = true) @PathVariable @NotNull String backendId) {
SysSystemDto dto = this.getDto(backendId);
Map<String, Set<IcConnectorInfo>> infos = new HashMap<>();
// if entity hasn't set up for remote return empty map
if (dto == null || !dto.isRemote()) {
return new ResponseEntity<Map<String, Set<IcConnectorInfo>>>(infos, HttpStatus.OK);
}
Assert.notNull(dto.getConnectorServer(), "Connector server is required.");
//
try {
for (IcConfigurationService config : icConfiguration.getIcConfigs().values()) {
SysConnectorServerDto server = dto.getConnectorServer();
server.setPassword(this.confidentialStorage.getGuardedString(dto.getId(), SysSystem.class, SysSystemService.REMOTE_SERVER_PASSWORD));
infos.put(config.getFramework(), config.getAvailableRemoteConnectors(server));
}
} catch (IcInvalidCredentialException e) {
throw new ResultCodeException(AccResultCode.REMOTE_SERVER_INVALID_CREDENTIAL, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e);
} catch (IcServerNotFoundException e) {
throw new ResultCodeException(AccResultCode.REMOTE_SERVER_NOT_FOUND, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e);
} catch (IcCantConnectException e) {
throw new ResultCodeException(AccResultCode.REMOTE_SERVER_CANT_CONNECT, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e);
} catch (IcRemoteServerException e) {
throw new ResultCodeException(AccResultCode.REMOTE_SERVER_UNEXPECTED_ERROR, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e);
}
//
return new ResponseEntity<Map<String, Set<IcConnectorInfo>>>(infos, HttpStatus.OK);
}
use of eu.bcvsolutions.idm.ic.exception.IcRemoteServerException in project CzechIdMng by bcvsolutions.
the class SysRemoteServerController method getConnectorFrameworks.
/**
* Return available connector frameworks with connectors on remote connector server.
*/
@RequestMapping(method = RequestMethod.GET, value = "/{backendId}/frameworks")
@PreAuthorize("hasAuthority('" + AccGroupPermission.REMOTESERVER_READ + "')")
@ApiOperation(value = "Get available connectors", nickname = "getAvailableConnectors", tags = { SysRemoteServerController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = AccGroupPermission.REMOTESERVER_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = AccGroupPermission.REMOTESERVER_READ, description = "") }) }, notes = "Available connector frameworks with connectors on remote connector server.")
public ResponseEntity<Map<String, Set<IcConnectorInfo>>> getConnectorFrameworks(@ApiParam(value = "Remote server uuid identifier or code.", required = true) @PathVariable @NotNull String backendId) {
SysConnectorServerDto connectorServer = getDto(backendId);
if (connectorServer == null) {
throw new EntityNotFoundException(getService().getEntityClass(), backendId);
}
Map<String, Set<IcConnectorInfo>> infos = new HashMap<>();
//
try {
for (IcConfigurationService config : icConfiguration.getIcConfigs().values()) {
connectorServer.setPassword(remoteServerService.getPassword(connectorServer.getId()));
infos.put(config.getFramework(), config.getAvailableRemoteConnectors(connectorServer));
}
} catch (IcInvalidCredentialException e) {
throw new ResultCodeException(AccResultCode.REMOTE_SERVER_INVALID_CREDENTIAL, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e);
} catch (IcServerNotFoundException e) {
throw new ResultCodeException(AccResultCode.REMOTE_SERVER_NOT_FOUND, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e);
} catch (IcCantConnectException e) {
throw new ResultCodeException(AccResultCode.REMOTE_SERVER_CANT_CONNECT, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e);
} catch (IcRemoteServerException e) {
throw new ResultCodeException(AccResultCode.REMOTE_SERVER_UNEXPECTED_ERROR, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e);
}
//
return new ResponseEntity<Map<String, Set<IcConnectorInfo>>>(infos, HttpStatus.OK);
}
use of eu.bcvsolutions.idm.ic.exception.IcRemoteServerException in project CzechIdMng by bcvsolutions.
the class SysRemoteServerController method getConnectorTypes.
/**
* Returns connector types registered on given remote server.
*
* @return connector types
*/
@ResponseBody
@RequestMapping(method = RequestMethod.GET, value = "/{backendId}/connector-types")
@PreAuthorize("hasAuthority('" + AccGroupPermission.REMOTESERVER_READ + "')")
@ApiOperation(value = "Get supported connector types", nickname = "getConnectorTypes", tags = { SysRemoteServerController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = AccGroupPermission.REMOTESERVER_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = AccGroupPermission.REMOTESERVER_READ, description = "") }) })
public Resources<ConnectorTypeDto> getConnectorTypes(@ApiParam(value = "Remote server uuid identifier or code.", required = true) @PathVariable @NotNull String backendId) {
SysConnectorServerDto connectorServer = getDto(backendId);
if (connectorServer == null) {
throw new EntityNotFoundException(getService().getEntityClass(), backendId);
}
//
try {
List<IcConnectorInfo> connectorInfos = Lists.newArrayList();
for (IcConfigurationService config : icConfiguration.getIcConfigs().values()) {
connectorServer.setPassword(remoteServerService.getPassword(connectorServer.getId()));
Set<IcConnectorInfo> availableRemoteConnectors = config.getAvailableRemoteConnectors(connectorServer);
if (CollectionUtils.isNotEmpty(availableRemoteConnectors)) {
connectorInfos.addAll(availableRemoteConnectors);
}
}
// Find connector types for existing connectors.
List<ConnectorTypeDto> connectorTypes = connectorManager.getSupportedTypes().stream().filter(connectorType -> {
return connectorInfos.stream().anyMatch(connectorInfo -> connectorType.getConnectorName().equals(connectorInfo.getConnectorKey().getConnectorName()));
}).map(connectorType -> {
// Find connector info and set version to the connectorTypeDto.
IcConnectorInfo info = connectorInfos.stream().filter(connectorInfo -> connectorType.getConnectorName().equals(connectorInfo.getConnectorKey().getConnectorName())).findFirst().orElse(null);
ConnectorTypeDto connectorTypeDto = connectorManager.convertTypeToDto(connectorType);
connectorTypeDto.setLocal(true);
if (info != null) {
connectorTypeDto.setVersion(info.getConnectorKey().getBundleVersion());
connectorTypeDto.setName(info.getConnectorDisplayName());
}
return connectorTypeDto;
}).collect(Collectors.toList());
// Find connectors without extension (specific connector type).
List<ConnectorTypeDto> defaultConnectorTypes = connectorInfos.stream().map(info -> {
ConnectorTypeDto connectorTypeDto = connectorManager.convertIcConnectorInfoToDto(info);
connectorTypeDto.setLocal(true);
return connectorTypeDto;
}).filter(type -> {
return !connectorTypes.stream().anyMatch(supportedType -> supportedType.getConnectorName().equals(type.getConnectorName()) && supportedType.isHideParentConnector());
}).collect(Collectors.toList());
connectorTypes.addAll(defaultConnectorTypes);
return new Resources<>(connectorTypes.stream().sorted(Comparator.comparing(ConnectorTypeDto::getOrder)).collect(Collectors.toList()));
} catch (IcInvalidCredentialException e) {
throw new ResultCodeException(AccResultCode.REMOTE_SERVER_INVALID_CREDENTIAL, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e);
} catch (IcServerNotFoundException e) {
throw new ResultCodeException(AccResultCode.REMOTE_SERVER_NOT_FOUND, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e);
} catch (IcCantConnectException e) {
throw new ResultCodeException(AccResultCode.REMOTE_SERVER_CANT_CONNECT, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e);
} catch (IcRemoteServerException e) {
throw new ResultCodeException(AccResultCode.REMOTE_SERVER_UNEXPECTED_ERROR, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e);
}
}
use of eu.bcvsolutions.idm.ic.exception.IcRemoteServerException in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemService method resolveConnectorFormDefinition.
/**
* Create form definition to given connectorInstance by connector properties
*
* @param formDefinition
* @param connectorInstance
* @return
*/
private synchronized IdmFormDefinitionDto resolveConnectorFormDefinition(IdmFormDefinitionDto formDefinition, IcConnectorInstance connectorInstance) {
IcConnectorConfiguration conf = null;
try {
conf = icConfigurationFacade.getConnectorConfiguration(connectorInstance);
} catch (IcRemoteServerException ex) {
if (formDefinition != null) {
LOG.info("Connector definition cannot be updated, because connector returns remote-server exception." + " Exists definition will be used.", ex);
return formDefinition;
}
throw ex;
}
if (conf == null) {
throw new IllegalStateException(MessageFormat.format("Connector with key [{0}] was not found on classpath.", connectorInstance.getConnectorKey().getFullName()));
}
//
List<IcConfigurationProperty> properties = conf.getConfigurationProperties().getProperties();
List<IdmFormAttributeDto> formAttributes = new ArrayList<>(properties.size());
//
if (formDefinition == null) {
// create new form definition
for (short seq = 0; seq < properties.size(); seq++) {
IcConfigurationProperty property = properties.get(seq);
IdmFormAttributeDto attribute = formPropertyManager.toFormAttribute(property);
attribute.setSeq(seq);
formAttributes.add(attribute);
}
formDefinition = getFormService().createDefinition(SysSystem.class, connectorInstance.getConnectorKey().getFullName(), formAttributes);
} else {
// update attribute is not supported now
for (short seq = 0; seq < properties.size(); seq++) {
IcConfigurationProperty property = properties.get(seq);
IdmFormAttributeDto formAttribute = formDefinition.getMappedAttributeByCode(property.getName());
if (formAttribute == null) {
LOG.info("Connector attribute [{}] not found in definition, attributte will be added into definition with code [{}].", property.getName(), formDefinition.getCode());
//
formAttribute = formPropertyManager.toFormAttribute(property);
formAttribute.setFormDefinition(formDefinition.getId());
formAttribute.setSeq(seq);
formAttribute = getFormService().saveAttribute(formAttribute);
formDefinition.addFormAttribute(formAttribute);
}
}
}
//
return formDefinition;
}
Aggregations