-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for role namespaces (#94)
Added namespaces to roles for grouping and future permission management
- Loading branch information
1 parent
a8598bf
commit 697dc64
Showing
45 changed files
with
1,943 additions
and
445 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
auth/auth-core/src/main/java/com/bazaarvoice/emodb/auth/AuthZooKeeper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.bazaarvoice.emodb.auth; | ||
|
||
import com.google.inject.BindingAnnotation; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import static java.lang.annotation.ElementType.FIELD; | ||
import static java.lang.annotation.ElementType.METHOD; | ||
import static java.lang.annotation.ElementType.PARAMETER; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
/** | ||
* Annotation for the ZooKeeper curator namespaced for the authentication framework. | ||
*/ | ||
@BindingAnnotation | ||
@Target({ FIELD, PARAMETER, METHOD }) @Retention(RUNTIME) | ||
public @interface AuthZooKeeper { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
auth/auth-core/src/main/java/com/bazaarvoice/emodb/auth/identity/AuthIdentityReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.bazaarvoice.emodb.auth.identity; | ||
|
||
import org.apache.shiro.authz.AuthorizationInfo; | ||
|
||
import java.util.Set; | ||
|
||
/** | ||
* Minimal interface for read-only access to authentication identities. | ||
*/ | ||
public interface AuthIdentityReader<T extends AuthIdentity> { | ||
|
||
/** | ||
* Gets an entity by ID, such as its API key. Returns the identity, or null if no such identity exists. | ||
*/ | ||
T getIdentity(String id); | ||
|
||
/** | ||
* Gets the roles associated with an identity by its internal ID. | ||
* | ||
* Although role management is done using {@link com.bazaarvoice.emodb.auth.role.RoleIdentifier} Shiro's | ||
* authorization framework represents roles as Strings, as demonstrated by {@link AuthorizationInfo#getRoles())}. | ||
* Since this reader is used as part of the authorization framework it provides an interface compatible with what | ||
* Shiro requires. | ||
*/ | ||
Set<String> getRolesByInternalId(String internalId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
auth/auth-core/src/main/java/com/bazaarvoice/emodb/auth/permissions/PermissionIDs.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.bazaarvoice.emodb.auth.permissions; | ||
|
||
import com.bazaarvoice.emodb.auth.role.RoleIdentifier; | ||
|
||
/** | ||
* Static helper class for converting type-specific permissions to flat namespaced Strings used by | ||
* {@link PermissionReader#getPermissions(String)}. While currently only roles can have permissions attached to them | ||
* this convention allows for future additional permission types without need for a separate permission management | ||
* system. | ||
*/ | ||
public final class PermissionIDs { | ||
|
||
public static String forRole(RoleIdentifier id) { | ||
return forRole(id.toString()); | ||
} | ||
|
||
public static String forRole(String role) { | ||
return "role:" + role; | ||
} | ||
} |
Oops, something went wrong.