This commit is contained in:
Lucio Lelii 2016-06-15 11:47:22 +00:00
parent 23e77bcc81
commit e09f53b3b5
3 changed files with 45 additions and 4 deletions

View File

@ -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;

View File

@ -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())

View File

@ -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