KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > security > test > LoginConfigInterceptorUnitTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.security.test;
23
24 import javax.management.MBeanServerConnection JavaDoc;
25
26 import org.jboss.security.auth.login.XMLLoginConfigMBean;
27 import org.jboss.test.JBossTestCase;
28
29 /**
30  * Test the LoginConfigInterceptor when used with an ejb
31  *
32  * @author <a HREF="mailto:dimitris@jboss.org">Dimitris Andreadis</a>
33  * @version $Revision: 37406 $
34  */

35 public class LoginConfigInterceptorUnitTestCase
36    extends JBossTestCase
37 {
38    public LoginConfigInterceptorUnitTestCase(String JavaDoc name)
39    {
40       super(name);
41    }
42
43    /** Test the LoginConfigInterceptor when used with an ejb
44     */

45    public void testLoginConfigInterceptorWithEjb()
46       throws Exception JavaDoc
47    {
48       getLog().info("+++ testLoginConfigInterceptorWithEjb");
49
50       MBeanServerConnection JavaDoc server = getServer();
51       String JavaDoc module = "security-incpt.jar";
52
53       assertFalse("'other2' domain not registered",
54             isSecurityDomainPresent(server, "other2", "anonymous2"));
55       
56       deploy(module);
57       
58       assertTrue("'other2' domain registered",
59             isSecurityDomainPresent(server, "other2", "anonymous2"));
60       
61       undeploy(module);
62       
63       assertFalse("'other2' domain not registered",
64             isSecurityDomainPresent(server, "other2", "anonymous2"));
65    }
66    
67    /**
68     * Sort of a hack to find out if a security domain has been created.
69     * We call "displayAppConfig" on the XMLLoginConfig MBean passing the domain
70     * and we look for a particular substring in the result.
71     *
72     * It seems this method will return in any case the default "other" security
73     * domain, if a domain is not registered, so the deployed test ejb includes
74     * a login-config.xml that creates domain "other2" with the addition of
75     * a distinguishable unathenticatedIdentity "anonymous2".
76     *
77     * By looking for "anonymous2" in the response we can ascertain the registration
78     * was successful.
79     *
80     * <module-option name="unauthenticatedIdentity">anonymous2</module-option>
81     */

82    private boolean isSecurityDomainPresent(MBeanServerConnection JavaDoc server, String JavaDoc domain, String JavaDoc substr)
83       throws Exception JavaDoc
84    {
85       String JavaDoc result = (String JavaDoc)server.invoke(
86             XMLLoginConfigMBean.OBJECT_NAME,
87             "displayAppConfig",
88             new Object JavaDoc[] { domain },
89             new String JavaDoc[] { domain.getClass().getName() });
90
91       return result.indexOf(substr) >= 0;
92    }
93 }
Popular Tags