whn-manager/src/main/java/org/gcube/vremanagement/whnmanager/jaxws/ws/WhnManagerImpl.java

67 lines
2.6 KiB
Java

package org.gcube.vremanagement.whnmanager.jaxws.ws;
import javax.jws.WebService;
import org.gcube.common.security.providers.SecretManagerProvider;
import org.gcube.common.security.secrets.Secret;
import org.gcube.resourcemanagement.whnmanager.api.WhnManager;
import org.gcube.resourcemanagement.whnmanager.api.exception.GCUBEUnrecoverableException;
import org.gcube.smartgears.ContextProvider;
import org.gcube.smartgears.context.application.ApplicationContext;
import org.gcube.smartgears.managers.ContextEvents;
import org.gcube.vremanagement.whnmanager.utils.ValidationUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
//import org.gcube.common.calls.jaxws.Constants;
@WebService(portName = "WhnManagerIOPort",
serviceName = WhnManager.SERVICE_NAME,
targetNamespace = WhnManager.TNS,
endpointInterface = "org.gcube.resourcemanagement.whnmanager.api.WhnManager" )
//@Singleton
public class WhnManagerImpl implements WhnManager{
private static Logger logger=LoggerFactory.getLogger(WhnManagerImpl.class);
/**
* Add a scope to the ghn profile and publish it on IS
*/
@Override
public boolean addToContext(String context) throws GCUBEUnrecoverableException{
Secret secret = SecretManagerProvider.instance.get();
logger.trace("WHNManager: addToContext method invokation with parameters context :{} and caller: {} curentContext: {}",context, secret.getOwner().getId(), secret.getContext() );
ValidationUtils.valid("context", context);
ApplicationContext appContext = ContextProvider.get();
if(context!=null){
//TODO must add client id to new context
appContext.container().events().fire(context, ContextEvents.ADD_CONTEXT_TO_CONTAINER);
}else{
logger.error("context is null");
return false;
}
return true;
}
/**
* Remove a scope from ghn profile and publish the new profile on IS
*/
@Override
public boolean removeFromContext(String context) throws GCUBEUnrecoverableException {
Secret secret = SecretManagerProvider.instance.get();
logger.trace("WHNManager: removeFromContext method invokation with parameters context :{} and caller: {} curentContext: {}",context, secret.getOwner().getId(), secret.getContext());
ValidationUtils.valid("context", context);
ApplicationContext appContext = ContextProvider.get();
if(context!=null){
logger.trace("allowed container in context are {} ",appContext.container().configuration().authorizationProvider().getContexts());
appContext.container().events().fire(context, ContextEvents.REMOVE_CONTEXT_FROM_CONTAINER);
}else{
logger.error("context is null");
return false;
}
return true;
}
}