private String getBeanName(final ExternalResource resource) { return String.format("connInstance-%s-%S-%s", AuthContextUtils.getDomain(), resource.getConnector().getKey(), resource.getKey()); }
@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; }
@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; }
@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; }
connInstanceTO.setKey(connInstance.getKey()); connInstanceTO.setBundleName(connInstance.getBundleName()); connInstanceTO.setConnectorName(connInstance.getConnectorName());
resourceTO.setConnector(connector == null ? null : connector.getKey()); resourceTO.setConnectorDisplayName(connector == null ? null : connector.getDisplayName());