@Override
public PermissionCollection getPermissions(ProtectionDomain domain) {
Principal[] principals = domain.getPrincipals();
GVSPrincipal[] gvsPrincipals = getGVSPrincipals(principals);
PermissionCollection result = new Permissions();
/*if (gvsPrincipals.length == 0) {
//allow everything
result.add(new GVSImpersonatePermission());
result.add(new GVSSetClockPermission());
} else {*/
//Resource userRes = gvsPrincipals[0].getUserResource();
//This variant ensures up-to-date authorization
for (GVSPrincipal principal : gvsPrincipals) {
if (principal == SuperUserGVSPrincipal.instance) {
result.add(new GVSImpersonatePermission());
result.add(new GVSSetClockPermission());
}
Resource userRes = getUserResource(principal.getUserName());
if (userRes.hasProperty(RDF.type, AUTHORIZATION.ClockMaster));
StmtIterator impersonateStmt = userRes.listProperties(AUTHORIZATION.mayImpersonate);
while (impersonateStmt.hasNext()) {
result.add(new GVSImpersonatePermission(new SourceImpl(impersonateStmt.nextStatement().getResource().toString())));
}
}
//}
return result;