1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.shiro.authz.aop;
20
21 import org.apache.shiro.authz.UnauthenticatedException;
22 import org.apache.shiro.authz.annotation.Logical;
23 import org.apache.shiro.authz.annotation.RequiresPermissions;
24 import org.apache.shiro.test.SecurityManagerTestSupport;
25 import org.junit.Test;
26
27 import java.lang.annotation.Annotation;
28
29
30
31
32 public class PermissionAnnotationHandlerTest extends SecurityManagerTestSupport {
33
34
35
36 @Test(expected = UnauthenticatedException.class)
37 public void testGuestSinglePermissionAssertion() throws Throwable {
38 PermissionAnnotationHandler handler = new PermissionAnnotationHandler();
39
40 Annotation requiresPermissionAnnotation = new RequiresPermissions() {
41 public String[] value() {
42 return new String[]{"test:test"};
43 }
44
45 public Class<? extends Annotation> annotationType() {
46 return RequiresPermissions.class;
47 }
48
49 public Logical logical() {
50 return Logical.AND;
51 }
52 };
53
54 handler.assertAuthorized(requiresPermissionAnnotation);
55 }
56
57
58
59 @Test(expected = UnauthenticatedException.class)
60 public void testGuestMultiplePermissionAssertion() throws Throwable {
61 PermissionAnnotationHandler handler = new PermissionAnnotationHandler();
62
63 Annotation requiresPermissionAnnotation = new RequiresPermissions() {
64 public String[] value() {
65 return new String[]{"test:test", "test2:test2"};
66 }
67
68 public Class<? extends Annotation> annotationType() {
69 return RequiresPermissions.class;
70 }
71
72 public Logical logical() {
73 return Logical.AND;
74 }
75 };
76
77 handler.assertAuthorized(requiresPermissionAnnotation);
78 }
79
80 }