2011-07-22 04:57:52 +02:00
|
|
|
package org.gcube.informationsystem.registry.testsuite.security;
|
|
|
|
|
|
|
|
import org.gcube.common.core.security.GCUBEClientSecurityManager;
|
|
|
|
import org.gcube.common.core.security.GCUBESecurityManager;
|
|
|
|
import org.gcube.common.core.security.GCUBESecurityManagerImpl;
|
|
|
|
import org.gcube.common.core.security.context.SecurityContextFactory;
|
2011-08-02 16:38:51 +02:00
|
|
|
import org.gcube.common.core.utils.logging.GCUBEClientLog;
|
2011-07-22 04:57:52 +02:00
|
|
|
|
2011-08-02 16:38:51 +02:00
|
|
|
public class Utils {
|
2011-07-22 04:57:52 +02:00
|
|
|
public static GCUBESecurityManager generateAndConfigureDefaultSecurityManager (String identity, final boolean isSecurityEnabled)
|
|
|
|
{
|
2011-08-02 16:38:51 +02:00
|
|
|
GCUBEClientLog logger = new GCUBEClientLog(Utils.class);
|
2011-07-22 04:57:52 +02:00
|
|
|
|
|
|
|
GCUBESecurityManager securityManager = null;
|
|
|
|
|
|
|
|
if (isSecurityEnabled)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
securityManager = SecurityContextFactory.getInstance().getSecurityContext().getDefaultSecurityManager();
|
|
|
|
logger.debug("Identity = "+identity);
|
|
|
|
((GCUBEClientSecurityManager) securityManager).setDefaultIdentityParameter(identity);
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("Unable to generate default security manager: trying without security...",e);
|
|
|
|
securityManager = new GCUBESecurityManagerImpl() {
|
|
|
|
public boolean isSecurityEnabled() {return isSecurityEnabled;}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
securityManager = new GCUBESecurityManagerImpl() {
|
|
|
|
public boolean isSecurityEnabled() {return isSecurityEnabled;}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return securityManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|