@Override public <E extends TenantAwareBaseEntity> E findEntity(final String tenant, final Long id, final Class<E> entityType) { return tenantAware.runAsTenant(tenant, () -> entityManager.find(entityType, id)); }
@Override public Object generate(final Object target, final Method method, final Object... params) { return tenantAware.getCurrentTenant().toUpperCase(); }
@Override public <T> T runAsTenant(final String tenant, final TenantRunner<T> callable) { final SecurityContext originalContext = SecurityContextHolder.getContext(); try { SecurityContextHolder.setContext(buildSecurityContext(tenant)); return callable.run(); } finally { SecurityContextHolder.setContext(originalContext); } }
@Override public Object generate(final Object target, final Method method, final Object... params) { return tenantAware.getCurrentTenant().toUpperCase(); }
@Override public <E extends TenantAwareBaseEntity> E findEntity(final String tenant, final Long id, final Class<E> entityType) { return tenantAware.runAsTenant(tenant, () -> entityManager.find(entityType, id)); }
@Override public TenantMetaData getTenantMetadata() { if (tenantAware.getCurrentTenant() == null) { throw new IllegalStateException("Tenant not set"); } return getTenantMetadata(tenantAware.getCurrentTenant()); }
@Override public boolean isEnable(final DmfTenantSecurityToken secruityToken) { return tenantAware.runAsTenant(secruityToken.getTenant(), configurationKeyTenantRunner); }
@Override public TenantMetaData getTenantMetadata() { if (tenantAware.getCurrentTenant() == null) { throw new IllegalStateException("Tenant not set"); } return getTenantMetadata(tenantAware.getCurrentTenant()); }
@Override public HeaderAuthentication getPreAuthenticatedCredentials(final DmfTenantSecurityToken secruityToken) { final String gatewayToken = tenantAware.runAsTenant(secruityToken.getTenant(), gatewaySecurityTokenKeyConfigRunner); return new HeaderAuthentication(secruityToken.getControllerId(), gatewayToken); }
/** * @return * @see org.springframework.cache.Cache#getName() */ @Override public String getName() { return tenantAware.getCurrentTenant() + "." + delegate.getName(); }
@Override public Optional<AbstractDbArtifact> loadArtifactBinary(final String sha1Hash) { return Optional.ofNullable(artifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), sha1Hash)); }
@Override public Optional<AbstractDbArtifact> loadArtifactBinary(final String sha1Hash) { return Optional.ofNullable(artifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), sha1Hash)); }
/** * Runs a given {@link Callable} within a system security context, which is * permitted to call secured system code. Often the system needs to call * secured methods by it's own without relying on the current security * context e.g. if the current security context does not contain the * necessary permission it's necessary to execute code as system code to * execute necessary methods and functionality. * * The security context will be switched to the system code and back after * the callable is called. * * The system code is executed for a current tenant by using the * {@link TenantAware#getCurrentTenant()}. * * @param callable * the callable to call within the system security context * @return the return value of the {@link Callable#call()} method. */ // Exception squid:S2221 - Callable declares Exception @SuppressWarnings("squid:S2221") public <T> T runAsSystem(final Callable<T> callable) { return runAsSystemAsTenant(callable, tenantAware.getCurrentTenant()); }
@Override // Exception squid:S923 - override @SuppressWarnings({ "squid:S923" }) public Object generate(final Object target, final Method method, final Object... params) { final String initialTenantCreation = createInitialTenant.get(); if (initialTenantCreation == null) { return SimpleKeyGenerator.generateKey(tenantAware.getCurrentTenant().toUpperCase(), tenantAware.getCurrentTenant().toUpperCase()); } return SimpleKeyGenerator.generateKey(initialTenantCreation.toUpperCase(), initialTenantCreation.toUpperCase()); } }
@Override // Exception squid:S923 - override @SuppressWarnings({ "squid:S923" }) public Object generate(final Object target, final Method method, final Object... params) { final String initialTenantCreation = createInitialTenant.get(); if (initialTenantCreation == null) { return SimpleKeyGenerator.generateKey(tenantAware.getCurrentTenant().toUpperCase(), tenantAware.getCurrentTenant().toUpperCase()); } return SimpleKeyGenerator.generateKey(initialTenantCreation.toUpperCase(), initialTenantCreation.toUpperCase()); } }
@Override protected Collection<String> getCacheNames(final CacheOperationInvocationContext<?> context) { return super.getCacheNames(context).stream() .map(cacheName -> tenantAware.getCurrentTenant() + "." + cacheName).collect(Collectors.toList()); } }
@Override public Collection<String> getCacheNames() { String currentTenant = tenantAware.getCurrentTenant(); if (isTenantInvalid(currentTenant)) { return Collections.emptyList(); } currentTenant = currentTenant.toUpperCase(); return getCacheNames(currentTenant); }
@Override public Collection<String> getCacheNames() { String currentTenant = tenantAware.getCurrentTenant(); if (isTenantInvalid(currentTenant)) { return Collections.emptyList(); } currentTenant = currentTenant.toUpperCase(); return getCacheNames(currentTenant); }
@Override public Cache getCache(final String name) { String currentTenant = tenantAware.getCurrentTenant(); if (isTenantInvalid(currentTenant)) { return null; } currentTenant = currentTenant.toUpperCase(); return delegate.getCache(buildKey(currentTenant, name)); }
@Override public Cache getCache(final String name) { String currentTenant = tenantAware.getCurrentTenant(); if (isTenantInvalid(currentTenant)) { return null; } currentTenant = currentTenant.toUpperCase(); return delegate.getCache(buildKey(currentTenant, name)); }