Difference between revisions of "Authorization Client Library"

From Gcube Wiki
Jump to: navigation, search
(Authorization Client Library)
(maven dependency)
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
The Authorization Client library helps clients to generate and resolve <code>gCube Token</code>.
+
The Authorization Client library helps clients to generate and resolve <code>gCube Token</code> and also to add/remove <code>Policies</code> for service/user/role access.
 +
 
 +
 
 +
== maven dependency ==
 +
The required dependency to be added to the pom is:
 +
 
 +
<source lang="xml">
 +
 
 +
  <dependency>
 +
  <groupId>org.gcube.common</groupId>
 +
  <artifactId>authorization-client</artifactId>
 +
  <version>2.0.0-SNAPSHOT</version>
 +
  </dependency>
 +
 
 +
</source>
 +
 
 +
 
 +
== Examples ==
 +
 
 +
 
 +
= Generate a token =
 +
 
 +
The following example will show how to generate a token for a user in a context.
 +
 
 +
<source lang="java">
 +
 
 +
import static org.gcube.common.authorization.client.Constants.authorizationService;
 +
 
 +
...
 +
authorizationService().generateToken(new UserInfo({userName}, Arrays.asList("role1", "role2")), "context");
 +
...
 +
 
 +
</source>
 +
 
 +
= Resolve token =
 +
 
 +
The following example will show how to resolve a token.
 +
 
 +
<source lang="java">
 +
 
 +
import static org.gcube.common.authorization.client.Constants.authorizationService;
 +
 
 +
...
 +
AuthorizationEntry entry = authorizationService().get("token");
 +
 
 +
//retrieve the info of the token owner
 +
entry.getClientInfo();
 +
 
 +
//retrieve the context of the token owner
 +
entry.getContext();
 +
 
 +
...
 +
 
 +
</source>

Latest revision as of 17:39, 10 May 2016

The Authorization Client library helps clients to generate and resolve gCube Token and also to add/remove Policies for service/user/role access.


maven dependency

The required dependency to be added to the pom is:

  <dependency>
   <groupId>org.gcube.common</groupId>
   <artifactId>authorization-client</artifactId>
   <version>2.0.0-SNAPSHOT</version>
  </dependency>


Examples

Generate a token

The following example will show how to generate a token for a user in a context.

import static org.gcube.common.authorization.client.Constants.authorizationService;
 
...
authorizationService().generateToken(new UserInfo({userName}, Arrays.asList("role1", "role2")), "context");
...

Resolve token

The following example will show how to resolve a token.

import static org.gcube.common.authorization.client.Constants.authorizationService;
 
...
AuthorizationEntry entry = authorizationService().get("token");
 
//retrieve the info of the token owner
entry.getClientInfo();
 
//retrieve the context of the token owner
entry.getContext();
 
...