fix determination of current tenant security context (#333)

Signed-off-by: Michael Hirsch <michael.hirsch@bosch-si.com>
This commit is contained in:
Michael Hirsch
2016-10-31 23:43:00 +01:00
committed by GitHub
parent 3b869e215e
commit a0f98529e6

View File

@@ -38,10 +38,10 @@ public class SecurityContextTenantAware implements TenantAware {
final SecurityContext context = SecurityContextHolder.getContext(); final SecurityContext context = SecurityContextHolder.getContext();
if (context.getAuthentication() != null) { if (context.getAuthentication() != null) {
final Object principal = context.getAuthentication().getPrincipal(); final Object principal = context.getAuthentication().getPrincipal();
if (principal instanceof UserPrincipal) { if (context.getAuthentication().getDetails() instanceof TenantAwareAuthenticationDetails) {
return ((UserPrincipal) principal).getTenant();
} else if (context.getAuthentication().getDetails() instanceof TenantAwareAuthenticationDetails) {
return ((TenantAwareAuthenticationDetails) context.getAuthentication().getDetails()).getTenant(); return ((TenantAwareAuthenticationDetails) context.getAuthentication().getDetails()).getTenant();
}else if (principal instanceof UserPrincipal) {
return ((UserPrincipal) principal).getTenant();
} }
} }
return null; return null;
@@ -80,10 +80,13 @@ public class SecurityContextTenantAware implements TenantAware {
private final UserPrincipal systemPrincipal; private final UserPrincipal systemPrincipal;
private TenantAwareAuthenticationDetails tenantAwareAuthenticationDetails;
private AuthenticationDelegate(final Authentication delegate, final String tenant) { private AuthenticationDelegate(final Authentication delegate, final String tenant) {
this.delegate = delegate; this.delegate = delegate;
this.systemPrincipal = new UserPrincipal(SYSTEM_USER, SYSTEM_USER, SYSTEM_USER, SYSTEM_USER, SYSTEM_USER, this.systemPrincipal = new UserPrincipal(SYSTEM_USER, SYSTEM_USER, SYSTEM_USER, SYSTEM_USER, SYSTEM_USER,
null, tenant, SYSTEM_AUTHORITIES); null, tenant, SYSTEM_AUTHORITIES);
tenantAwareAuthenticationDetails = new TenantAwareAuthenticationDetails(tenant, false);
} }
@Override @Override
@@ -123,7 +126,7 @@ public class SecurityContextTenantAware implements TenantAware {
@Override @Override
public Object getDetails() { public Object getDetails() {
return (delegate != null) ? delegate.getDetails() : null; return tenantAwareAuthenticationDetails;
} }
@Override @Override