geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r189719 - /geronimo/trunk/modules/client-builder/src/java/org/apache/geronimo/client/builder /geronimo/trunk/modules/client-builder/src/schema /geronimo/trunk/modules/client-builder/src/test-resources/plans /geronimo/trunk/modules/client/src/java/org/apache/geronimo/client
Date Thu, 09 Jun 2005 06:32:49 GMT
Author: djencks
Date: Wed Jun  8 23:32:48 2005
New Revision: 189719

URL: http://svn.apache.org/viewcvs?rev=189719&view=rev
Log:
GERONIMO-333, GERONIMO-415. Implement app client CallbackHandlers with a bit of enhancement

Modified:
    geronimo/trunk/modules/client-builder/src/java/org/apache/geronimo/client/builder/AppClientModuleBuilder.java
    geronimo/trunk/modules/client-builder/src/schema/geronimo-application-client.xsd
    geronimo/trunk/modules/client-builder/src/test-resources/plans/plan1.xml
    geronimo/trunk/modules/client/src/java/org/apache/geronimo/client/AppClientContainer.java

Modified: geronimo/trunk/modules/client-builder/src/java/org/apache/geronimo/client/builder/AppClientModuleBuilder.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/client-builder/src/java/org/apache/geronimo/client/builder/AppClientModuleBuilder.java?rev=189719&r1=189718&r2=189719&view=diff
==============================================================================
--- geronimo/trunk/modules/client-builder/src/java/org/apache/geronimo/client/builder/AppClientModuleBuilder.java
(original)
+++ geronimo/trunk/modules/client-builder/src/java/org/apache/geronimo/client/builder/AppClientModuleBuilder.java
Wed Jun  8 23:32:48 2005
@@ -98,17 +98,17 @@
     private final ServiceReferenceBuilder serviceReferenceBuilder;
 
     public AppClientModuleBuilder(URI defaultClientParentId,
-            URI defaultServerParentId,
-            ObjectName transactionContextManagerObjectName,
-            ObjectName connectionTrackerObjectName,
-            ObjectName corbaGBeanObjectName,
-            EJBReferenceBuilder ejbReferenceBuilder,
-            ModuleBuilder connectorModuleBuilder,
-            ResourceReferenceBuilder resourceReferenceBuilder,
-            ServiceReferenceBuilder serviceReferenceBuilder,
-            ConfigurationStore store,
-            Repository repository,
-            Kernel kernel) {
+                                  URI defaultServerParentId,
+                                  ObjectName transactionContextManagerObjectName,
+                                  ObjectName connectionTrackerObjectName,
+                                  ObjectName corbaGBeanObjectName,
+                                  EJBReferenceBuilder ejbReferenceBuilder,
+                                  ModuleBuilder connectorModuleBuilder,
+                                  ResourceReferenceBuilder resourceReferenceBuilder,
+                                  ServiceReferenceBuilder serviceReferenceBuilder,
+                                  ConfigurationStore store,
+                                  Repository repository,
+                                  Kernel kernel) {
         this.defaultClientParentId = defaultClientParentId;
         this.defaultServerParentId = defaultServerParentId;
         this.corbaGBeanObjectName = corbaGBeanObjectName;
@@ -294,7 +294,7 @@
             if (mainClasss == null) {
                 throw new DeploymentException("App client module jar does not have Main-Class
defined in the manifest: " + moduleFile.getName());
             }
-           String classPath = manifest.getMainAttributes().getValue(Attributes.Name.CLASS_PATH);
+            String classPath = manifest.getMainAttributes().getValue(Attributes.Name.CLASS_PATH);
             if (module.isStandAlone() && classPath != null) {
                 throw new DeploymentException("Manifest class path entry is not allowed in
a standalone jar (J2EE 1.4 Section 8.2)");
             }
@@ -468,10 +468,27 @@
                 try {
                     appClientContainerGBeanData.setAttribute("mainClassName", mainClasss);
                     appClientContainerGBeanData.setAttribute("appClientModuleName", appClientModuleName);
-                    if (geronimoAppClient.isSetDefaultPrincipal()) {
-                           DefaultPrincipal defaultPrincipal = SecurityBuilder.buildDefaultPrincipal(geronimoAppClient.getDefaultPrincipal());
+                    String callbackHandlerClassName = null;
+                    if (appClient.isSetCallbackHandler()) {
+                        callbackHandlerClassName = appClient.getCallbackHandler().getStringValue().trim();
+                    }
+                    if (geronimoAppClient.isSetCallbackHandler()) {
+                        callbackHandlerClassName = geronimoAppClient.getCallbackHandler().trim();
+                    }
+                    String realmName = null;
+                    if (geronimoAppClient.isSetRealmName()) {
+                        realmName = geronimoAppClient.getRealmName().trim();
+                    }
+                    if (callbackHandlerClassName != null && realmName == null) {
+                        throw new DeploymentException("You must specify a realm name with
the callback handler");
+                    }
+                    if (realmName != null) {
+                        appClientContainerGBeanData.setAttribute("realmName", realmName);
+                        appClientContainerGBeanData.setAttribute("callbackHandlerClassName",
callbackHandlerClassName);
+                    } else if (geronimoAppClient.isSetDefaultPrincipal()) {
+                        DefaultPrincipal defaultPrincipal = SecurityBuilder.buildDefaultPrincipal(geronimoAppClient.getDefaultPrincipal());
                         appClientContainerGBeanData.setAttribute("defaultPrincipal", defaultPrincipal);
-                       }
+                    }
                     appClientContainerGBeanData.setReferencePattern("JNDIContext", jndiContextName);
                     appClientContainerGBeanData.setReferencePattern("TransactionContextManager",
transactionContextManagerObjectName);
                 } catch (Exception e) {

Modified: geronimo/trunk/modules/client-builder/src/schema/geronimo-application-client.xsd
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/client-builder/src/schema/geronimo-application-client.xsd?rev=189719&r1=189718&r2=189719&view=diff
==============================================================================
--- geronimo/trunk/modules/client-builder/src/schema/geronimo-application-client.xsd (original)
+++ geronimo/trunk/modules/client-builder/src/schema/geronimo-application-client.xsd Wed Jun
 8 23:32:48 2005
@@ -40,12 +40,6 @@
             <xs:element name="include" type="sys:dependencyType" minOccurs="0" maxOccurs="unbounded"/>
             <xs:element ref="sys:dependency" minOccurs="0" maxOccurs="unbounded"/>
 
-            <!---->
-            <!--            <xs:element name="callback-handler"-->
-            <!--                type="geronimo:fully-qualified-classType"-->
-            <!--                minOccurs="0"/>-->
-            <xs:element ref="security:default-principal" minOccurs="0"/>
-
             <!--xs:group ref="naming:jndiEnvironmentRefsGroup"/-->
 
             <xs:element ref="naming:ejb-ref" minOccurs="0" maxOccurs="unbounded"/>
@@ -53,6 +47,14 @@
             <xs:element ref="naming:service-ref" minOccurs="0" maxOccurs="unbounded"/>
             <xs:element ref="naming:resource-ref" minOccurs="0" maxOccurs="unbounded"/>
             <xs:element ref="naming:resource-env-ref" minOccurs="0" maxOccurs="unbounded"/>
+
+            <xs:element ref="security:default-principal" minOccurs="0"/>
+
+            <xs:sequence minOccurs="0">
+                <xs:element name="realm-name" type="xs:string"/>
+                <xs:element name="callback-handler" type="xs:string" minOccurs="0"/>
+            </xs:sequence>
+
 
             <xs:element name="resource" type="geronimo:resourceType" minOccurs="0" maxOccurs="unbounded"/>
 

Modified: geronimo/trunk/modules/client-builder/src/test-resources/plans/plan1.xml
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/client-builder/src/test-resources/plans/plan1.xml?rev=189719&r1=189718&r2=189719&view=diff
==============================================================================
--- geronimo/trunk/modules/client-builder/src/test-resources/plans/plan1.xml (original)
+++ geronimo/trunk/modules/client-builder/src/test-resources/plans/plan1.xml Wed Jun  8 23:32:48
2005
@@ -7,4 +7,6 @@
         <ref-name>jdbc/DB1</ref-name>
         <target-name>DefaultDatabase</target-name>
     </resource-ref>
+    <realm-name>default</realm-name>
+    <callback-handler>org.apache.geronimo.client.DefaultCallbackHandler</callback-handler>
 </application-client>

Modified: geronimo/trunk/modules/client/src/java/org/apache/geronimo/client/AppClientContainer.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/client/src/java/org/apache/geronimo/client/AppClientContainer.java?rev=189719&r1=189718&r2=189719&view=diff
==============================================================================
--- geronimo/trunk/modules/client/src/java/org/apache/geronimo/client/AppClientContainer.java
(original)
+++ geronimo/trunk/modules/client/src/java/org/apache/geronimo/client/AppClientContainer.java
Wed Jun  8 23:32:48 2005
@@ -18,8 +18,12 @@
 
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.lang.reflect.Constructor;
+import java.security.PrivilegedAction;
 import javax.management.ObjectName;
 import javax.security.auth.Subject;
+import javax.security.auth.login.LoginContext;
+import javax.security.auth.callback.CallbackHandler;
 
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
@@ -40,14 +44,18 @@
     private final String mainClassName;
     private final AppClientPlugin jndiContext;
     private final ObjectName appClientModuleName;
+    private final String realmName;
+    private final Class callbackHandlerClass;
     private final Subject defaultSubject;
     private final Method mainMethod;
     private final ClassLoader classLoader;
     private final Kernel kernel;
     private final TransactionContextManager transactionContextManager;
 
-    public AppClientContainer(String mainClassName, 
+    public AppClientContainer(String mainClassName,
                               ObjectName appClientModuleName,
+                              String realmName,
+                              String callbackHandlerClassName,
                               DefaultPrincipal defaultPrincipal,
                               AppClientPlugin jndiContext,
                               TransactionContextManager transactionContextManager,
@@ -56,6 +64,19 @@
                               ) throws Exception {
         this.mainClassName = mainClassName;
         this.appClientModuleName = appClientModuleName;
+        if ((realmName == null) != (callbackHandlerClassName == null)) {
+            throw new IllegalArgumentException("You must supply both realmName and callbackHandlerClass
or neither");
+        }
+        this.realmName = realmName;
+        if (callbackHandlerClassName != null) {
+            try {
+                this.callbackHandlerClass = classLoader.loadClass(callbackHandlerClassName);
+            } catch (ClassNotFoundException e) {
+                throw new AppClientInitializationException("Could not load callbackHandlerClass",
e);
+            }
+        } else {
+            callbackHandlerClass = null;
+        }
         if (defaultPrincipal != null) {
             defaultSubject = ConfigurationUtil.generateDefaultSubject(defaultPrincipal);
         } else {
@@ -84,20 +105,49 @@
         return mainClassName;
     }
 
-    public void main(String[] args) throws Exception {
+    public void main(final String[] args) throws Exception {
         Thread thread = Thread.currentThread();
 
         ClassLoader oldClassLoader = thread.getContextClassLoader();
         TransactionContext oldTransactionContext = transactionContextManager.getContext();
         TransactionContext currentTransactionContext = null;
         Subject oldCurrentCaller = ContextManager.getCurrentCaller();
+        Subject clientSubject = defaultSubject;
+        LoginContext loginContext = null;
         try {
             thread.setContextClassLoader(classLoader);
-            ContextManager.setCurrentCaller(defaultSubject);
+            if (callbackHandlerClass != null) {
+                //look for a constructor taking the args
+                CallbackHandler callbackHandler;
+                try {
+                    Constructor cArgs = callbackHandlerClass.getConstructor(new Class[] {String[].class});
+                    callbackHandler = (CallbackHandler) cArgs.newInstance(new Object[] {args});
+                } catch (NoSuchMethodException e) {
+                    callbackHandler = (CallbackHandler) callbackHandlerClass.newInstance();
+                }
+                loginContext = new LoginContext(realmName, callbackHandler);
+                loginContext.login();
+                clientSubject = loginContext.getSubject();
+            }
+            ContextManager.setCurrentCaller(clientSubject);
             jndiContext.startClient(appClientModuleName, kernel, classLoader);
             currentTransactionContext = transactionContextManager.newUnspecifiedTransactionContext();
-            mainMethod.invoke(null, new Object[]{args});
-
+            if (clientSubject == null) {
+                mainMethod.invoke(null, new Object[]{args});
+            } else {
+                Subject.doAs(clientSubject, new PrivilegedAction() {
+                    public Object run() {
+                        try {
+                            mainMethod.invoke(null, new Object[]{args});
+                        } catch (IllegalAccessException e) {
+                            throw new RuntimeException(e);
+                        } catch (InvocationTargetException e) {
+                            throw new RuntimeException(e);
+                        }
+                        return null;
+                    }
+                });
+            }
         } catch (InvocationTargetException e) {
             Throwable cause = e.getCause();
             if (cause instanceof Exception) {
@@ -107,6 +157,9 @@
             }
             throw new Error(e);
         } finally {
+            if (loginContext != null) {
+                loginContext.logout();
+            }
             jndiContext.stopClient(appClientModuleName);
 
             thread.setContextClassLoader(oldClassLoader);
@@ -122,22 +175,29 @@
         GBeanInfoBuilder infoFactory = new GBeanInfoBuilder(AppClientContainer.class, NameFactory.APP_CLIENT);
 
         infoFactory.addOperation("main", new Class[]{String[].class});
+
         infoFactory.addAttribute("mainClassName", String.class, true);
         infoFactory.addAttribute("appClientModuleName", ObjectName.class, true);
+        infoFactory.addAttribute("realmName", String.class, true);
+        infoFactory.addAttribute("callbackHandlerClassName", String.class, true);
         infoFactory.addAttribute("defaultPrincipal", DefaultPrincipal.class, true);
+
         infoFactory.addReference("JNDIContext", AppClientPlugin.class, NameFactory.GERONIMO_SERVICE);
         infoFactory.addReference("TransactionContextManager", TransactionContextManager.class,
NameFactory.JTA_RESOURCE);
+
         infoFactory.addAttribute("classLoader", ClassLoader.class, false);
         infoFactory.addAttribute("kernel", Kernel.class, false);
 
 
-        infoFactory.setConstructor(new String[]{"mainClassName", 
+        infoFactory.setConstructor(new String[]{"mainClassName",
                                                 "appClientModuleName",
+                                                "realmName",
+                                                "callbackHandlerClassName",
                                                 "defaultPrincipal",
                                                 "JNDIContext",
                                                 "TransactionContextManager",
-                                                "classLoader", 
-                                                "kernel"                                
  
+                                                "classLoader",
+                                                "kernel"
         });
 
         GBEAN_INFO = infoFactory.getBeanInfo();



Mime
View raw message