1
+ package com .opensymphony .xwork2 .ognl ;
2
+
3
+ import java .lang .reflect .Member ;
4
+ import java .util .HashMap ;
5
+ import java .util .Map ;
6
+
7
+ import com .opensymphony .xwork2 .ActionProxy ;
8
+ import com .opensymphony .xwork2 .XWorkTestCase ;
9
+ import com .opensymphony .xwork2 .config .providers .XmlConfigurationProvider ;
10
+
11
+ public class SecurityMemberAccessProxyTest extends XWorkTestCase {
12
+ private Map <String , Object > context ;
13
+
14
+ @ Override
15
+ public void setUp () throws Exception {
16
+ super .setUp ();
17
+
18
+ context = new HashMap <String , Object >();
19
+ // Set up XWork
20
+ XmlConfigurationProvider provider = new XmlConfigurationProvider ("com/opensymphony/xwork2/spring/actionContext-xwork.xml" );
21
+ container .inject (provider );
22
+ loadConfigurationProviders (provider );
23
+ }
24
+
25
+ public void testProxyAccessIsBlocked () throws Exception {
26
+ ActionProxy proxy = actionProxyFactory .createActionProxy (null ,
27
+ "paramsAwareProxiedAction" , null , context );
28
+
29
+ SecurityMemberAccess sma = new SecurityMemberAccess (false );
30
+ sma .setDisallowProxyMemberAccess (true );
31
+
32
+ Member member = proxy .getAction ().getClass ().getMethod ("isExposeProxy" );
33
+
34
+ boolean accessible = sma .isAccessible (context , proxy .getAction (), member , "" );
35
+ assertFalse (accessible );
36
+ }
37
+
38
+ public void testProxyAccessIsAccessible () throws Exception {
39
+ ActionProxy proxy = actionProxyFactory .createActionProxy (null ,
40
+ "paramsAwareProxiedAction" , null , context );
41
+
42
+ SecurityMemberAccess sma = new SecurityMemberAccess (false );
43
+
44
+ Member member = proxy .getAction ().getClass ().getMethod ("isExposeProxy" );
45
+
46
+ boolean accessible = sma .isAccessible (context , proxy .getAction (), member , "" );
47
+ assertTrue (accessible );
48
+ }
49
+ }
0 commit comments