KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > security > test > authorization > AuthorizationConfigUnitTestCase


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.authorization;
23  
24 import java.util.Map JavaDoc;
25
26 import org.jboss.security.auth.container.config.AuthModuleEntry;
27 import org.jboss.security.auth.login.BaseAuthenticationInfo;
28 import org.jboss.security.auth.login.JASPIAuthenticationInfo;
29 import org.jboss.security.authorization.config.AuthorizationModuleEntry;
30 import org.jboss.security.authorization.config.SecurityConfigObjectModelFactory;
31 import org.jboss.security.config.ApplicationPolicy;
32 import org.jboss.security.config.AuthorizationInfo;
33 import org.jboss.security.config.PolicyConfig;
34 import org.jboss.test.security.container.auth.config.JASPIConfigurationTestCase;
35
36 //$Id: AuthorizationConfigUnitTestCase.java 45690 2006-06-20 04:53:17Z asaldhana $
37

38 /**
39  * Test the Authorization Framework Configuration
40  * @author <a HREF="mailto:Anil.Saldhana@jboss.org">Anil Saldhana</a>
41  * @since Jun 9, 2006
42  * @version $Revision: 45690 $
43  */

44 public class AuthorizationConfigUnitTestCase extends JASPIConfigurationTestCase
45 {
46    public AuthorizationConfigUnitTestCase(String JavaDoc name)
47    {
48       super(name);
49    }
50    
51    public void testAuthorizationInfo() throws Exception JavaDoc
52    {
53       String JavaDoc loc = "security/authorization/config/authorization-config.xml";
54       PolicyConfig config = getPolicyConfig(loc,new SecurityConfigObjectModelFactory());
55       assertNotNull("Returned PolicyConfig is != null ?", config);
56       
57       ApplicationPolicy aPolicy = config.get("TestAuthorization");
58       //Test Authentication
59
BaseAuthenticationInfo infoBase = aPolicy.getAuthenticationInfo();
60       assertTrue("infoBase==AuthenticationJaspiInfo", infoBase instanceof JASPIAuthenticationInfo);
61       JASPIAuthenticationInfo info = (JASPIAuthenticationInfo)infoBase;
62       assertTrue("jaspi != null", info != null);
63       AuthModuleEntry[] authEntry = info.getAuthModuleEntry();
64       //Get the first AuthModule
65
AuthModuleEntry aEntry1 = authEntry[0];
66       validateAuthModule1(aEntry1);
67       //Get the second AuthModule
68
AuthModuleEntry aEntry2 = authEntry[1];
69       validateAuthModule2(aEntry2);
70       
71       //Test Authorization
72
AuthorizationInfo authzInfo = aPolicy.getAuthorizationInfo();
73       AuthorizationModuleEntry[] authzEntries = authzInfo.getAuthorizationModuleEntry();
74       assertTrue("AuthzInfo != null", authzInfo != null);
75       assertTrue("authzEntries has 1 element", authzEntries.length == 1);
76       // Get the first AuthorizationModuleEntry
77
AuthorizationModuleEntry azEntry1 = authzEntries[0];
78       validateAuthorizationModuleEntry(azEntry1);
79    }
80    
81    private void validateAuthorizationModuleEntry(AuthorizationModuleEntry ame)
82    {
83       assertEquals("policy.module1.class.name", ame.getPolicyModuleName());
84       Map JavaDoc aEntry1Options = ame.getOptions();
85       assertNotNull("Options in the first AuthModule != null", aEntry1Options);
86       assertTrue( "Length of options == 3", aEntry1Options.size() == 3);
87       String JavaDoc usersProperties = (String JavaDoc) aEntry1Options.get("usersProperties");
88       assertNotNull("options.usersProperties exists", usersProperties);
89       assertTrue("options.usersProperties == props/jbossws-users.properties",
90             usersProperties.equals("props/jbossws-users.properties"));
91       String JavaDoc rolesProperties = (String JavaDoc) aEntry1Options.get("rolesProperties");
92       assertNotNull("options.rolesProperties exists", rolesProperties);
93       assertTrue("options.rolesProperties == props/jbossws-roles.properties",
94             rolesProperties.equals("props/jbossws-roles.properties"));
95    }
96 }
97
Popular Tags