Skip to content

Commit

Permalink
Issue #6 - support view resource
Browse files Browse the repository at this point in the history
  • Loading branch information
gondor committed Oct 9, 2016
1 parent 2e12419 commit 94d5096
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<dependency>
<groupId>mesosphere.marathon</groupId>
<artifactId>plugin-interface_2.11</artifactId>
<version>1.3.1</version>
<version>1.3.2</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,27 @@ public <Resource> boolean isAuthorized(Identity identity, AuthorizedAction<Resou
if (identity instanceof UserIdentity) {
UserIdentity user = (UserIdentity) identity;
Action action = Action.byAction(authorizedAction);

if (resource instanceof Group) {
return isAuthorized(user, action, ((Group) resource).id());
}
if (resource instanceof RunSpec) {
return isAuthorized(user, action, ((RunSpec) resource).id());
}

// We don't get the PathID from View Resource but prior calls ensure the RunSpec is authorized
// in general
if (action == Action.VIEW_RESOURCE) {
return true;
}
return resource instanceof PathId && isAuthorized(user, action, (PathId) resource);
}
return false;
}

private boolean isAuthorized(UserIdentity identity, Action action, PathId path) {
boolean authorized = identity.isAuthorized(action, path.toString());
LOGGER.debug("IsAuthorized: Action :: {}, Path = {}, authorized :: {}" + action, path.toString(), authorized);
LOGGER.debug("IsAuthorized (private): Action :: {}, Path = {}, authorized = {}", action, path.toString(), authorized);
return authorized;
}

Expand Down
11 changes: 10 additions & 1 deletion src/main/java/io/containx/marathon/plugin/auth/type/Action.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.containx.marathon.plugin.auth.type;

import mesosphere.marathon.plugin.auth.AuthorizedAction;
import com.google.common.base.MoreObjects;
import mesosphere.marathon.plugin.auth.*;

/**
Expand Down Expand Up @@ -47,4 +47,13 @@ public EntityType getEntityType() {
public PermissionType getPermType() {
return permType;
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("action", action)
.add("entityType", entityType)
.add("permType", permType)
.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static AuthKey authKeyFromHeaders(HttpRequest request) throws Exception {
String encoded = header.get().replaceFirst("Basic ", "");
String decoded = new String(Base64.getDecoder().decode(encoded), "UTF-8");
String[] userPass = decoded.split(":", 2);
LOGGER.error("Returning username {} from HTTP Request headers", userPass[0]);

return AuthKey.with(userPass[0], userPass[1]);
}
return null;
Expand Down

0 comments on commit 94d5096

Please sign in to comment.