2013-12-12 16:59:25 +01:00
|
|
|
package org.gcube.vremanagement.whnmanager.jaxws.ws;
|
|
|
|
|
|
|
|
import javax.jws.WebService;
|
2015-07-03 14:40:26 +02:00
|
|
|
|
2022-06-10 18:33:29 +02:00
|
|
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
|
|
|
import org.gcube.common.security.secrets.Secret;
|
2013-12-12 16:59:25 +01:00
|
|
|
import org.gcube.resourcemanagement.whnmanager.api.WhnManager;
|
2016-09-06 15:17:53 +02:00
|
|
|
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;
|
2013-12-12 16:59:25 +01:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2016-09-06 15:17:53 +02:00
|
|
|
//import org.gcube.common.calls.jaxws.Constants;
|
2013-12-12 16:59:25 +01:00
|
|
|
|
|
|
|
@WebService(portName = "WhnManagerIOPort",
|
|
|
|
serviceName = WhnManager.SERVICE_NAME,
|
|
|
|
targetNamespace = WhnManager.TNS,
|
|
|
|
endpointInterface = "org.gcube.resourcemanagement.whnmanager.api.WhnManager" )
|
|
|
|
//@Singleton
|
|
|
|
public class WhnManagerImpl implements WhnManager{
|
|
|
|
|
2016-09-06 15:17:53 +02:00
|
|
|
|
2013-12-12 16:59:25 +01:00
|
|
|
private static Logger logger=LoggerFactory.getLogger(WhnManagerImpl.class);
|
2022-06-10 18:33:29 +02:00
|
|
|
|
2013-12-12 16:59:25 +01:00
|
|
|
/**
|
|
|
|
* Add a scope to the ghn profile and publish it on IS
|
|
|
|
*/
|
|
|
|
@Override
|
2016-09-06 15:17:53 +02:00
|
|
|
public boolean addToContext(String context) throws GCUBEUnrecoverableException{
|
2022-06-10 18:33:29 +02:00
|
|
|
Secret secret = SecretManagerProvider.instance.get();
|
|
|
|
logger.trace("WHNManager: addToContext method invokation with parameters context :{} and caller: {} curentContext: {}",context, secret.getOwner().getId(), secret.getContext() );
|
2016-09-06 15:17:53 +02:00
|
|
|
ValidationUtils.valid("context", context);
|
|
|
|
ApplicationContext appContext = ContextProvider.get();
|
2013-12-12 16:59:25 +01:00
|
|
|
if(context!=null){
|
2022-06-10 18:33:29 +02:00
|
|
|
//TODO must add client id to new context
|
|
|
|
appContext.container().events().fire(context, ContextEvents.ADD_CONTEXT_TO_CONTAINER);
|
2013-12-12 16:59:25 +01:00
|
|
|
}else{
|
2016-09-06 15:17:53 +02:00
|
|
|
logger.error("context is null");
|
|
|
|
return false;
|
2013-12-12 16:59:25 +01:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a scope from ghn profile and publish the new profile on IS
|
|
|
|
*/
|
|
|
|
@Override
|
2016-09-06 15:17:53 +02:00
|
|
|
public boolean removeFromContext(String context) throws GCUBEUnrecoverableException {
|
2022-06-10 18:33:29 +02:00
|
|
|
Secret secret = SecretManagerProvider.instance.get();
|
|
|
|
logger.trace("WHNManager: removeFromContext method invokation with parameters context :{} and caller: {} curentContext: {}",context, secret.getOwner().getId(), secret.getContext());
|
2016-09-06 15:17:53 +02:00
|
|
|
ValidationUtils.valid("context", context);
|
|
|
|
ApplicationContext appContext = ContextProvider.get();
|
2013-12-12 16:59:25 +01:00
|
|
|
if(context!=null){
|
2022-06-10 18:33:29 +02:00
|
|
|
logger.trace("allowed container in context are {} ",appContext.container().configuration().authorizationProvider().getContexts());
|
|
|
|
appContext.container().events().fire(context, ContextEvents.REMOVE_CONTEXT_FROM_CONTAINER);
|
2013-12-12 16:59:25 +01:00
|
|
|
}else{
|
2016-09-06 15:17:53 +02:00
|
|
|
logger.error("context is null");
|
|
|
|
return false;
|
2013-12-12 16:59:25 +01:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2015-07-03 14:40:26 +02:00
|
|
|
|
2016-09-06 15:17:53 +02:00
|
|
|
|
2013-12-12 16:59:25 +01:00
|
|
|
}
|