01: /*
02: jGuard is a security framework based on top of jaas (java authentication and authorization security).
03: it is written for web applications, to resolve simply, access control problems.
04: version $Name$
05: http://sourceforge.net/projects/jguard/
06:
07: Copyright (C) 2004 Charles GAY
08:
09: This library is free software; you can redistribute it and/or
10: modify it under the terms of the GNU Lesser General Public
11: License as published by the Free Software Foundation; either
12: version 2.1 of the License, or (at your option) any later version.
13:
14: This library is distributed in the hope that it will be useful,
15: but WITHOUT ANY WARRANTY; without even the implied warranty of
16: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17: Lesser General Public License for more details.
18:
19: You should have received a copy of the GNU Lesser General Public
20: License along with this library; if not, write to the Free Software
21: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22:
23:
24: jGuard project home page:
25: http://sourceforge.net/projects/jguard/
26:
27: */
28: package net.sf.jguard.ext.authorization.manager;
29:
30: import java.util.HashMap;
31: import java.util.Map;
32:
33: import junit.framework.TestCase;
34: import junitx.util.PrivateAccessor;
35: import net.sf.jguard.core.CoreConstants;
36: import net.sf.jguard.core.principals.RolePrincipal;
37: import net.sf.jguard.ext.SecurityConstants;
38: import net.sf.jguard.ext.authentication.manager.AuthenticationManagerFactory;
39: import net.sf.jguard.ext.authorization.AuthorizationException;
40:
41: public class XmlAuthorizationManagerTest extends TestCase {
42:
43: private AuthorizationManager auth;
44:
45: protected void setUp() throws Exception {
46: super .setUp();
47: PrivateAccessor.setField(AuthenticationManagerFactory.class,
48: "authenticationManager", null);
49: auth = getXmlAuthorizationManager();
50:
51: }
52:
53: private AuthorizationManager getXmlAuthorizationManager() {
54: Map authorizationManagerOptions = new HashMap();
55: authorizationManagerOptions.put(
56: SecurityConstants.AUTHORIZATION_XML_FILE_LOCATION,
57: getClass().getResource(
58: "/jGuardPrincipalsPermissions.xml").toString());
59: authorizationManagerOptions.put(CoreConstants.DEBUG, "true");
60: authorizationManagerOptions.put(CoreConstants.APPLICATION_NAME,
61: "jGuardExample");
62: AuthorizationManager xmlAuthManager = new XmlAuthorizationManager();
63: xmlAuthManager.init(authorizationManagerOptions);
64:
65: return xmlAuthManager;
66: }
67:
68: /*
69: * Test method for 'net.sf.jguard.ext.authorization.XmlAuthorizationManager.init(Map)'
70: */
71: public void testInit() {
72: //call to setUp is implied
73: }
74:
75: public void testUpdateUnknownPrincipal() {
76: RolePrincipal principal = new RolePrincipal();
77: try {
78: auth.updatePrincipal("qsdqsd", principal);
79: } catch (AuthorizationException e) {
80: TestCase.fail();
81: }
82: }
83:
84: }
|