You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ga...@apache.org on 2007/11/02 19:52:25 UTC
svn commit: r591424 - in
/geronimo/server/trunk/testsuite/security-testsuite/test-security: pom.xml
src/test/java/org/apache/geronimo/testsuite/security/TestMEJBSecurity.java
Author: gawor
Date: Fri Nov 2 11:52:24 2007
New Revision: 591424
URL: http://svn.apache.org/viewvc?rev=591424&view=rev
Log:
basic mejb security tests
Added:
geronimo/server/trunk/testsuite/security-testsuite/test-security/src/test/java/org/apache/geronimo/testsuite/security/TestMEJBSecurity.java (with props)
Modified:
geronimo/server/trunk/testsuite/security-testsuite/test-security/pom.xml
Modified: geronimo/server/trunk/testsuite/security-testsuite/test-security/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/testsuite/security-testsuite/test-security/pom.xml?rev=591424&r1=591423&r2=591424&view=diff
==============================================================================
--- geronimo/server/trunk/testsuite/security-testsuite/test-security/pom.xml (original)
+++ geronimo/server/trunk/testsuite/security-testsuite/test-security/pom.xml Fri Nov 2 11:52:24 2007
@@ -54,6 +54,32 @@
<artifactId>geronimo-j2ee-management_1.1_spec</artifactId>
<scope>provided</scope>
</dependency>
+
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-ejb_3.0_spec</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>openejb-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>openejb-client</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.geronimo.modules</groupId>
+ <artifactId>geronimo-security</artifactId>
+ <version>${version}</version>
+ <scope>test</scope>
+ </dependency>
+
</dependencies>
<profiles>
Added: geronimo/server/trunk/testsuite/security-testsuite/test-security/src/test/java/org/apache/geronimo/testsuite/security/TestMEJBSecurity.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/testsuite/security-testsuite/test-security/src/test/java/org/apache/geronimo/testsuite/security/TestMEJBSecurity.java?rev=591424&view=auto
==============================================================================
--- geronimo/server/trunk/testsuite/security-testsuite/test-security/src/test/java/org/apache/geronimo/testsuite/security/TestMEJBSecurity.java (added)
+++ geronimo/server/trunk/testsuite/security-testsuite/test-security/src/test/java/org/apache/geronimo/testsuite/security/TestMEJBSecurity.java Fri Nov 2 11:52:24 2007
@@ -0,0 +1,123 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.testsuite.security;
+
+import java.rmi.AccessException;
+import java.util.Hashtable;
+
+import javax.management.j2ee.Management;
+import javax.management.j2ee.ManagementHome;
+import javax.naming.AuthenticationException;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.rmi.PortableRemoteObject;
+
+import org.apache.geronimo.testsupport.TestSupport;
+import org.testng.annotations.Test;
+
+public class TestMEJBSecurity extends TestSupport {
+
+ @Test
+ public void testLogin() throws Exception {
+ Hashtable env = getEnvironment();
+ env.put(Context.SECURITY_PRINCIPAL, "system");
+ env.put(Context.SECURITY_CREDENTIALS, "manager");
+
+ Management mgmt = getMEJB(env);
+ System.out.println(mgmt.getDefaultDomain());
+ assertEquals("geronimo", mgmt.getDefaultDomain());
+ }
+
+ @Test
+ public void testBadPasswordLogin() throws Exception {
+ testFailure("system", "managerr");
+ }
+
+ @Test
+ public void testBadUser() throws Exception {
+ testFailure("doesnotexist", "managerr");
+ }
+
+ @Test
+ public void testNullPasswordLogin() throws Exception {
+ testFailure("system", null);
+ }
+
+ @Test
+ public void testNullUserLogin() throws Exception {
+ testFailure(null, "manager");
+ }
+
+ @Test
+ public void testNullCredentialsLogin() throws Exception {
+ testFailure(null, null);
+ }
+
+ @Test
+ public void testEmptyCredentialsLogin() throws Exception {
+ testFailure("", "");
+ }
+
+ private void testFailure(String username, String password) throws Exception {
+ Hashtable env = getEnvironment();
+ if (username != null) {
+ env.put(Context.SECURITY_PRINCIPAL, username);
+ }
+ if (password != null) {
+ env.put(Context.SECURITY_CREDENTIALS, password);
+ }
+
+ try {
+ Management mgmt = getMEJB(env);
+ fail("Did not throw security exception");
+ } catch (AuthenticationException e) {
+ // expected
+ e.printStackTrace(System.out);
+ } catch (AccessException e) {
+ // expected
+ e.printStackTrace(System.out);
+ }
+ }
+
+ private Hashtable getEnvironment() {
+ Hashtable p = new Hashtable();
+
+ p.put("java.naming.factory.initial",
+ "org.apache.openejb.client.RemoteInitialContextFactory");
+ p.put("java.naming.provider.url",
+ "127.0.0.1:4201");
+
+ // XXXX: this should not be necessary
+ p.put("openejb.authentication.realmName", "geronimo-admin");
+
+ return p;
+ }
+
+ private Management getMEJB(Hashtable env) throws Exception {
+ String jndiName = "ejb/mgmt/MEJBRemoteHome"; // should be "ejb/mgmt/MEJB"
+ InitialContext ctx = new InitialContext(env);
+ Object objref = ctx.lookup(jndiName);
+ ManagementHome home = (ManagementHome)
+ PortableRemoteObject.narrow(objref,ManagementHome.class);
+ Management mejb = home.create();
+ return mejb;
+ }
+
+}
Propchange: geronimo/server/trunk/testsuite/security-testsuite/test-security/src/test/java/org/apache/geronimo/testsuite/security/TestMEJBSecurity.java
------------------------------------------------------------------------------
svn:eol-style = native