Skip to content
Snippets Groups Projects
Verified Commit b70075a7 authored by Timm Fitschen's avatar Timm Fitschen
Browse files

WIP: acm grpc

parent 4344728d
No related branches found
No related tags found
2 merge requests!58REL: prepare release 0.7.2,!45F grpc f acm
Pipeline #17224 failed
...@@ -29,6 +29,7 @@ import static org.caosdb.server.utils.Utils.URLDecodeWithUTF8; ...@@ -29,6 +29,7 @@ import static org.caosdb.server.utils.Utils.URLDecodeWithUTF8;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.Collection; import java.util.Collection;
import java.util.LinkedList; import java.util.LinkedList;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.subject.Subject; import org.apache.shiro.subject.Subject;
import org.caosdb.server.CaosDBServer; import org.caosdb.server.CaosDBServer;
import org.caosdb.server.ServerProperties; import org.caosdb.server.ServerProperties;
...@@ -199,4 +200,8 @@ public class AuthenticationUtils { ...@@ -199,4 +200,8 @@ public class AuthenticationUtils {
.getRealm() .getRealm()
.equals(OneTimeAuthenticationToken.REALM_NAME); .equals(OneTimeAuthenticationToken.REALM_NAME);
} }
public static AuthorizationInfo getAuthorizationInfo(Subject user) {
return new CaosDBAuthorizingRealm().doGetAuthorizationInfo(user.getPrincipals());
}
} }
...@@ -49,6 +49,7 @@ public class CaosDBRolePermissionResolver { ...@@ -49,6 +49,7 @@ public class CaosDBRolePermissionResolver {
throw new AuthenticationException(e); throw new AuthenticationException(e);
} }
} }
return new CaosPermission(rules); return new CaosPermission(rules);
} }
} }
...@@ -21,7 +21,11 @@ ...@@ -21,7 +21,11 @@
package org.caosdb.server.grpc; package org.caosdb.server.grpc;
import io.grpc.stub.StreamObserver; import io.grpc.stub.StreamObserver;
import java.util.Collection;
import java.util.LinkedList;
import org.apache.shiro.SecurityUtils; import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.Permission;
import org.apache.shiro.subject.Subject; import org.apache.shiro.subject.Subject;
import org.caosdb.api.info.v1.GeneralInfoServiceGrpc.GeneralInfoServiceImplBase; import org.caosdb.api.info.v1.GeneralInfoServiceGrpc.GeneralInfoServiceImplBase;
import org.caosdb.api.info.v1.GetSessionInfoRequest; import org.caosdb.api.info.v1.GetSessionInfoRequest;
...@@ -31,7 +35,9 @@ import org.caosdb.api.info.v1.GetVersionInfoResponse; ...@@ -31,7 +35,9 @@ import org.caosdb.api.info.v1.GetVersionInfoResponse;
import org.caosdb.api.info.v1.VersionInfo; import org.caosdb.api.info.v1.VersionInfo;
import org.caosdb.server.CaosDBServer; import org.caosdb.server.CaosDBServer;
import org.caosdb.server.ServerProperties; import org.caosdb.server.ServerProperties;
import org.caosdb.server.accessControl.AuthenticationUtils;
import org.caosdb.server.accessControl.Principal; import org.caosdb.server.accessControl.Principal;
import org.caosdb.server.permissions.CaosPermission;
/** /**
* Implementation of the GeneralInfoService. * Implementation of the GeneralInfoService.
...@@ -83,6 +89,24 @@ public class GeneralInfoServiceImpl extends GeneralInfoServiceImplBase { ...@@ -83,6 +89,24 @@ public class GeneralInfoServiceImpl extends GeneralInfoServiceImplBase {
response.setUsername(principal.getUsername()); response.setUsername(principal.getUsername());
response.setRealm(principal.getRealm()); response.setRealm(principal.getRealm());
AuthorizationInfo authorizationInfo = AuthenticationUtils.getAuthorizationInfo(user);
Collection<String> roles = authorizationInfo.getRoles();
if (roles != null && !roles.isEmpty()) {
response.addAllRoles(roles);
}
Collection<String> permissions =
new LinkedList<String>(authorizationInfo.getStringPermissions());
for (Permission p : authorizationInfo.getObjectPermissions()) {
if (p instanceof CaosPermission) {
permissions.addAll(((CaosPermission) p).getStringPermissions(user));
} else {
permissions.add(p.toString());
}
}
if (permissions != null && !permissions.isEmpty()) {
response.addAllPermissions(permissions);
}
responseObserver.onNext(response.build()); responseObserver.onNext(response.build());
responseObserver.onCompleted(); responseObserver.onCompleted();
} }
......
...@@ -97,8 +97,8 @@ public class Schedule { ...@@ -97,8 +97,8 @@ public class Schedule {
? this.jobLists.get(jobclass.getAnnotation(JobAnnotation.class).stage().ordinal()) ? this.jobLists.get(jobclass.getAnnotation(JobAnnotation.class).stage().ordinal())
: this.jobLists.get(TransactionStage.CHECK.ordinal()); : this.jobLists.get(TransactionStage.CHECK.ordinal());
for (final ScheduledJob scheduledJob : jobs) { for (final ScheduledJob scheduledJob : jobs) {
if (jobclass.isInstance(scheduledJob.job)) { if (jobclass.isInstance(scheduledJob.getJob())) {
if (scheduledJob.job.getEntity() == entity) { if (scheduledJob.getJob().getEntity() == entity) {
runJob(scheduledJob); runJob(scheduledJob);
} }
} }
......
...@@ -31,11 +31,14 @@ package org.caosdb.server.jobs; ...@@ -31,11 +31,14 @@ package org.caosdb.server.jobs;
public class ScheduledJob { public class ScheduledJob {
long runtime = 0; long runtime = 0;
final Job job; private final Job job;
private long startTime = -1; private long startTime = -1;
ScheduledJob(final Job j) { ScheduledJob(final Job job) {
this.job = j; if (job == null) {
throw new NullPointerException("job was null.");
}
this.job = job;
} }
void run() { void run() {
...@@ -85,4 +88,8 @@ public class ScheduledJob { ...@@ -85,4 +88,8 @@ public class ScheduledJob {
public boolean skip() { public boolean skip() {
return this.job.getTarget().skipJob(); return this.job.getTarget().skipJob();
} }
public Job getJob() {
return job;
}
} }
...@@ -22,12 +22,11 @@ ...@@ -22,12 +22,11 @@
*/ */
package org.caosdb.server.permissions; package org.caosdb.server.permissions;
import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map;
import org.apache.shiro.SecurityUtils; import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.Permission; import org.apache.shiro.authz.Permission;
import org.apache.shiro.subject.Subject; import org.apache.shiro.subject.Subject;
import org.eclipse.jetty.util.ajax.JSON;
public class CaosPermission extends HashSet<PermissionRule> implements Permission { public class CaosPermission extends HashSet<PermissionRule> implements Permission {
...@@ -35,16 +34,33 @@ public class CaosPermission extends HashSet<PermissionRule> implements Permissio ...@@ -35,16 +34,33 @@ public class CaosPermission extends HashSet<PermissionRule> implements Permissio
super(rules); super(rules);
} }
public CaosPermission() {} public Collection<String> getStringPermissions(Subject subject) {
HashSet<String> grant = new HashSet<>();
HashSet<String> prio_grant = new HashSet<>();
HashSet<String> deny = new HashSet<>();
HashSet<String> prio_deny = new HashSet<>();
public static CaosPermission parseJSON(final String json) { for (PermissionRule r : this) {
final CaosPermission ret = new CaosPermission(); String p = subject == null ? r.getPermission() : r.getPermission(subject).toString();
@SuppressWarnings("unchecked") if (r.isGrant()) {
final Map<String, String>[] rules = (Map<String, String>[]) JSON.parse(json); if (r.isPriority()) {
for (final Map<String, String> rule : rules) { prio_grant.add(p);
ret.add(PermissionRule.parse(rule)); } else {
grant.add(p);
}
} else {
if (r.isPriority()) {
prio_deny.add(p);
} else {
deny.add(p);
}
}
} }
return ret;
grant.removeAll(deny);
grant.addAll(prio_grant);
grant.removeAll(prio_deny);
return grant;
} }
private static final long serialVersionUID = 2136265443788256009L; private static final long serialVersionUID = 2136265443788256009L;
......
...@@ -251,6 +251,7 @@ public abstract class AbstractCaosDBServerResource extends ServerResource { ...@@ -251,6 +251,7 @@ public abstract class AbstractCaosDBServerResource extends ServerResource {
try { try {
return httpPostInChildClass(entity); return httpPostInChildClass(entity);
} catch (final Throwable t) { } catch (final Throwable t) {
t.printStackTrace();
return handleThrowable(t); return handleThrowable(t);
} }
} }
......
...@@ -51,12 +51,14 @@ public class RetrieveRoleTransaction extends AccessControlTransaction { ...@@ -51,12 +51,14 @@ public class RetrieveRoleTransaction extends AccessControlTransaction {
if (this.role == null) { if (this.role == null) {
throw ServerMessages.ROLE_DOES_NOT_EXIST; throw ServerMessages.ROLE_DOES_NOT_EXIST;
} }
Iterator<ProtoUser> iterator = this.role.users.iterator(); if (this.role.users != null) {
while (iterator.hasNext()) { Iterator<ProtoUser> iterator = this.role.users.iterator();
ProtoUser user = iterator.next(); while (iterator.hasNext()) {
if (!currentUser.isPermitted( ProtoUser user = iterator.next();
ACMPermissions.PERMISSION_RETRIEVE_USER_ROLES(user.realm, user.name))) { if (!currentUser.isPermitted(
iterator.remove(); ACMPermissions.PERMISSION_RETRIEVE_USER_ROLES(user.realm, user.name))) {
iterator.remove();
}
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment