Author: ozizka(a)redhat.com
Date: 2009-07-22 20:15:52 -0400 (Wed, 22 Jul 2009)
New Revision: 577
Added:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/ProfileServiceUtils.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/jaas/SecuredProfileServiceAccess.java
Removed:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/jaas/JaasUtils.java
Modified:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/AppConstants.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as4/DatasourceTest.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/app/ear/ProfileServiceTest.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/hbn/HibernateTest.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/jbcache/JBossCacheTest.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EmbJoprTestToolkit.java
Log:
* ProfileService access refactored.
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/AppConstants.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/AppConstants.java 2009-07-22
19:24:37 UTC (rev 576)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/AppConstants.java 2009-07-23
00:15:52 UTC (rev 577)
@@ -55,7 +55,7 @@
EMB_WAR(AppConstants.NAV_EMB_WAR,"Embbedded WAR", "",
".war", null, "application/war"),
// TODO: Create a superclass for non-app resource types - ResourceTypes.
- JBCACHE(AppConstants.NAV_JBCACHE, "JBoss Cache", null, null, null,
null),
+ JBCACHE(AppConstants.NAV_JBCACHE, "Jboss Cache", null, null, null,
null), // TODO: Should be JBoss
HBN(AppConstants.NAV_HBN, "Hibernate", null, null, null,
null);
@@ -147,6 +147,7 @@
public static final String NAV_SBMS = "Service Binding Managers";
public static final String NAV_SBM = "ServiceBindingManager";
public static final String NAV_JBCACHE = "JBoss Cache";
+ public static final String NAV_JBCACHES = "Jboss Caches";
public static final String NAV_HBN = "Hibernate";
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java 2009-07-22
19:24:37 UTC (rev 576)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java 2009-07-23
00:15:52 UTC (rev 577)
@@ -48,7 +48,7 @@
import org.jboss.jopr.jsfunit.exceptions.EmbJoprTestException;
import org.jboss.jopr.jsfunit.exceptions.HtmlElementNotFoundException;
import org.jboss.jopr.jsfunit.util.EmbJoprTestToolkit;
-import org.jboss.jopr.jsfunit.util.jaas.JaasUtils;
+import org.jboss.jopr.jsfunit.util.jaas.SecuredProfileServiceAccess;
/**
@@ -95,7 +95,7 @@
* created each time a test is run.
*/
@Override
- public void setUp() throws IOException
+ public void setUp() throws IOException, EmbJoprTestException
{
// Announce this test in the JBoss log.
@@ -982,9 +982,13 @@
*/
protected ManagedComponent getManagedComponent(String componentName,
ComponentType type) throws Exception
{
- return getManagedComponent(componentName, type, false);
+ return getManagedComponent(componentName, type, true);
}
+ /**
+ * Return a ManagedComponent, given the component name and type.
+ * @param secured If true, uses JAAS secured access to ProfileService etc.
+ */
protected ManagedComponent getManagedComponent(String componentName,
ComponentType type, boolean secured)
throws Exception {
@@ -1032,7 +1036,7 @@
protected ProfileService getProfileServiceSecured()
{
try {
- return JaasUtils.getInstance().getProfileService();
+ return SecuredProfileServiceAccess.getInstance().getProfileService();
} catch (NamingException ex) {
// Farah's methods don't propagate exceptions -> report and swallow.
log.error("Can't get secured ProfileService: " + ex.toString(), ex);
@@ -1067,14 +1071,16 @@
* Get the current profile view.
* @param secured If true, returns JAAS profile view of secured profile service.
*/
- protected ManagementView getCurrentProfileView( boolean secured ){ return secured ?
getCurrentProfileViewSecured() : getCurrentProfileView(); }
+ protected ManagementView getCurrentProfileView( boolean secured ){
+ return secured ? getCurrentProfileView() : getCurrentProfileViewUnsecured();
+ }
/**
* Get the current profile view.
*/
- protected ManagementView getCurrentProfileViewSecured(){
+ protected ManagementView getCurrentProfileView(){
try {
- ManagementView view = JaasUtils.getInstance().getManagementView();
+ ManagementView view = SecuredProfileServiceAccess.getInstance().getManagementView();
view.load();
return view;
} catch (NamingException ex) {
@@ -1083,7 +1089,7 @@
}
}
- protected ManagementView getCurrentProfileView()
+ protected ManagementView getCurrentProfileViewUnsecured()
{
ProfileService profileService = getProfileService();
ManagementView currentProfileView = profileService.getViewManager();
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as4/DatasourceTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as4/DatasourceTest.java 2009-07-22
19:24:37 UTC (rev 576)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as4/DatasourceTest.java 2009-07-23
00:15:52 UTC (rev 577)
@@ -47,13 +47,6 @@
public class DatasourceTest extends org.jboss.jopr.jsfunit.DatasourceTestBase {
- @Override
- public void setUp() throws IOException {
- super.setUp();
- }
-
-
-
/**
* Create a new datasource using the given template and properties.
*
Modified:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/app/ear/ProfileServiceTest.java
===================================================================
---
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/app/ear/ProfileServiceTest.java 2009-07-22
19:24:37 UTC (rev 576)
+++
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/app/ear/ProfileServiceTest.java 2009-07-23
00:15:52 UTC (rev 577)
@@ -29,11 +29,13 @@
import javax.naming.InitialContext;
import javax.naming.NamingException;
+import junit.framework.Test;
+import junit.framework.TestSuite;
import org.jboss.deployers.spi.management.ManagementView;
import org.jboss.deployers.spi.management.deploy.DeploymentManager;
import org.jboss.deployers.spi.management.deploy.DeploymentProgress;
import org.jboss.jopr.jsfunit.EmbjoprTestCase;
-import org.jboss.jopr.jsfunit.util.jaas.JaasUtils;
+import org.jboss.jopr.jsfunit.util.jaas.SecuredProfileServiceAccess;
import org.jboss.managed.api.ComponentType;
import org.jboss.managed.api.DeploymentTemplateInfo;
import org.jboss.managed.api.ManagedComponent;
@@ -41,8 +43,6 @@
import org.jboss.metatype.api.values.MetaValue;
import org.jboss.metatype.api.values.MetaValueFactory;
import org.jboss.profileservice.spi.ProfileKey;
-import org.jboss.profileservice.spi.ProfileService;
-import org.jboss.virtual.VFS;
@@ -60,7 +60,8 @@
protected DeploymentManager deployMgr;
private MetaValueFactory metaValueFactory;
- public ProfileServiceTest(String name){
+
+ public ProfileServiceTest(String name){
super();
}
public ProfileServiceTest(){
@@ -68,11 +69,19 @@
}
+ public static Test suite(){
+ return new TestSuite(EarStressTest.class);
+ }
+
+
+
+
+
/**
* List the contents of ProfileService.
*/
public void testProfileServiceListContent() throws NamingException, Exception{
- ManagementView managementView = JaasUtils.getInstance().getManagementView();
+ ManagementView managementView =
SecuredProfileServiceAccess.getInstance().getManagementView();
log.info("List of ProfileService contents (default profile):");
@@ -222,7 +231,7 @@
return activeView;
/**/
- return JaasUtils.getInstance().getManagementView();
+ return SecuredProfileServiceAccess.getInstance().getManagementView();
}
/**
* Obtain the ProfileService.ManagementView
@@ -244,7 +253,7 @@
}
return deployMgr;
/**/
- return JaasUtils.getInstance().getDeploymentManager();
+ return SecuredProfileServiceAccess.getInstance().getDeploymentManager();
}
/**
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/hbn/HibernateTest.java
===================================================================
---
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/hbn/HibernateTest.java 2009-07-22
19:24:37 UTC (rev 576)
+++
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/hbn/HibernateTest.java 2009-07-23
00:15:52 UTC (rev 577)
@@ -17,6 +17,14 @@
+ public void testHibernateParentNode() throws HtmlElementNotFoundException {
+ fail("Hibernate not present yet.");
+
+ ejtt.navTree.getNodeByLabel(APP_TYPE.getNavTreeLabel());
+ }
+
+
+
public void testHibernateSummary() throws HtmlElementNotFoundException {
fail("Hibernate not present yet.");
Modified:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/jbcache/JBossCacheTest.java
===================================================================
---
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/jbcache/JBossCacheTest.java 2009-07-22
19:24:37 UTC (rev 576)
+++
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/jbcache/JBossCacheTest.java 2009-07-23
00:15:52 UTC (rev 577)
@@ -17,10 +17,15 @@
- public void testHibernateSummary() throws HtmlElementNotFoundException {
+ public void testJBossCacheParentNode() throws HtmlElementNotFoundException {
+ ejtt.navTree.getNodeByLabel(APP_TYPE.getNavTreeLabel());
fail("JBoss Cache not present yet.");
+ }
+
+ public void testHibernateSummary() throws HtmlElementNotFoundException {
ejtt.navTree.getNodeByLabel(APP_TYPE.getNavTreeLabel());
+ fail("JBoss Cache not present yet.");
}
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EmbJoprTestToolkit.java
===================================================================
---
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EmbJoprTestToolkit.java 2009-07-22
19:24:37 UTC (rev 576)
+++
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EmbJoprTestToolkit.java 2009-07-23
00:15:52 UTC (rev 577)
@@ -9,6 +9,7 @@
import java.util.logging.Level;
import javax.management.MalformedObjectNameException;
+import javax.naming.NamingException;
import org.jboss.jopr.jsfunit.exceptions.*;
import com.gargoylesoftware.htmlunit.html.*;
import com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine;
@@ -60,19 +61,34 @@
public JSFServerSession getServer() { return server; }
- public EmbJoprTestToolkit(JSFClientSession client, JSFServerSession server) {
+ public EmbJoprTestToolkit(JSFClientSession client, JSFServerSession server) throws
EmbJoprTestException {
this.client = client;
this.server = server;
this.selfEjtt = this;
+
+ try {
+ profileService = new ProfileServiceUtils(true); // TODO: Make "secured"
configurable in POM.
+ } catch (NamingException ex) {
+ String message = "Error when initializing ProfileService: "+ex;
+ log.fatal( message );
+ throw new EmbJoprTestException(message, ex);
+ }
}
+
+ /** Used in inner classes (they can't use this). */
public EmbJoprTestToolkit getEjtt(){ return this; }
- private EmbjoprTestCase currentTest = null;
+ /** Returns information about current test being run. Filled before each test method (in
setUp()). */
public EmbjoprTestCase getCurrentTest() { return currentTest; }
public void setCurrentTest(EmbjoprTestCase currentTest) { this.currentTest =
currentTest; }
+ private EmbjoprTestCase currentTest = null;
+ /**
+ * ProfileService references.
+ */
+ public final ProfileServiceUtils profileService;
/**
@@ -2183,38 +2199,4 @@
-
- // TODO
- protected class JMXDeploymentInfo {
-
- // Etc...
- public boolean isDeployed(){
- return false;
- }
-
- }
-
- // TODO
- protected class FileDeploymentInfo {
-
- // Etc...
- public boolean isDeployed(){
- return false;
- }
-
- }
-
- // TODO
- protected class EmbJoprDeploymentInfo {
-
- // Etc...
- public boolean isDeployed(){
- return false;
- }
-
- }
-
-
-
-
}// class EmbJoprTestToolkit
Added: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/ProfileServiceUtils.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/ProfileServiceUtils.java
(rev 0)
+++
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/ProfileServiceUtils.java 2009-07-23
00:15:52 UTC (rev 577)
@@ -0,0 +1,49 @@
+package org.jboss.jopr.jsfunit.util;
+
+import javax.naming.NamingException;
+import org.jboss.deployers.spi.management.ManagementView;
+import org.jboss.deployers.spi.management.deploy.DeploymentManager;
+import org.jboss.jopr.jsfunit.util.jaas.SecuredProfileServiceAccess;
+import org.jboss.profileservice.spi.ProfileService;
+
+
+/**
+ * Immutable class holding references to ProfileService, ManagementView and
DeploymentManager,
+ * either secured or unsecured, depending on constructor parameter.
+ * @author Ondrej Zizka
+ */
+public class ProfileServiceUtils {
+
+ // Properties
+ final ProfileService profileService;
+ final ManagementView managementView;
+ final DeploymentManager deploymentManager;
+ final boolean secured;
+
+ public DeploymentManager getDeploymentManager() { return deploymentManager; }
+ public ManagementView getManagementView() { return managementView; }
+ public ProfileService getProfileService() { return profileService; }
+ public boolean isSecured() { return secured; }
+
+
+
+ // Ctor.
+
+ public ProfileServiceUtils( boolean secured ) throws NamingException
+ {
+ this.secured = secured;
+
+ SecuredProfileServiceAccess jaasUtils = null;
+
+ jaasUtils = secured ? SecuredProfileServiceAccess.getSecuredInstance() :
SecuredProfileServiceAccess.getUnsecuredInstance();
+
+ // NPE will occur here if exception happens above.
+ // TODO: Move ejtt's members initialization to some init() method to avoid this
nasty thing.
+ this.profileService = jaasUtils.getProfileService();
+ this.managementView = jaasUtils.getManagementView();
+ this.deploymentManager = jaasUtils.getDeploymentManager();
+ }
+
+
+}
+// class ProfileServiceUtils
Deleted: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/jaas/JaasUtils.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/jaas/JaasUtils.java 2009-07-22
19:24:37 UTC (rev 576)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/jaas/JaasUtils.java 2009-07-23
00:15:52 UTC (rev 577)
@@ -1,114 +0,0 @@
-package org.jboss.jopr.jsfunit.util.jaas;
-
-import java.lang.reflect.Proxy;
-
-import java.util.Properties;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-
-import org.jboss.deployers.spi.management.ManagementView;
-import org.jboss.deployers.spi.management.deploy.DeploymentManager;
-import org.jboss.logging.Logger;
-import org.jboss.profileservice.spi.ProfileService;
-
-
-
-/**
- * Singleton class to keep JAAS secured ProfileService, ManagementView and
DeploymentManager.
- * Partially copied from Jopr's test.EjbClient.
- * @author Ondrej Zizka
- */
-public class JaasUtils {
-
- private static final Logger log = Logger.getLogger(JaasUtils.class);
-
- // Singleton.
- private static JaasUtils INSTANCE = null;
- public static JaasUtils getInstance() throws NamingException {
- if( null == INSTANCE ){
- INSTANCE = new JaasUtils();
- INSTANCE.init( true );
- }
- return INSTANCE;
- }
-
- private static final String JNDI_LOGIN_INITIAL_CONTEXT_FACTORY =
"org.jboss.security.jndi.JndiLoginInitialContextFactory";
- private static final String NAMING_CONTEXT_FACTORY =
"org.jnp.interfaces.NamingContextFactory";
- private static final String SECURE_PROFILE_SERVICE_JNDI_NAME =
"SecureProfileService/remote";
- private static final String SECURE_MANAGEMENT_VIEW_JNDI_NAME =
"SecureManagementView/remote";
- private static final String SECURE_DEPLOYMENT_MANAGER_JNDI_NAME =
"SecureDeploymentManager/remote";
- private static final String PROFILE_SERVICE_JNDI_NAME = "ProfileService";
- private static final String MANAGEMENT_VIEW_JNDI_NAME = "ManagementView";
- private static final String DEPLOYMENT_MANAGER_JNDI_NAME =
"DeploymentManager";
- private static final String PROFILE_SERVICE_PRINCIPAL = "admin";
- private static final String PROFILE_SERVICE_CREDENTIALS = "admin";
-
-
- ProfileService profileService;
- ManagementView managementView;
- DeploymentManager deploymentManager;
-
- public DeploymentManager getDeploymentManager() { return deploymentManager; }
- public ManagementView getManagementView() { return managementView; }
- public ProfileService getProfileService() { return profileService; }
-
-
- /**
- * Obtains ProfileService, ManagementView and DeploymentManager.
- * @param useJaas If true, all those three are secured with JAAS.
- */
- private void init(boolean useJaas) throws NamingException {
-
- Properties env = new Properties();
- env.setProperty(Context.PROVIDER_URL, "jnp://127.0.0.1:1099/");
- env.setProperty(Context.INITIAL_CONTEXT_FACTORY, NAMING_CONTEXT_FACTORY);
-
- InitialContext initialContext = createInitialContext(env);
-
-
- if (!useJaas) {
- this.profileService = (ProfileService) lookup(initialContext,
PROFILE_SERVICE_JNDI_NAME);
- this.managementView = this.profileService.getViewManager();
- this.deploymentManager = this.profileService.getDeploymentManager();
- }
- else {
- this.profileService = (ProfileService) lookup(initialContext,
PROFILE_SERVICE_JNDI_NAME);
- this.managementView = (ManagementView) lookup(initialContext,
MANAGEMENT_VIEW_JNDI_NAME);
- this.deploymentManager = (DeploymentManager) lookup(initialContext,
DEPLOYMENT_MANAGER_JNDI_NAME);
-
- //apply the jaas security
- ClassLoader classLoader = JaasUtils.class.getClassLoader();
- this.profileService = (ProfileService) Proxy.newProxyInstance(classLoader,
- new Class<?>[]{ProfileService.class},
- new JaasAuthenticationInvocationHandler( this.profileService,
PROFILE_SERVICE_PRINCIPAL, PROFILE_SERVICE_CREDENTIALS ));
-
- this.managementView = (ManagementView) Proxy.newProxyInstance(classLoader,
- new Class<?>[]{ManagementView.class},
- new JaasAuthenticationInvocationHandler( this.managementView,
PROFILE_SERVICE_PRINCIPAL, PROFILE_SERVICE_CREDENTIALS ));
-
- this.deploymentManager = (DeploymentManager) Proxy.newProxyInstance(classLoader,
- new Class<?>[]{DeploymentManager.class},
- new JaasAuthenticationInvocationHandler( this.deploymentManager,
PROFILE_SERVICE_PRINCIPAL, PROFILE_SERVICE_CREDENTIALS ));
- }
-
- // This must be called before the other ManagementView operations may be used.
- this.managementView.load();
- }
-
-
- private static InitialContext createInitialContext(Properties env) throws
NamingException {
- log.info("Creating JNDI InitialContext with env [" + env +
"]...");
- InitialContext initialContext = new InitialContext(env);
- log.info("Created JNDI InitialContext [" + initialContext + "].");
- return initialContext;
- }
-
- private static Object lookup(InitialContext initialContext, String name) throws
NamingException {
- log.info("Looking up name '" + name + "' from
InitialContext...");
- Object obj = initialContext.lookup(name);
- log.info("Found Object: " + obj);
- return obj;
- }
-}// class
Copied:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/jaas/SecuredProfileServiceAccess.java
(from rev 568,
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/jaas/JaasUtils.java)
===================================================================
---
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/jaas/SecuredProfileServiceAccess.java
(rev 0)
+++
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/jaas/SecuredProfileServiceAccess.java 2009-07-23
00:15:52 UTC (rev 577)
@@ -0,0 +1,127 @@
+package org.jboss.jopr.jsfunit.util.jaas;
+
+import java.lang.reflect.Proxy;
+
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.jboss.deployers.spi.management.ManagementView;
+import org.jboss.deployers.spi.management.deploy.DeploymentManager;
+import org.jboss.logging.Logger;
+import org.jboss.profileservice.spi.ProfileService;
+
+
+
+/**
+ * Singleton class to keep JAAS secured ProfileService, ManagementView and
DeploymentManager.
+ * Partially copied from Jopr's test.EjbClient.
+ * @author Ondrej Zizka
+ *
+ */
+public class SecuredProfileServiceAccess {
+
+ private static final Logger log = Logger.getLogger(SecuredProfileServiceAccess.class);
+
+ // Singleton.
+ private static SecuredProfileServiceAccess INSTANCE_SECURED = null;
+ private static SecuredProfileServiceAccess INSTANCE_UNSECURED = null;
+
+ public static SecuredProfileServiceAccess getInstance() throws NamingException { return
getSecuredInstance(); }
+
+ public static SecuredProfileServiceAccess getSecuredInstance() throws NamingException {
+ if( null == INSTANCE_SECURED ){
+ INSTANCE_SECURED = new SecuredProfileServiceAccess();
+ INSTANCE_SECURED.init( true );
+ }
+ return INSTANCE_SECURED;
+ }
+
+ public static SecuredProfileServiceAccess getUnsecuredInstance() throws NamingException
{
+ if( null == INSTANCE_UNSECURED ){
+ INSTANCE_UNSECURED = new SecuredProfileServiceAccess();
+ INSTANCE_UNSECURED.init( false );
+ }
+ return INSTANCE_UNSECURED;
+ }
+
+ private static final String JNDI_LOGIN_INITIAL_CONTEXT_FACTORY =
"org.jboss.security.jndi.JndiLoginInitialContextFactory";
+ private static final String NAMING_CONTEXT_FACTORY =
"org.jnp.interfaces.NamingContextFactory";
+ private static final String SECURE_PROFILE_SERVICE_JNDI_NAME =
"SecureProfileService/remote";
+ private static final String SECURE_MANAGEMENT_VIEW_JNDI_NAME =
"SecureManagementView/remote";
+ private static final String SECURE_DEPLOYMENT_MANAGER_JNDI_NAME =
"SecureDeploymentManager/remote";
+ private static final String PROFILE_SERVICE_JNDI_NAME = "ProfileService";
+ private static final String MANAGEMENT_VIEW_JNDI_NAME = "ManagementView";
+ private static final String DEPLOYMENT_MANAGER_JNDI_NAME =
"DeploymentManager";
+ private static final String PROFILE_SERVICE_PRINCIPAL = "admin";
+ private static final String PROFILE_SERVICE_CREDENTIALS = "admin";
+
+
+ ProfileService profileService;
+ ManagementView managementView;
+ DeploymentManager deploymentManager;
+
+ public DeploymentManager getDeploymentManager() { return deploymentManager; }
+ public ManagementView getManagementView() { return managementView; }
+ public ProfileService getProfileService() { return profileService; }
+
+
+ /**
+ * Obtains ProfileService, ManagementView and DeploymentManager.
+ * @param useJaas If true, all those three are secured with JAAS.
+ */
+ private void init(boolean useJaas) throws NamingException {
+
+ Properties env = new Properties();
+ env.setProperty(Context.PROVIDER_URL, "jnp://127.0.0.1:1099/");
+ env.setProperty(Context.INITIAL_CONTEXT_FACTORY, NAMING_CONTEXT_FACTORY);
+
+ InitialContext initialContext = createInitialContext(env);
+
+
+ if (!useJaas) {
+ this.profileService = (ProfileService) lookup(initialContext,
PROFILE_SERVICE_JNDI_NAME);
+ this.managementView = this.profileService.getViewManager();
+ this.deploymentManager = this.profileService.getDeploymentManager();
+ }
+ else {
+ this.profileService = (ProfileService) lookup(initialContext,
PROFILE_SERVICE_JNDI_NAME);
+ this.managementView = (ManagementView) lookup(initialContext,
MANAGEMENT_VIEW_JNDI_NAME);
+ this.deploymentManager = (DeploymentManager) lookup(initialContext,
DEPLOYMENT_MANAGER_JNDI_NAME);
+
+ //apply the jaas security
+ ClassLoader classLoader = SecuredProfileServiceAccess.class.getClassLoader();
+ this.profileService = (ProfileService) Proxy.newProxyInstance(classLoader,
+ new Class<?>[]{ProfileService.class},
+ new JaasAuthenticationInvocationHandler( this.profileService,
PROFILE_SERVICE_PRINCIPAL, PROFILE_SERVICE_CREDENTIALS ));
+
+ this.managementView = (ManagementView) Proxy.newProxyInstance(classLoader,
+ new Class<?>[]{ManagementView.class},
+ new JaasAuthenticationInvocationHandler( this.managementView,
PROFILE_SERVICE_PRINCIPAL, PROFILE_SERVICE_CREDENTIALS ));
+
+ this.deploymentManager = (DeploymentManager) Proxy.newProxyInstance(classLoader,
+ new Class<?>[]{DeploymentManager.class},
+ new JaasAuthenticationInvocationHandler( this.deploymentManager,
PROFILE_SERVICE_PRINCIPAL, PROFILE_SERVICE_CREDENTIALS ));
+ }
+
+ // This must be called before the other ManagementView operations may be used.
+ this.managementView.load();
+ }
+
+
+ private static InitialContext createInitialContext(Properties env) throws
NamingException {
+ log.info("Creating JNDI InitialContext with env [" + env +
"]...");
+ InitialContext initialContext = new InitialContext(env);
+ log.info("Created JNDI InitialContext [" + initialContext + "].");
+ return initialContext;
+ }
+
+ private static Object lookup(InitialContext initialContext, String name) throws
NamingException {
+ log.info("Looking up name '" + name + "' from
InitialContext...");
+ Object obj = initialContext.lookup(name);
+ log.info("Found Object: " + obj);
+ return obj;
+ }
+}// class