git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/Common/authorization-common-client@117387 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
af9a0f80f0
commit
ed1e6a29b2
|
@ -5,8 +5,8 @@ import javax.xml.bind.JAXBContext;
|
|||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.gcube.common.authorization.library.AuthorizationEntry;
|
||||
import org.gcube.common.authorization.library.BannedService;
|
||||
import org.gcube.common.authorization.library.BannedServices;
|
||||
import org.gcube.common.authorization.library.provider.Service;
|
||||
|
||||
public class Binder {
|
||||
|
||||
|
@ -14,7 +14,7 @@ public class Binder {
|
|||
|
||||
public static JAXBContext getContext() throws JAXBException{
|
||||
if (context==null)
|
||||
context = JAXBContext.newInstance(AuthorizationEntry.class, Service.class, BannedServices.class);
|
||||
context = JAXBContext.newInstance(AuthorizationEntry.class, BannedService.class, BannedServices.class);
|
||||
return context;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ import java.util.List;
|
|||
|
||||
import org.gcube.common.authorization.library.AuthorizationEntry;
|
||||
import org.gcube.common.authorization.library.BannedService;
|
||||
import org.gcube.common.authorization.library.provider.Service;
|
||||
|
||||
public interface AuthorizationProxy {
|
||||
|
||||
|
@ -12,9 +11,9 @@ public interface AuthorizationProxy {
|
|||
|
||||
AuthorizationEntry get(String token);
|
||||
|
||||
Service deny(String userName, Service service);
|
||||
BannedService deny(String userName, String serviceClass, String serviceName);
|
||||
|
||||
void allow(String userName, Service service);
|
||||
void allow(String userName, String serviceClass, String serviceName);
|
||||
|
||||
List<BannedService> getBannedServices(String userName);
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ import org.gcube.common.authorization.client.Constants;
|
|||
import org.gcube.common.authorization.library.AuthorizationEntry;
|
||||
import org.gcube.common.authorization.library.BannedService;
|
||||
import org.gcube.common.authorization.library.BannedServices;
|
||||
import org.gcube.common.authorization.library.provider.Service;
|
||||
import org.gcube.common.clients.Call;
|
||||
import org.gcube.common.clients.delegates.ProxyDelegate;
|
||||
import org.gcube.common.clients.stubs.jaxws.JAXWSUtils.Empty;
|
||||
|
@ -69,8 +68,7 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
|||
|
||||
@Override
|
||||
public AuthorizationEntry call(String endpoint) throws Exception {
|
||||
|
||||
System.out.println("calling get to "+endpoint);
|
||||
|
||||
URL url = new URL(endpoint+"/retrieve/"+token);
|
||||
HttpURLConnection connection = makeRequest(url, "GET");
|
||||
if (connection.getResponseCode()!=200) throw new Exception("error contacting authorization service");
|
||||
|
@ -84,8 +82,8 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
|||
|
||||
}
|
||||
};
|
||||
/*if (cache.containsKey(token) && cache.get(token).isValid())
|
||||
return cache.get(token).getEntry();*/
|
||||
if (cache.containsKey(token) && cache.get(token).isValid())
|
||||
return cache.get(token).getEntry();
|
||||
try {
|
||||
return delegate.make(call);
|
||||
} catch (Exception e) {
|
||||
|
@ -94,18 +92,18 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Service deny(final String userName, final Service service) {
|
||||
Call<String, Service> call = new Call<String, Service>() {
|
||||
public BannedService deny(final String userName, final String serviceClass, final String serviceName) {
|
||||
Call<String, BannedService> call = new Call<String, BannedService>() {
|
||||
@Override
|
||||
public Service call(String endpoint) throws Exception {
|
||||
URL url = new URL(endpoint+"/deny/"+userName+"/"+service.getServiceClass()+"/"+service.getServiceName());
|
||||
public BannedService call(String endpoint) throws Exception {
|
||||
URL url = new URL(endpoint+"/deny/"+userName+"/"+serviceClass+"/"+serviceName);
|
||||
HttpURLConnection connection = makeRequest(url, "POST");
|
||||
|
||||
if (connection.getResponseCode()!=200) throw new Exception("error contacting authorization service");
|
||||
if (connection.getResponseCode()!=200 && connection.getResponseCode()!=200) throw new Exception("error contacting authorization service");
|
||||
if (connection.getContentLengthLong()<=0) return null;
|
||||
|
||||
try(InputStream stream = (InputStream)connection.getContent();){
|
||||
Service service = (Service)Binder.getContext().createUnmarshaller().unmarshal(stream);
|
||||
BannedService service = (BannedService)Binder.getContext().createUnmarshaller().unmarshal(stream);
|
||||
return service;
|
||||
}
|
||||
}
|
||||
|
@ -119,14 +117,14 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void allow(final String userName, final Service service) {
|
||||
public void allow(final String userName, final String serviceClass, final String serviceName) {
|
||||
Call<String, Empty> call = new Call<String, Empty>() {
|
||||
|
||||
@Override
|
||||
public Empty call(String endpoint) throws Exception {
|
||||
URL url = new URL(endpoint+"/deny/"+userName+"/"+service.getServiceClass()+"/"+service.getServiceName());
|
||||
URL url = new URL(endpoint+"/deny/"+userName+"/"+serviceClass+"/"+serviceName);
|
||||
HttpURLConnection connection = makeRequest(url, "DELETE");
|
||||
if (connection.getResponseCode()!=200) throw new Exception("error contacting authorization service");
|
||||
if (!(connection.getResponseCode()>=200 && connection.getResponseCode()<=206)) throw new Exception("error contacting authorization service");
|
||||
return new Empty();
|
||||
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import java.util.Arrays;
|
|||
import java.util.List;
|
||||
|
||||
import org.gcube.common.authorization.library.BannedService;
|
||||
import org.gcube.common.authorization.library.provider.Service;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.junit.Test;
|
||||
public class CallTest {
|
||||
|
@ -15,14 +14,14 @@ public class CallTest {
|
|||
@Test
|
||||
public void call(){
|
||||
ScopeProvider.instance.set("/gcube/devsec");
|
||||
System.out.println(authorizationService().build().get("d7a4076c-e8c1-42fe-81e0-bdecb1e8074a"));
|
||||
System.out.println(authorizationService().build().get("df75336d-0944-4324-b444-c711d21f705b"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestToken(){
|
||||
|
||||
ScopeProvider.instance.set("/gcube/devsec");
|
||||
String token = authorizationService().build().generate("lucio.lelii", Arrays.asList("User"));
|
||||
ScopeProvider.instance.set("/gcube/devNext/NextNext");
|
||||
String token = authorizationService().build().generate("fabio.sinibaldi", Arrays.asList("User"));
|
||||
System.out.println("token is: "+token);
|
||||
|
||||
}
|
||||
|
@ -31,7 +30,7 @@ public class CallTest {
|
|||
public void denyService(){
|
||||
|
||||
ScopeProvider.instance.set("/gcube/devsec");
|
||||
authorizationService().build().deny("gianpaolo.coro", new Service("Test", "AuthorizationTest"));
|
||||
authorizationService().build().deny("lucio.lelii", "Test", "AuthorizationTest");
|
||||
|
||||
}
|
||||
|
||||
|
@ -39,7 +38,7 @@ public class CallTest {
|
|||
public void allowService(){
|
||||
|
||||
ScopeProvider.instance.set("/gcube/devsec");
|
||||
authorizationService().build().allow("gianpaolo.coro", new Service("Test", "AuthorizationTest"));
|
||||
authorizationService().build().allow("lucio.lelii", "Test", "AuthorizationTest");
|
||||
|
||||
}
|
||||
|
||||
|
@ -49,7 +48,7 @@ public class CallTest {
|
|||
ScopeProvider.instance.set("/gcube/devsec");
|
||||
List<BannedService> bannedServices = authorizationService().build().getBannedServices("lucio.lelii");
|
||||
for (BannedService banService : bannedServices)
|
||||
System.out.println(banService.getService());
|
||||
System.out.println(banService);
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue