new features for configuration file type changing
parent
cf3c134953
commit
08b3cd590a
@ -1,2 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<smartgears version="${project.version}" />
|
@ -0,0 +1,138 @@
|
||||
package org.gcube.smartgears.handlers;
|
||||
|
||||
import static org.gcube.smartgears.utils.Utils.notEmpty;
|
||||
import static org.gcube.smartgears.utils.Utils.rethrowUnchecked;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.resources.gcore.Resource;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.informationsystem.publisher.ScopedPublisher;
|
||||
import org.gcube.smartgears.provider.ProviderFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public abstract class AbstractProfilePublisher<P extends Resource> implements ProfilePublisher {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(AbstractProfilePublisher.class);
|
||||
|
||||
//the underlying IS publisher
|
||||
private final ScopedPublisher publisher;
|
||||
|
||||
//private AuthorizationProvider authProvider ;
|
||||
|
||||
public AbstractProfilePublisher() {
|
||||
this.publisher=ProviderFactory.provider().publisher();
|
||||
//this.authProvider = ProviderFactory.provider().authorizationProvider();
|
||||
}
|
||||
|
||||
protected abstract P getProfile();
|
||||
protected abstract boolean isRoot();
|
||||
protected abstract void sharePublished(P profile);
|
||||
protected abstract Set<String> getAllowedContexts();
|
||||
|
||||
/**
|
||||
* Removes the application from one or more scopes.
|
||||
* @param scopes the scopes
|
||||
*/
|
||||
public void removeFrom(Collection<String> contexts) {
|
||||
P profile = getProfile();
|
||||
ClassLoader contextCL = Thread.currentThread().getContextClassLoader();
|
||||
|
||||
log.debug("using context {}",contextCL.getClass().getSimpleName());
|
||||
|
||||
String previousToken = SecurityTokenProvider.instance.get();
|
||||
String previousScope = ScopeProvider.instance.get();
|
||||
try{//This classloader set is needed for the jaxb context
|
||||
if (previousToken!=null)
|
||||
SecurityTokenProvider.instance.reset();
|
||||
if (isRoot())
|
||||
Thread.currentThread().setContextClassLoader(AbstractProfilePublisher.class.getClassLoader());
|
||||
profile = publisher.remove(profile, new ArrayList<String>(contexts));
|
||||
|
||||
} catch (Exception e) {
|
||||
rethrowUnchecked(e);
|
||||
} finally{
|
||||
SecurityTokenProvider.instance.set(previousToken);
|
||||
ScopeProvider.instance.set(previousScope);
|
||||
if (isRoot())
|
||||
Thread.currentThread().setContextClassLoader(contextCL);
|
||||
}
|
||||
log.debug("after remove application profile contains scopes {}",profile.scopes().asCollection());
|
||||
sharePublished(profile);
|
||||
}
|
||||
|
||||
|
||||
public void addToAll(){
|
||||
this.addTo(getAllowedContexts());
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds for the first time the current resource profile of the application in one or more scopes.
|
||||
* @param contexts the contexts
|
||||
*/
|
||||
public void addTo(Collection<String> contexts) {
|
||||
notEmpty("contexts",contexts);
|
||||
|
||||
P profile = getProfile();
|
||||
|
||||
ClassLoader contextCL = Thread.currentThread().getContextClassLoader();
|
||||
|
||||
log.debug("using context {}",contextCL.getClass().getSimpleName());
|
||||
|
||||
String previousToken = SecurityTokenProvider.instance.get();
|
||||
String previousScope = ScopeProvider.instance.get();
|
||||
try{//This classloader set is needed for the jaxb context
|
||||
if (previousToken!=null)
|
||||
SecurityTokenProvider.instance.reset();;
|
||||
if (isRoot()) Thread.currentThread().setContextClassLoader(AbstractProfilePublisher.class.getClassLoader());
|
||||
ScopeProvider.instance.set(contexts.stream().findFirst().get());
|
||||
profile = publisher.create(profile, new ArrayList<String>(contexts));
|
||||
|
||||
} catch (Exception e) {
|
||||
rethrowUnchecked(e);
|
||||
} finally{
|
||||
SecurityTokenProvider.instance.set(previousToken);
|
||||
ScopeProvider.instance.set(previousScope);
|
||||
if (isRoot()) Thread.currentThread().setContextClassLoader(contextCL);
|
||||
}
|
||||
|
||||
sharePublished(profile);
|
||||
log.debug("shared profile with scopes {}", profile.scopes().asCollection());
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void update() {
|
||||
P profile = getProfile();
|
||||
ClassLoader contextCL = Thread.currentThread().getContextClassLoader();
|
||||
|
||||
log.debug("using context {}",contextCL.getClass().getSimpleName());
|
||||
|
||||
String previousToken = SecurityTokenProvider.instance.get();
|
||||
String previousScope = ScopeProvider.instance.get();
|
||||
try{//This classloader set is needed for the jaxb context
|
||||
if (previousToken!=null)
|
||||
SecurityTokenProvider.instance.reset();
|
||||
|
||||
if (isRoot())
|
||||
Thread.currentThread().setContextClassLoader(AbstractProfilePublisher.class.getClassLoader());
|
||||
profile = publisher.update(profile);
|
||||
|
||||
} catch (Exception e) {
|
||||
rethrowUnchecked(e);
|
||||
} finally{
|
||||
SecurityTokenProvider.instance.set(previousToken);
|
||||
ScopeProvider.instance.set(previousScope);
|
||||
if (isRoot())
|
||||
Thread.currentThread().setContextClassLoader(contextCL);
|
||||
}
|
||||
|
||||
sharePublished(profile);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,201 +0,0 @@
|
||||
package org.gcube.smartgears.handlers.application.lifecycle;
|
||||
|
||||
import static org.gcube.smartgears.handlers.ProfileEvents.published;
|
||||
import static org.gcube.smartgears.utils.Utils.notEmpty;
|
||||
import static org.gcube.smartgears.utils.Utils.rethrowUnchecked;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.resources.gcore.GCoreEndpoint;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.informationsystem.publisher.ScopedPublisher;
|
||||
import org.gcube.smartgears.configuration.Mode;
|
||||
import org.gcube.smartgears.context.application.ApplicationContext;
|
||||
import org.gcube.smartgears.handlers.ProfilePublisher;
|
||||
import org.gcube.smartgears.provider.ProviderFactory;
|
||||
import org.gcube.smartgears.security.AuthorizationProvider;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Publishes the current resource profile of the application.
|
||||
* <p>
|
||||
*Distinguishes publication in new scopes ({@link #addTo(List)} from publication updates in existing scopes ({@link #update()}.
|
||||
*
|
||||
*
|
||||
* @author Fabio Simeoni
|
||||
*
|
||||
*/
|
||||
public class ProfilePublisherImpl implements ProfilePublisher {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(ProfilePublisherImpl.class);
|
||||
|
||||
//the underlying IS publisher
|
||||
private final ScopedPublisher publisher;
|
||||
|
||||
private final ApplicationContext context;
|
||||
|
||||
private AuthorizationProvider authProxy ;
|
||||
|
||||
/**
|
||||
* Creates an instance for a given application.
|
||||
* @param context the context of the application
|
||||
*/
|
||||
public ProfilePublisherImpl(ApplicationContext context) {
|
||||
this.context = context;
|
||||
this.publisher=ProviderFactory.provider().publisherFor(context);
|
||||
this.authProxy = context.container().configuration().authorizationProvider();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds for the first time the current resource profile of the application in one or more scopes.
|
||||
* @param scopes the scopes
|
||||
*/
|
||||
@Override
|
||||
public void addTo(Collection<String> contexts) {
|
||||
|
||||
notEmpty("tokens",contexts);
|
||||
|
||||
GCoreEndpoint profile = context.profile(GCoreEndpoint.class);
|
||||
|
||||
/* TODO: reintroduce it when scope will be removed
|
||||
//TODO: remove when move to new IS
|
||||
Collection<String> retainedContexts = new ArrayList<String>(context.container().configuration().allowedContexts());
|
||||
retainedContexts.removeAll(profile.scopes().asCollection());
|
||||
profile.scopes().asCollection().addAll(retainedContexts);
|
||||
|
||||
|
||||
String previousToken = SecurityTokenProvider.instance.get();
|
||||
try {
|
||||
for (String token: tokens){
|
||||
log.info("creating profile with token {}", token);
|
||||
SecurityTokenProvider.instance.set(token);
|
||||
profile = publisher.create(profile);
|
||||
SecurityTokenProvider.instance.reset();
|
||||
}
|
||||
}catch (Exception e) {
|
||||
rethrowUnchecked(e);
|
||||
} finally{
|
||||
SecurityTokenProvider.instance.set(previousToken);
|
||||
}
|
||||
*/
|
||||
|
||||
ClassLoader contextCL = Thread.currentThread().getContextClassLoader();
|
||||
|
||||
log.debug("using context {}",contextCL.getClass().getSimpleName());
|
||||
|
||||
String previousToken = SecurityTokenProvider.instance.get();
|
||||
String previousScope = ScopeProvider.instance.get();
|
||||
try{//This classloader set is needed for the jaxb context
|
||||
if (previousToken!=null)
|
||||
SecurityTokenProvider.instance.reset();;
|
||||
if (context.container().configuration().mode()!=Mode.root) Thread.currentThread().setContextClassLoader(ProfilePublisherImpl.class.getClassLoader());
|
||||
ScopeProvider.instance.set(contexts.stream().findFirst().get());
|
||||
profile = publisher.create(profile, new ArrayList<String>(contexts));
|
||||
|
||||
} catch (Exception e) {
|
||||
rethrowUnchecked(e);
|
||||
} finally{
|
||||
SecurityTokenProvider.instance.set(previousToken);
|
||||
ScopeProvider.instance.set(previousScope);
|
||||
if (context.container().configuration().mode()!=Mode.root) Thread.currentThread().setContextClassLoader(contextCL);
|
||||
}
|
||||
|
||||
sharePublished(profile);
|
||||
log.debug("shared profile with scopes {}", profile.scopes().asCollection());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addToAll() {
|
||||
this.addTo(context.configuration().allowedContexts());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
|
||||
|
||||
GCoreEndpoint profile = context.profile(GCoreEndpoint.class);
|
||||
|
||||
ClassLoader contextCL = Thread.currentThread().getContextClassLoader();
|
||||
|
||||
log.debug("using context {}",contextCL.getClass().getSimpleName());
|
||||
|
||||
String previousToken = SecurityTokenProvider.instance.get();
|
||||
String previousScope = ScopeProvider.instance.get();
|
||||
try{//This classloader set is needed for the jaxb context
|
||||
if (previousToken!=null)
|
||||
SecurityTokenProvider.instance.reset();
|
||||
|
||||
if (context.container().configuration().mode()!=Mode.root)
|
||||
Thread.currentThread().setContextClassLoader(ProfilePublisherImpl.class.getClassLoader());
|
||||
profile = publisher.update(profile);
|
||||
|
||||
} catch (Exception e) {
|
||||
rethrowUnchecked(e);
|
||||
} finally{
|
||||
SecurityTokenProvider.instance.set(previousToken);
|
||||
ScopeProvider.instance.set(previousScope);
|
||||
if (context.container().configuration().mode()!=Mode.root)
|
||||
Thread.currentThread().setContextClassLoader(contextCL);
|
||||
}
|
||||
|
||||
sharePublished(profile);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes the application from one or more scopes.
|
||||
* @param scopes the scopes
|
||||
*/
|
||||
@Override
|
||||
public void removeFrom(Collection<String> contexts) {
|
||||
|
||||
GCoreEndpoint profile = context.profile(GCoreEndpoint.class);
|
||||
|
||||
ClassLoader contextCL = Thread.currentThread().getContextClassLoader();
|
||||
|
||||
log.debug("using context {}",contextCL.getClass().getSimpleName());
|
||||
|
||||
String previousToken = SecurityTokenProvider.instance.get();
|
||||
String previousScope = ScopeProvider.instance.get();
|
||||
try{//This classloader set is needed for the jaxb context
|
||||
if (previousToken!=null)
|
||||
SecurityTokenProvider.instance.reset();
|
||||
if (context.container().configuration().mode()!=Mode.root)
|
||||
Thread.currentThread().setContextClassLoader(ProfilePublisherImpl.class.getClassLoader());
|
||||
profile = publisher.remove(profile, contexts);
|
||||
|
||||
} catch (Exception e) {
|
||||
rethrowUnchecked(e);
|
||||
} finally{
|
||||
SecurityTokenProvider.instance.set(previousToken);
|
||||
ScopeProvider.instance.set(previousScope);
|
||||
if (context.container().configuration().mode()!=Mode.root)
|
||||
Thread.currentThread().setContextClassLoader(contextCL);
|
||||
}
|
||||
log.debug("after remove application profile contains scopes {}",profile.scopes().asCollection());
|
||||
sharePublished(profile);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void sharePublished(GCoreEndpoint profile) {
|
||||
context.events().fire(profile,published);
|
||||
}
|
||||
|
||||
private List<String> resolveScopesFromTokens(Collection<String> tokens){
|
||||
List<String> scopes = new ArrayList<String>(tokens.size());
|
||||
for (String token: tokens)
|
||||
try{
|
||||
scopes.add(this.authProxy.get(token).getContext());
|
||||
}catch (Exception e) {
|
||||
log.warn("error retrieving token {} , it should never happen",token);
|
||||
}
|
||||
return scopes;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
package org.gcube.smartgears.handlers.application.lifecycle;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.gcube.common.resources.gcore.GCoreEndpoint;
|
||||
import org.gcube.common.resources.gcore.HostingNode;
|
||||
import org.gcube.smartgears.configuration.Mode;
|
||||
import org.gcube.smartgears.context.application.ApplicationContext;
|
||||
import org.gcube.smartgears.handlers.AbstractProfilePublisher;
|
||||
import org.gcube.smartgears.handlers.ProfileEvents;
|
||||
|
||||
/**
|
||||
* Publishes the current resource profile of the application.
|
||||
* <p>
|
||||
*Distinguishes publication in new scopes ({@link #addTo(List)} from publication updates in existing scopes ({@link #update()}.
|
||||
*
|
||||
*
|
||||
* @author Fabio Simeoni
|
||||
*
|
||||
*/
|
||||
public class ServicePublisher extends AbstractProfilePublisher<GCoreEndpoint> {
|
||||
|
||||
private final ApplicationContext context;
|
||||
|
||||
public ServicePublisher(ApplicationContext context) {
|
||||
super();
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
|
||||
protected void sharePublished(HostingNode profile) {
|
||||
context.events().fire(profile,ProfileEvents.published);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected GCoreEndpoint getProfile() {
|
||||
return context.profile();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected boolean isRoot() {
|
||||
return context.container().configuration().mode()!=Mode.root;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void sharePublished(GCoreEndpoint profile) {
|
||||
context.events().fire(profile,ProfileEvents.published);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Set<String> getAllowedContexts() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,55 @@
|
||||
package org.gcube.smartgears.handlers.container.lifecycle;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.gcube.common.resources.gcore.HostingNode;
|
||||
import org.gcube.smartgears.configuration.Mode;
|
||||
import org.gcube.smartgears.context.container.ContainerContext;
|
||||
import org.gcube.smartgears.handlers.AbstractProfilePublisher;
|
||||
import org.gcube.smartgears.handlers.ProfileEvents;
|
||||
|
||||
/**
|
||||
* Publishes the resource profile of the container.
|
||||
* <p>
|
||||
* Distinguishes publication in new scopes ({@link #addTo(List)} from publication updates in existing scopes ({@link #update(List)}.
|
||||
*
|
||||
* @author Fabio Simeoni
|
||||
*
|
||||
*/
|
||||
public class ContainerPublisher extends AbstractProfilePublisher<HostingNode> {
|
||||
|
||||
|
||||
private final ContainerContext context;
|
||||
|
||||
public ContainerPublisher(ContainerContext context) {
|
||||
super();
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
|
||||
protected void sharePublished(HostingNode profile) {
|
||||
context.events().fire(profile,ProfileEvents.published);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected HostingNode getProfile() {
|
||||
return context.profile();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected boolean isRoot() {
|
||||
return context.configuration().mode()!=Mode.root;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Set<String> getAllowedContexts() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,241 +0,0 @@
|
||||
package org.gcube.smartgears.handlers.container.lifecycle;
|
||||
|
||||
import static org.gcube.smartgears.utils.Utils.notEmpty;
|
||||
import static org.gcube.smartgears.utils.Utils.rethrowUnchecked;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.common.authorization.client.proxy.AuthorizationProxy;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.resources.gcore.HostingNode;
|
||||
import org.gcube.informationsystem.publisher.ScopedPublisher;
|
||||
import org.gcube.smartgears.configuration.Mode;
|
||||
import org.gcube.smartgears.context.container.ContainerContext;
|
||||
import org.gcube.smartgears.handlers.ProfileEvents;
|
||||
import org.gcube.smartgears.handlers.ProfilePublisher;
|
||||
import org.gcube.smartgears.provider.ProviderFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Publishes the resource profile of the container.
|
||||
* <p>
|
||||
* Distinguishes publication in new scopes ({@link #addTo(List)} from publication updates in existing scopes ({@link #update(List)}.
|
||||
*
|
||||
* @author Fabio Simeoni
|
||||
*
|
||||
*/
|
||||
public class ProfilePublisherImpl implements ProfilePublisher {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(ProfilePublisherImpl.class);
|
||||
|
||||
//the underlying IS publisher
|
||||
private final ScopedPublisher publisher;
|
||||
//private final AuthorizationProvider authorization;
|
||||
private final ContainerContext context;
|
||||
|
||||
private AuthorizationProxy authProxy ;
|
||||
|
||||
/**
|
||||
* Creates an instance for the container.
|
||||
* @param context the context of the application
|
||||
*/
|
||||
public ProfilePublisherImpl(ContainerContext context) {
|
||||
this.context = context;
|
||||
this.publisher=ProviderFactory.provider().publisherFor(context);
|
||||
this.authProxy = ProviderFactory.provider().authorizationProxy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the current resource profile of the application in one or more
|
||||
* scopes. The scopes are retrieved from tokens
|
||||
* @param tokens the tokens
|
||||
*/
|
||||
public void addTo(Collection<String> tokens) {
|
||||
|
||||
notEmpty("tokens",tokens);
|
||||
|
||||
log.info("publishing container with tokens {}", tokens);
|
||||
|
||||
HostingNode profile = context.profile(HostingNode.class);
|
||||
|
||||
/* TODO: reintroduce it when scope will be removed
|
||||
//TODO: remove when move to new IS
|
||||
Collection<String> retainedContexts = new ArrayList<String>(context.configuration().allowedContexts());
|
||||
retainedContexts.removeAll(profile.scopes().asCollection());
|
||||
profile.scopes().asCollection().addAll(retainedContexts);
|
||||
|
||||
log.trace("profile scopes on create are {} ",profile.scopes().asCollection());
|
||||
|
||||
String previousToken = SecurityTokenProvider.instance.get();
|
||||
|
||||
try {
|
||||
for (String token: tokens){
|
||||
log.info("creating profile with token {}", token);
|
||||
SecurityTokenProvider.instance.set(token);
|
||||
profile = publisher.create(profile);
|
||||
SecurityTokenProvider.instance.reset();
|
||||
}
|
||||
|
||||
update();
|
||||
|
||||
} catch (Exception e) {
|
||||
log.warn("error adding scopes",e);
|
||||
rethrowUnchecked(e);
|
||||
|
||||
} finally{
|
||||
SecurityTokenProvider.instance.set(previousToken);
|
||||
}*/
|
||||
|
||||
ClassLoader contextCL = Thread.currentThread().getContextClassLoader();
|
||||
log.debug("using context {}",contextCL.getClass().getSimpleName());
|
||||
String previousToken = SecurityTokenProvider.instance.get();
|
||||
try{//This classloader set is needed for the jaxb context
|
||||
if (previousToken==null)
|
||||
SecurityTokenProvider.instance.set((String)tokens.toArray()[0]);
|
||||
if (context.configuration().mode()!=Mode.root)
|
||||
Thread.currentThread().setContextClassLoader(ProfilePublisherImpl.class.getClassLoader());
|
||||
profile = publisher.create(profile, resolveScopesFromTokens(tokens));
|
||||
} catch (Exception e) {
|
||||
rethrowUnchecked(e);
|
||||
} finally {
|
||||
SecurityTokenProvider.instance.set(previousToken);
|
||||
if (context.configuration().mode()!=Mode.root)
|
||||
Thread.currentThread().setContextClassLoader(contextCL);
|
||||
}
|
||||
|
||||
sharePublished(profile);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the current resource profile of the application in one or more scopes.
|
||||
*/
|
||||
public void addToAll() {
|
||||
addTo(context.configuration().startTokens());
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the current resource profile of the application in its current scopes.
|
||||
*/
|
||||
public void update() {
|
||||
|
||||
HostingNode profile = context.profile(HostingNode.class);
|
||||
/* TODO: reintroduce it when scope will be removed
|
||||
Collection<String> tokens = context.configuration().startTokens();
|
||||
|
||||
log.info("updating container with tokens {}", tokens);
|
||||
|
||||
String previousToken = SecurityTokenProvider.instance.get();
|
||||
|
||||
try {
|
||||
for (String token: tokens){
|
||||
SecurityTokenProvider.instance.set(token);
|
||||
profile = publisher.update(profile);
|
||||
SecurityTokenProvider.instance.reset();
|
||||
}
|
||||
sharePublished(profile);
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.warn("error updating container",e);
|
||||
rethrowUnchecked(e);
|
||||
|
||||
} finally{
|
||||
SecurityTokenProvider.instance.set(previousToken);
|
||||
}*/
|
||||
|
||||
|
||||
log.debug("[update] resource scopes are : {} ",profile.scopes().asCollection());
|
||||
|
||||
ClassLoader contextCL = Thread.currentThread().getContextClassLoader();
|
||||
log.debug("using context {}",contextCL.getClass().getSimpleName());
|
||||
String previousToken = SecurityTokenProvider.instance.get();
|
||||
try{//This classloader set is needed for the jaxb context
|
||||
if (previousToken==null)
|
||||
SecurityTokenProvider.instance.set((String)context.configuration().startTokens().toArray()[0]);
|
||||
|
||||
if (context.configuration().mode()!=Mode.root)
|
||||
Thread.currentThread().setContextClassLoader(ProfilePublisherImpl.class.getClassLoader());
|
||||
profile = publisher.update(profile);
|
||||
} catch (Exception e) {
|
||||
rethrowUnchecked(e);
|
||||
} finally {
|
||||
SecurityTokenProvider.instance.set(previousToken);
|
||||
if (context.configuration().mode()!=Mode.root)
|
||||
Thread.currentThread().setContextClassLoader(contextCL);
|
||||
}
|
||||
|
||||
sharePublished(profile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the container from one or more scopes.
|
||||
* @param tokens the tokens
|
||||
*/
|
||||
public void removeFrom(Collection<String> tokens) {
|
||||
|
||||
HostingNode profile = context.profile(HostingNode.class);
|
||||
|
||||
log.info("removing container with tokens {}", tokens);
|
||||
|
||||
/* TODO: reintroduce it when scope will be removed
|
||||
String previousToken = SecurityTokenProvider.instance.get();
|
||||
|
||||
try {
|
||||
|
||||
for (String token: tokens){
|
||||
SecurityTokenProvider.instance.set(token);
|
||||
profile = publisher.remove(profile);
|
||||
SecurityTokenProvider.instance.reset();
|
||||
}
|
||||
|
||||
update();
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.warn("error removing scopes",e);
|
||||
rethrowUnchecked(e);
|
||||
|
||||
} finally{
|
||||
SecurityTokenProvider.instance.set(previousToken);
|
||||
} */
|
||||
|
||||
ClassLoader contextCL = Thread.currentThread().getContextClassLoader();
|
||||
log.debug("using context {}",contextCL.getClass().getSimpleName());
|
||||
String previousToken = SecurityTokenProvider.instance.get();
|
||||
try{//This classloader set is needed for the jaxb context
|
||||
if (previousToken==null)
|
||||
SecurityTokenProvider.instance.set((String)tokens.toArray()[0]);
|
||||
if (context.configuration().mode()!=Mode.root)
|
||||
Thread.currentThread().setContextClassLoader(ProfilePublisherImpl.class.getClassLoader());
|
||||
profile = publisher.remove(profile, resolveScopesFromTokens(tokens));
|
||||
} catch (Exception e) {
|
||||
rethrowUnchecked(e);
|
||||
} finally {
|
||||
SecurityTokenProvider.instance.set(previousToken);
|
||||
if (context.configuration().mode()!=Mode.root)
|
||||
Thread.currentThread().setContextClassLoader(contextCL);
|
||||
}
|
||||
|
||||
log.debug("after remove container profile contains scopes {}",profile.scopes().asCollection());
|
||||
sharePublished(profile);
|
||||
}
|
||||
|
||||
private void sharePublished(HostingNode profile) {
|
||||
context.events().fire(profile,ProfileEvents.published);
|
||||
}
|
||||
|
||||
private List<String> resolveScopesFromTokens(Collection<String> tokens){
|
||||
List<String> scopes = new ArrayList<String>(tokens.size());
|
||||
for (String token: tokens)
|
||||
try{
|
||||
scopes.add(this.authProxy.get(token).getContext());
|
||||
}catch (Exception e) {
|
||||
log.warn("error retrieving token {} , it should never happen",token);
|
||||
}
|
||||
return scopes;
|
||||
}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
package org.gcube.smartgears.security;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
public interface AuthorizationProvider {
|
||||
|
||||
void connect(Credentials credentials) throws Exception;
|
||||
|
||||
Collection<String> getAllowedContexts();
|
||||
Set<String> getAllowedContexts();
|
||||
}
|
||||
|
@ -1,37 +0,0 @@
|
||||
package test;
|
||||
|
||||
import static junit.framework.Assert.*;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
||||
import org.gcube.smartgears.configuration.library.SmartGearsConfiguration;
|
||||
import org.gcube.smartgears.configuration.library.SmartGearsConfigurationBinder;
|
||||
import org.junit.Test;
|
||||
|
||||
public class SmartgearsConfigurationTest {
|
||||
|
||||
@Test
|
||||
public void configurationBinds() throws Exception {
|
||||
|
||||
String xml = "<smartgears version='1.0.0-SNAPSHOT'/>";
|
||||
|
||||
SmartGearsConfigurationBinder binder = new SmartGearsConfigurationBinder();
|
||||
|
||||
SmartGearsConfiguration bound = binder.bind(new ByteArrayInputStream(xml.getBytes()));
|
||||
|
||||
bound.validate();
|
||||
|
||||
String version = bound.version();
|
||||
assertEquals("1.0.0-SNAPSHOT",version);
|
||||
|
||||
assertEquals(sampleSmartgearsConfiguration(),bound);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private SmartGearsConfiguration sampleSmartgearsConfiguration() {
|
||||
|
||||
return new SmartGearsConfiguration().version("1.0.0-SNAPSHOT");
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue