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 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
0 |
public class AbstractSecurityTestcase extends AbstractPrefsSupportedTestCase |
51 |
|
{ |
52 |
|
|
53 |
|
protected SecurityAccess securityAccess; |
54 |
|
|
55 |
|
|
56 |
|
protected CredentialHandler ch; |
57 |
|
|
58 |
|
|
59 |
|
protected UserSecurityHandler ush; |
60 |
|
|
61 |
|
|
62 |
|
protected RoleSecurityHandler rsh; |
63 |
|
|
64 |
|
|
65 |
|
protected GroupSecurityHandler gsh; |
66 |
|
|
67 |
|
|
68 |
|
protected SecurityMappingHandler smh; |
69 |
|
|
70 |
|
|
71 |
|
protected SecurityProvider securityProvider; |
72 |
|
|
73 |
|
|
74 |
|
protected UserManager ums; |
75 |
|
|
76 |
|
|
77 |
|
protected GroupManager gms; |
78 |
|
|
79 |
|
|
80 |
|
protected RoleManager rms; |
81 |
|
|
82 |
|
|
83 |
|
protected PermissionManager pms; |
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
protected void setUp() throws Exception |
89 |
|
{ |
90 |
|
|
91 |
0 |
super.setUp(); |
92 |
|
|
93 |
|
|
94 |
0 |
securityAccess = (SecurityAccess) ctx.getBean("org.apache.jetspeed.security.spi.SecurityAccess"); |
95 |
0 |
ch = (CredentialHandler) ctx.getBean("org.apache.jetspeed.security.spi.CredentialHandler"); |
96 |
0 |
ush = (UserSecurityHandler) ctx.getBean("org.apache.jetspeed.security.spi.UserSecurityHandler"); |
97 |
0 |
rsh = (RoleSecurityHandler) ctx.getBean("org.apache.jetspeed.security.spi.RoleSecurityHandler"); |
98 |
0 |
gsh = (GroupSecurityHandler) ctx.getBean("org.apache.jetspeed.security.spi.GroupSecurityHandler"); |
99 |
0 |
smh = (SecurityMappingHandler) ctx.getBean("org.apache.jetspeed.security.spi.SecurityMappingHandler"); |
100 |
|
|
101 |
|
|
102 |
0 |
AuthenticationProvider atnProvider = (AuthenticationProvider) ctx.getBean("org.apache.jetspeed.security.AuthenticationProvider"); |
103 |
0 |
List atnProviders = new ArrayList(); |
104 |
0 |
atnProviders.add(atnProvider); |
105 |
|
|
106 |
|
|
107 |
0 |
AuthenticationProviderProxy atnProviderProxy = (AuthenticationProviderProxy) ctx.getBean("org.apache.jetspeed.security.AuthenticationProviderProxy"); |
108 |
0 |
securityProvider = new SecurityProviderImpl(atnProviderProxy, rsh, gsh, smh); |
109 |
|
|
110 |
0 |
securityProvider = (SecurityProvider) ctx.getBean("org.apache.jetspeed.security.SecurityProvider"); |
111 |
|
|
112 |
0 |
ums = (UserManager) ctx.getBean("org.apache.jetspeed.security.UserManager"); |
113 |
0 |
gms = (GroupManager) ctx.getBean("org.apache.jetspeed.security.GroupManager"); |
114 |
0 |
rms = (RoleManager) ctx.getBean("org.apache.jetspeed.security.RoleManager"); |
115 |
|
|
116 |
|
|
117 |
0 |
pms = (PermissionManager) ctx.getBean("org.apache.jetspeed.security.PermissionManager"); |
118 |
|
|
119 |
0 |
new JetspeedActions(class="keyword">new String[] {"secure"}, new String[] {}); |
120 |
0 |
} |
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
protected Collection getPrincipals(Subject subject, Class claz) |
130 |
|
{ |
131 |
0 |
List principals = new ArrayList(); |
132 |
0 |
for (Iterator iter = subject.getPrincipals().iterator(); iter.hasNext();) |
133 |
|
{ |
134 |
0 |
Object element = iter.next(); |
135 |
0 |
if (claz.isInstance(element)) |
136 |
0 |
principals.add(element); |
137 |
|
|
138 |
0 |
} |
139 |
0 |
return principals; |
140 |
|
} |
141 |
|
|
142 |
|
protected String[] getConfigurations() |
143 |
|
{ |
144 |
0 |
String[] confs = super.getConfigurations(); |
145 |
0 |
List confList = new ArrayList(Arrays.asList(confs)); |
146 |
0 |
confList.add("security-atn.xml"); |
147 |
0 |
confList.add("security-atz.xml"); |
148 |
0 |
confList.add("security-managers.xml"); |
149 |
0 |
confList.add("security-providers.xml"); |
150 |
0 |
confList.add("security-spi.xml"); |
151 |
0 |
confList.add("security-spi-atn.xml"); |
152 |
0 |
confList.add("security-spi-atz.xml"); |
153 |
0 |
return (String[]) confList.toArray(new String[1]); |
154 |
|
} |
155 |
|
|
156 |
|
} |