Difference between revisions of "Authorization Client Library"

From Gcube Wiki
Jump to: navigation, search
(maven dependency)
 
Line 12: Line 12:
 
   <version>2.0.0-SNAPSHOT</version>
 
   <version>2.0.0-SNAPSHOT</version>
 
   </dependency>
 
   </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>
 
</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();
 
...