@PreAuthorize("hasRole('" + StandardEntitlement.CONNECTOR_DELETE + "')") public ConnInstanceTO delete(final String key) { ConnInstance connInstance = connInstanceDAO.authFind(key); if (connInstance == null) { throw new NotFoundException("Connector '" + key + "'"); } Set<String> effectiveRealms = RealmUtils.getEffective( AuthContextUtils.getAuthorizations().get(StandardEntitlement.CONNECTOR_DELETE), connInstance.getAdminRealm().getFullPath()); securityChecks(effectiveRealms, connInstance.getAdminRealm().getFullPath(), connInstance.getKey()); if (!connInstance.getResources().isEmpty()) { SyncopeClientException associatedResources = SyncopeClientException.build( ClientExceptionType.AssociatedResources); connInstance.getResources().forEach(resource -> { associatedResources.getElements().add(resource.getKey()); }); throw associatedResources; } ConnInstanceTO deleted = binder.getConnInstanceTO(connInstance); connInstanceDAO.delete(key); return deleted; }
@Override public Pair<URI, ConnectorInfo> getConnectorInfo(final ConnInstance connInstance) { // check ConnIdLocation URI uriLocation = null; try { uriLocation = URIUtils.buildForConnId(connInstance.getLocation()); } catch (Exception e) { throw new IllegalArgumentException("Invalid ConnId location " + connInstance.getLocation(), e); } // create key for search all properties ConnectorKey key = new ConnectorKey( connInstance.getBundleName(), connInstance.getVersion(), connInstance.getConnectorName()); if (LOG.isDebugEnabled()) { LOG.debug("\nBundle name: " + key.getBundleName() + "\nBundle version: " + key.getBundleVersion() + "\nBundle class: " + key.getConnectorName()); } // get the specified connector ConnectorInfo info = null; if (getConnManagers().containsKey(uriLocation)) { info = getConnManagers().get(uriLocation).findConnectorInfo(key); } if (info == null) { throw new NotFoundException("ConnectorInfo for location " + connInstance.getLocation() + " and key " + key); } return Pair.of(uriLocation, info); }
@PreAuthorize("hasRole('" + StandardEntitlement.CONNECTOR_LIST + "')") @Transactional(readOnly = true) public List<ConnInstanceTO> list(final String lang) { CurrentLocale.set(StringUtils.isBlank(lang) ? Locale.ENGLISH : new Locale(lang)); return connInstanceDAO.findAll().stream(). filter(connInstance -> connInstance != null). map(connInstance -> { ConnInstanceTO result = null; try { result = binder.getConnInstanceTO(connInstance); } catch (NotFoundException e) { LOG.error("Connector '{}#{}' not found", connInstance.getBundleName(), connInstance.getVersion()); } return result; }).collect(Collectors.toList()); }
@Override public ConnInstance authFind(final String key) { ConnInstance connInstance = find(key); if (connInstance == null) { return null; } Set<String> authRealms = AuthContextUtils.getAuthorizations().get(StandardEntitlement.CONNECTOR_READ); if (authRealms == null || authRealms.isEmpty() || !authRealms.stream().anyMatch( realm -> connInstance.getAdminRealm().getFullPath().startsWith(realm))) { throw new DelegatedAdministrationException( connInstance.getAdminRealm().getFullPath(), ConnInstance.class.getSimpleName(), connInstance.getKey()); } return connInstance; }
connInstanceTO.setKey(connInstance.getKey()); connInstanceTO.setBundleName(connInstance.getBundleName()); connInstanceTO.setConnectorName(connInstance.getConnectorName()); connInstanceTO.setVersion(connInstance.getVersion()); connInstanceTO.setDisplayName(connInstance.getDisplayName()); connInstanceTO.setConnRequestTimeout(connInstance.getConnRequestTimeout()); connInstanceTO.setAdminRealm(connInstance.getAdminRealm().getFullPath()); connInstanceTO.setLocation(info.getLeft().toASCIIString()); connInstanceTO.getCapabilities().addAll(connInstance.getCapabilities()); connInstanceTO.getConf().addAll(connInstance.getConf()); if (connInstance.getPoolConf() != null && (connInstance.getPoolConf().getMaxIdle() != null || connInstance.getPoolConf().getMaxObjects() != null || connInstance.getPoolConf().getMaxWait() != null || connInstance.getPoolConf().getMinEvictableIdleTimeMillis() != null || connInstance.getPoolConf().getMinIdle() != null)) { poolConf.setMaxIdle(connInstance.getPoolConf().getMaxIdle()); poolConf.setMaxObjects(connInstance.getPoolConf().getMaxObjects()); poolConf.setMaxWait(connInstance.getPoolConf().getMaxWait()); poolConf.setMinEvictableIdleTimeMillis(connInstance.getPoolConf().getMinEvictableIdleTimeMillis()); poolConf.setMinIdle(connInstance.getPoolConf().getMinIdle()); connInstanceTO.setPoolConf(poolConf);
connInstance.setBundleName(connInstanceTO.getBundleName()); connInstance.setConnectorName(connInstanceTO.getConnectorName()); connInstance.setVersion(connInstanceTO.getVersion()); connInstance.setDisplayName(connInstanceTO.getDisplayName()); connInstance.setConnRequestTimeout(connInstanceTO.getConnRequestTimeout()); connInstance.getCapabilities().addAll(connInstanceTO.getCapabilities()); connInstance.setAdminRealm(realmDAO.findByFullPath(connInstanceTO.getAdminRealm())); if (connInstance.getAdminRealm() == null) { sce.getElements().add("Invalid or null realm specified: " + connInstanceTO.getAdminRealm()); connInstance.setLocation(connInstanceTO.getLocation()); connInstance.setConf(connInstanceTO.getConf()); if (connInstanceTO.getPoolConf() != null) { connInstance.setPoolConf( ConnPoolConfUtils.getConnPoolConf(connInstanceTO.getPoolConf(), entityFactory.newConnPoolConf()));
@Override public List<ConnInstance> findAll() { final Set<String> authRealms = AuthContextUtils.getAuthorizations().get(StandardEntitlement.CONNECTOR_LIST); if (authRealms == null || authRealms.isEmpty()) { return Collections.emptyList(); } TypedQuery<ConnInstance> query = entityManager().createQuery( "SELECT e FROM " + JPAConnInstance.class.getSimpleName() + " e", ConnInstance.class); return query.getResultList().stream().filter(connInstance -> authRealms.stream(). anyMatch(realm -> connInstance.getAdminRealm().getFullPath().startsWith(realm))). collect(Collectors.toList()); }
if (isHtml(connInstance.getDisplayName())) { context.buildConstraintViolationWithTemplate( getTemplate(EntityViolationType.InvalidName, "Invalid display name")). URIUtils.buildForConnId(connInstance.getLocation()); } catch (Exception e) { LOG.error("While validating {}", connInstance.getLocation(), e); if (isValid && connInstance.getPoolConf() != null) { try { ConnPoolConfUtils.getObjectPoolConfiguration(connInstance.getPoolConf()).validate(); } catch (Exception e) { LOG.error("Invalid pool configuration", e);
if (connInstance.getDisplayName() != null) { apiConfig.setInstanceName(connInstance.getDisplayName()); connInstance.getConf().stream(). filter(property -> (property.getValues() != null && !property.getValues().isEmpty())). forEachOrdered(property -> { if (connInstance.getPoolConf() != null) { if (apiConfig.isConnectorPoolingSupported()) { ConnPoolConfUtils.updateObjectPoolConfiguration( apiConfig.getConnectorPoolConfiguration(), connInstance.getPoolConf()); } else { LOG.warn("Connector pooling not supported for {}", info);
resourceTO.setConnector(connector == null ? null : connector.getKey()); resourceTO.setConnectorDisplayName(connector == null ? null : connector.getDisplayName());
@Override public ConnInstance save(final ConnInstance connector) { final ConnInstance merged = entityManager().merge(connector); merged.getResources().forEach(resource -> { try { connRegistry.registerConnector(resource); } catch (NotFoundException e) { LOG.error("While registering connector for resource", e); } }); return merged; }
resource.setConnector(connector); if (!connector.getResources().contains(resource)) { connector.add(resource);
private String getBeanName(final ExternalResource resource) { return String.format("connInstance-%s-%S-%s", AuthContextUtils.getDomain(), resource.getConnector().getKey(), resource.getKey()); }
@Override public List<ExternalResource> findAll() { final Set<String> authRealms = AuthContextUtils.getAuthorizations().get(StandardEntitlement.RESOURCE_LIST); if (authRealms == null || authRealms.isEmpty()) { return Collections.emptyList(); } TypedQuery<ExternalResource> query = entityManager().createQuery( "SELECT e FROM " + JPAExternalResource.class.getSimpleName() + " e", ExternalResource.class); return query.getResultList().stream().filter(resource -> authRealms.stream(). anyMatch(realm -> resource.getConnector() != null && resource.getConnector().getAdminRealm().getFullPath().startsWith(realm))). collect(Collectors.toList()); }
@Override public void delete(final String key) { ConnInstance connInstance = find(key); if (connInstance == null) { return; } connInstance.getResources().stream(). map(Entity::getKey).collect(Collectors.toList()). forEach(resource -> resourceDAO.delete(resource)); connInstanceHistoryConfDAO.deleteByEntity(connInstance); entityManager().remove(connInstance); connRegistry.unregisterConnector(key); } }
@PreAuthorize("hasRole('" + StandardEntitlement.CONNECTOR_READ + "')") @Transactional(readOnly = true) public ConnInstanceTO readByResource(final String resourceName, final String lang) { CurrentLocale.set(StringUtils.isBlank(lang) ? Locale.ENGLISH : new Locale(lang)); ExternalResource resource = resourceDAO.find(resourceName); if (resource == null) { throw new NotFoundException("Resource '" + resourceName + "'"); } ConnInstanceTO connInstance = binder.getConnInstanceTO(connFactory.getConnector(resource).getConnInstance()); connInstance.setKey(resource.getConnector().getKey()); return connInstance; }
@Override public ExternalResource authFind(final String key) { ExternalResource resource = find(key); if (resource == null) { return null; } Set<String> authRealms = AuthContextUtils.getAuthorizations().get(StandardEntitlement.RESOURCE_READ); if (authRealms == null || authRealms.isEmpty() || !authRealms.stream().anyMatch(realm -> resource.getConnector() != null && resource.getConnector().getAdminRealm().getFullPath().startsWith(realm))) { throw new DelegatedAdministrationException( resource.getConnector().getAdminRealm().getFullPath(), ExternalResource.class.getSimpleName(), resource.getKey()); } return resource; }
if (resource.getConnector() != null && resource.getConnector().getResources() != null && !resource.getConnector().getResources().isEmpty()) { resource.getConnector().getResources().remove(resource);
@PreAuthorize("hasRole('" + StandardEntitlement.RESOURCE_DELETE + "')") public ResourceTO delete(final String key) { ExternalResource resource = resourceDAO.authFind(key); if (resource == null) { throw new NotFoundException("Resource '" + key + "'"); } Set<String> effectiveRealms = RealmUtils.getEffective( AuthContextUtils.getAuthorizations().get(StandardEntitlement.RESOURCE_DELETE), resource.getConnector().getAdminRealm().getFullPath()); securityChecks(effectiveRealms, resource.getConnector().getAdminRealm().getFullPath(), resource.getKey()); ResourceTO resourceToDelete = binder.getResourceTO(resource); resourceDAO.delete(key); return resourceToDelete; }
@PreAuthorize("hasRole('" + StandardEntitlement.RESOURCE_UPDATE + "')") public ResourceTO update(final ResourceTO resourceTO) { ExternalResource resource = resourceDAO.authFind(resourceTO.getKey()); if (resource == null) { throw new NotFoundException("Resource '" + resourceTO.getKey() + "'"); } Set<String> effectiveRealms = RealmUtils.getEffective( AuthContextUtils.getAuthorizations().get(StandardEntitlement.RESOURCE_UPDATE), resource.getConnector().getAdminRealm().getFullPath()); securityChecks(effectiveRealms, resource.getConnector().getAdminRealm().getFullPath(), resource.getKey()); return binder.getResourceTO(resourceDAO.save(binder.update(resource, resourceTO))); }