git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/Common/authorization-common-client@129126 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
23e77bcc81
commit
e09f53b3b5
|
@ -7,6 +7,7 @@ import org.gcube.common.authorization.library.AuthorizationEntry;
|
|||
import org.gcube.common.authorization.library.enpoints.AuthorizationEndpoint;
|
||||
import org.gcube.common.authorization.library.policies.Policy;
|
||||
import org.gcube.common.authorization.library.provider.ClientInfo;
|
||||
import org.gcube.common.authorization.library.provider.ServiceInfo;
|
||||
|
||||
public interface AuthorizationProxy {
|
||||
|
||||
|
@ -19,6 +20,9 @@ public interface AuthorizationProxy {
|
|||
String generateToken(ClientInfo client, String context)
|
||||
throws Exception;
|
||||
|
||||
String requestActivation(ServiceInfo container, String context)
|
||||
throws Exception;
|
||||
|
||||
void addPolicies(List<Policy> policies) throws Exception;
|
||||
|
||||
void removePolicies(long ... ids) throws Exception;
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.gcube.common.authorization.library.enpoints.AuthorizationEndpoint;
|
|||
import org.gcube.common.authorization.library.enpoints.AuthorizationEndpointScanner;
|
||||
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.encryption.StringEncrypter;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -45,7 +46,6 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
|||
StringBuilder endpoint = new StringBuilder("http://").append(getEndpoint().getHost()).append(":")
|
||||
.append(getEndpoint().getPort()).append("/authorization-service/gcube/service");
|
||||
return endpoint.toString();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -71,6 +71,42 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
|||
Binder.getContext().createMarshaller().marshal(client, os);
|
||||
}
|
||||
|
||||
log.debug("response code for "+callUrl.toString()+" is "+connection.getResponseCode()+" "+connection.getResponseMessage());
|
||||
|
||||
if (connection.getResponseCode()!=200) throw new Exception("error contacting authorization service");
|
||||
String encryptedToken= "";
|
||||
try(BufferedReader reader = new BufferedReader(new InputStreamReader((InputStream)connection.getContent()))){
|
||||
StringBuilder result = new StringBuilder();
|
||||
String line;
|
||||
while((line = reader.readLine()) != null)
|
||||
result.append(line);
|
||||
encryptedToken = result.toString();
|
||||
}
|
||||
|
||||
return StringEncrypter.getEncrypter().decrypt(encryptedToken, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String requestActivation(ServiceInfo container, String context) throws Exception {
|
||||
|
||||
String methodPath = "/generate/node";
|
||||
|
||||
|
||||
|
||||
StringBuilder callUrl = new StringBuilder(getInternalEnpoint()).append(methodPath).append("?")
|
||||
.append(CONTEXT_PARAM).append("=").append(context);
|
||||
|
||||
URL url = new URL(callUrl.toString());
|
||||
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
|
||||
connection.setRequestMethod("PUT");
|
||||
connection.setDoOutput(true);
|
||||
connection.setDoInput(true);
|
||||
connection.setRequestProperty("Content-type", "application/xml");
|
||||
|
||||
try(OutputStream os = new BufferedOutputStream(connection.getOutputStream())){
|
||||
Binder.getContext().createMarshaller().marshal(container, os);
|
||||
}
|
||||
|
||||
log.debug("response code is "+connection.getResponseCode());
|
||||
|
||||
if (connection.getResponseCode()!=200) throw new Exception("error contacting authorization service");
|
||||
|
@ -85,7 +121,7 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
|||
|
||||
return StringEncrypter.getEncrypter().decrypt(encryptedToken, context);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public AuthorizationEntry get(String token) throws ObjectNotFound, Exception{
|
||||
if (cache.containsKey(token) && cache.get(token).isValid())
|
||||
|
|
|
@ -30,9 +30,10 @@ public class CallTest {
|
|||
|
||||
@Test
|
||||
public void requestToken() throws Exception {
|
||||
//ScopeProvider.instance.set("/gcube/devsec");
|
||||
System.out.println( authorizationService().generateToken(new UserInfo("testckan", new ArrayList<String>()), "/gcube"));
|
||||
|
||||
for (int i=0; i<4000; i++){
|
||||
System.out.println( authorizationService().generateToken(new UserInfo("ckanTestRec"+i, new ArrayList<String>()), "/gcube"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue