1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.security.util.test;
18
19 import java.util.ArrayList;
20 import java.util.Arrays;
21 import java.util.Collection;
22 import java.util.Iterator;
23 import java.util.List;
24
25 import javax.security.auth.Subject;
26
27 import org.apache.jetspeed.JetspeedActions;
28 import org.apache.jetspeed.prefs.util.test.AbstractPrefsSupportedTestCase;
29 import org.apache.jetspeed.security.AuthenticationProvider;
30 import org.apache.jetspeed.security.AuthenticationProviderProxy;
31 import org.apache.jetspeed.security.GroupManager;
32 import org.apache.jetspeed.security.PermissionManager;
33 import org.apache.jetspeed.security.RoleManager;
34 import org.apache.jetspeed.security.SecurityProvider;
35 import org.apache.jetspeed.security.UserManager;
36 import org.apache.jetspeed.security.impl.SecurityProviderImpl;
37 import org.apache.jetspeed.security.spi.CredentialHandler;
38 import org.apache.jetspeed.security.spi.GroupSecurityHandler;
39 import org.apache.jetspeed.security.spi.RoleSecurityHandler;
40 import org.apache.jetspeed.security.spi.SecurityAccess;
41 import org.apache.jetspeed.security.spi.SecurityMappingHandler;
42 import org.apache.jetspeed.security.spi.UserSecurityHandler;
43
44 /***
45 * @author <a href="mailto:sweaver@einnovation.com">Scott T. Weaver </a>
46 * @author <a href="mailto:dlestrat@apache.org">David Le Strat </a>
47 * @version $Id: AbstractSecurityTestcase.java 516448 2007-03-09 16:25:47Z ate $
48 *
49 */
50 public class AbstractSecurityTestcase extends AbstractPrefsSupportedTestCase
51 {
52 /*** SPI Common Queries. */
53 protected SecurityAccess securityAccess;
54
55 /*** SPI Default Credential Handler. */
56 protected CredentialHandler ch;
57
58 /*** SPI Default User Security Handler. */
59 protected UserSecurityHandler ush;
60
61 /*** SPI Default Role Security Handler. */
62 protected RoleSecurityHandler rsh;
63
64 /*** SPI Default Group Security Handler. */
65 protected GroupSecurityHandler gsh;
66
67 /*** SPI Default Security Mapping Handler. */
68 protected SecurityMappingHandler smh;
69
70 /*** The security provider. */
71 protected SecurityProvider securityProvider;
72
73 /*** The user manager. */
74 protected UserManager ums;
75
76 /*** The group manager. */
77 protected GroupManager gms;
78
79 /*** The role manager. */
80 protected RoleManager rms;
81
82 /*** The permission manager. */
83 protected PermissionManager pms;
84
85 /***
86 * @see junit.framework.TestCase#setUp()
87 */
88 protected void setUp() throws Exception
89 {
90
91 super.setUp();
92
93
94 securityAccess = (SecurityAccess) ctx.getBean("org.apache.jetspeed.security.spi.SecurityAccess");
95 ch = (CredentialHandler) ctx.getBean("org.apache.jetspeed.security.spi.CredentialHandler");
96 ush = (UserSecurityHandler) ctx.getBean("org.apache.jetspeed.security.spi.UserSecurityHandler");
97 rsh = (RoleSecurityHandler) ctx.getBean("org.apache.jetspeed.security.spi.RoleSecurityHandler");
98 gsh = (GroupSecurityHandler) ctx.getBean("org.apache.jetspeed.security.spi.GroupSecurityHandler");
99 smh = (SecurityMappingHandler) ctx.getBean("org.apache.jetspeed.security.spi.SecurityMappingHandler");
100
101
102 AuthenticationProvider atnProvider = (AuthenticationProvider) ctx.getBean("org.apache.jetspeed.security.AuthenticationProvider");
103 List atnProviders = new ArrayList();
104 atnProviders.add(atnProvider);
105
106
107 AuthenticationProviderProxy atnProviderProxy = (AuthenticationProviderProxy) ctx.getBean("org.apache.jetspeed.security.AuthenticationProviderProxy");
108 securityProvider = new SecurityProviderImpl(atnProviderProxy, rsh, gsh, smh);
109
110 securityProvider = (SecurityProvider) ctx.getBean("org.apache.jetspeed.security.SecurityProvider");
111
112 ums = (UserManager) ctx.getBean("org.apache.jetspeed.security.UserManager");
113 gms = (GroupManager) ctx.getBean("org.apache.jetspeed.security.GroupManager");
114 rms = (RoleManager) ctx.getBean("org.apache.jetspeed.security.RoleManager");
115
116
117 pms = (PermissionManager) ctx.getBean("org.apache.jetspeed.security.PermissionManager");
118
119 new JetspeedActions(new String[] {"secure"}, new String[] {});
120 }
121
122 /***
123 * Returns subject's principals of type claz
124 *
125 * @param subject
126 * @param claz
127 * @return Returns subject's principals of type claz
128 */
129 protected Collection getPrincipals(Subject subject, Class claz)
130 {
131 List principals = new ArrayList();
132 for (Iterator iter = subject.getPrincipals().iterator(); iter.hasNext();)
133 {
134 Object element = iter.next();
135 if (claz.isInstance(element))
136 principals.add(element);
137
138 }
139 return principals;
140 }
141
142 protected String[] getConfigurations()
143 {
144 String[] confs = super.getConfigurations();
145 List confList = new ArrayList(Arrays.asList(confs));
146 confList.add("security-atn.xml");
147 confList.add("security-atz.xml");
148 confList.add("security-managers.xml");
149 confList.add("security-providers.xml");
150 confList.add("security-spi.xml");
151 confList.add("security-spi-atn.xml");
152 confList.add("security-spi-atz.xml");
153 return (String[]) confList.toArray(new String[1]);
154 }
155
156 }