setRoles on a token added
This commit is contained in:
parent
6cbfabc0a7
commit
6d6bd2daa0
2
pom.xml
2
pom.xml
|
@ -3,7 +3,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>authorization-client</artifactId>
|
||||
<version>2.0.4-SNAPSHOT</version>
|
||||
<version>2.0.5-SNAPSHOT</version>
|
||||
<name>authorization service client library</name>
|
||||
|
||||
<parent>
|
||||
|
|
|
@ -12,6 +12,7 @@ import org.gcube.common.authorization.library.policies.Policy;
|
|||
import org.gcube.common.authorization.library.provider.ClientInfo;
|
||||
import org.gcube.common.authorization.library.provider.ServiceInfo;
|
||||
import org.gcube.common.authorization.library.provider.UserInfo;
|
||||
import org.gcube.common.authorization.library.utils.ListMapper;
|
||||
|
||||
public class Binder {
|
||||
|
||||
|
@ -20,7 +21,7 @@ public class Binder {
|
|||
public static JAXBContext getContext() throws JAXBException{
|
||||
if (context==null)
|
||||
context = JAXBContext.newInstance(ExternalServiceList.class, QualifiersList.class, AuthorizationEntry.class, ClientInfo.class, UserInfo.class,
|
||||
ServiceInfo.class, Policies.class, Policy.class);
|
||||
ServiceInfo.class, Policies.class, Policy.class, ListMapper.class);
|
||||
return context;
|
||||
}
|
||||
|
||||
|
|
|
@ -52,4 +52,6 @@ public interface AuthorizationProxy {
|
|||
|
||||
void removeAllReleatedToken(String clientId, String context) throws Exception;
|
||||
|
||||
void setTokenRoles(String token, List<String> roles) throws Exception;
|
||||
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ import org.gcube.common.authorization.library.provider.ContainerInfo;
|
|||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.authorization.library.provider.ServiceInfo;
|
||||
import org.gcube.common.authorization.library.provider.UserInfo;
|
||||
import org.gcube.common.authorization.library.utils.ListMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -186,6 +187,35 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
|||
return Utils.addInfrastructureHashToToken(token, infrastructureHash);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTokenRoles(String token, List<String> roles) throws Exception {
|
||||
|
||||
String realToken = Utils.getRealToken(token);
|
||||
String methodPath = String.format("/token/user/%s/roles",realToken);
|
||||
|
||||
int infrastructureHash = Utils.getInfrastructureHashFromToken(token, endpoints.getDefaultInfrastructure());
|
||||
|
||||
StringBuilder callUrl = new StringBuilder(getInternalEnpoint(infrastructureHash)).append(methodPath);
|
||||
|
||||
URL url = new URL(callUrl.toString());
|
||||
HttpURLConnection connection = makeRequest(url, "PUT", false);
|
||||
connection.setDoOutput(true);
|
||||
connection.setDoInput(true);
|
||||
connection.setRequestProperty("Content-type", "application/xml");
|
||||
|
||||
ListMapper listmapper = new ListMapper();
|
||||
listmapper.setList(roles);
|
||||
try(OutputStream os = new BufferedOutputStream(connection.getOutputStream())){
|
||||
Binder.getContext().createMarshaller().marshal(listmapper, os);
|
||||
}
|
||||
|
||||
log.debug("response code for "+callUrl.toString()+" is "+connection.getResponseCode()+" "+connection.getResponseMessage());
|
||||
|
||||
if (connection.getResponseCode()!=200) throw new Exception("error contacting authorization service");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void removeAllReleatedToken(String clientId, String context) throws Exception{
|
||||
String methodPath = "/token/user";
|
||||
|
|
|
@ -8,6 +8,8 @@ import java.io.FileInputStream;
|
|||
import java.io.FileWriter;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -25,7 +27,7 @@ import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
|||
import org.gcube.common.authorization.library.provider.UserInfo;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
@Ignore
|
||||
|
||||
public class CallTest {
|
||||
|
||||
@Test
|
||||
|
@ -35,7 +37,10 @@ public class CallTest {
|
|||
|
||||
@Test
|
||||
public void requestUserTokenViaUserNameAndScope() throws Exception {
|
||||
System.out.println(authorizationService().resolveTokenByUserAndContext("valentina.marioli", "/gcube/devNext/NextNext"));
|
||||
String token = authorizationService().resolveTokenByUserAndContext("valentina.marioli", "/gcube");
|
||||
authorizationService().setTokenRoles(token, Arrays.asList("VOManager"));
|
||||
AuthorizationEntry authEntry = authorizationService().get(token);
|
||||
System.out.println(authEntry.getClientInfo().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue