1
- /*
1
+ /*
2
2
* Copyright (c) 2013 - 2014, TRIOLOGY GmbH
3
3
* All rights reserved.
4
4
*
24
24
*
25
25
* http://www.scm-manager.com
26
26
*/
27
-
28
27
package de .triology .universeadm ;
29
28
30
29
import com .google .inject .Inject ;
42
41
import org .apache .shiro .cas .CasFilter ;
43
42
import org .apache .shiro .cas .CasRealm ;
44
43
import org .apache .shiro .cas .CasSubjectFactory ;
45
- import org .apache .shiro .guice .web .ShiroWebModule ;
46
44
import org .apache .shiro .mgt .SubjectFactory ;
47
45
import org .apache .shiro .realm .Realm ;
48
46
import org .apache .shiro .subject .PrincipalCollection ;
53
51
54
52
/**
55
53
*
56
- * @author Sebastian Sdorra <[email protected] >
54
+ * @author mbehlendorf
57
55
*/
58
- public class SecurityModule extends ShiroWebModule
59
- {
56
+ public class CasSecurityModule extends BaseSecurityModule {
60
57
58
+ private static final Logger logger = LoggerFactory .getLogger (CasSecurityModule .class );
59
+
61
60
private static final Key <CasFilter > CAS = Key .get (CasFilter .class );
62
61
private static final Key <ApiAuthenticationFilter > API = Key .get (ApiAuthenticationFilter .class );
63
62
@@ -68,19 +67,10 @@ public class SecurityModule extends ShiroWebModule
68
67
private static final String CAS_FAILURE_URL = "shiro.failureUrl" ;
69
68
private static final String CAS_SERVICE = "shiro.casService" ;
70
69
71
- private static final Logger logger = LoggerFactory .getLogger (SecurityModule .class );
72
-
73
- public SecurityModule (ServletContext context )
74
- {
70
+ public CasSecurityModule (ServletContext context ) {
75
71
super (context );
76
72
}
77
-
78
- private void config (String key , String value )
79
- {
80
- logger .debug ("bind config {} to {}" , key , value );
81
- bindConstant ().annotatedWith (Names .named (key )).to (value );
82
- }
83
-
73
+
84
74
private CasConfiguration getCasConfiguration ()
85
75
{
86
76
CasConfiguration casConfiguration = BaseDirectory .getConfiguration (CasConfiguration .FILE , CasConfiguration .class );
@@ -91,10 +81,14 @@ private CasConfiguration getCasConfiguration()
91
81
return casConfiguration ;
92
82
}
93
83
94
- @ Override
95
- @ SuppressWarnings ("unchecked" )
96
- protected void configureShiroWeb ()
84
+ private void config (String key , String value )
97
85
{
86
+ logger .debug ("bind config {} to {}" , key , value );
87
+ bindConstant ().annotatedWith (Names .named (key )).to (value );
88
+ }
89
+
90
+ @ Override
91
+ protected void configureRealm () {
98
92
CasConfiguration cas = getCasConfiguration ();
99
93
bind (CasConfiguration .class ).toInstance (cas );
100
94
expose (CasConfiguration .class );
@@ -113,19 +107,16 @@ protected void configureShiroWeb()
113
107
// beacuse it looks like guice does not set constants for multi binding
114
108
bindRealm ().toProvider (CasRealmProvider .class ).in (Singleton .class );
115
109
bind (SubjectFactory .class ).to (CasSubjectFactory .class );
116
-
117
- addFilterChain ("/error/*" , ANON );
118
- addFilterChain ("/style/**" , ANON );
119
- addFilterChain ("/components/**" , ANON );
110
+
111
+ // protect uris
120
112
addFilterChain ("/login/cas" , ANON , CAS );
121
- addFilterChain ("/api/logout" , ANON );
122
113
addFilterChain ("/api/users" , API , config (ROLES , Roles .ADMINISTRATOR ));
123
114
addFilterChain ("/api/users/*" , API , config (ROLES , Roles .ADMINISTRATOR ));
124
115
addFilterChain ("/api/groups" , API , config (ROLES , Roles .ADMINISTRATOR ));
125
116
addFilterChain ("/api/groups/*" , API , config (ROLES , Roles .ADMINISTRATOR ));
126
117
addFilterChain ("/**" , AUTHC );
127
118
}
128
-
119
+
129
120
private static class CasRealmProvider implements Provider <Realm >
130
121
{
131
122
@@ -144,8 +135,8 @@ public Realm get()
144
135
}
145
136
146
137
}
147
-
148
- /**
138
+
139
+ /**
149
140
* CasRealm with fixed support for multi value attributes
150
141
*
151
142
* @see https://issues.apache.org/jira/browse/SHIRO-442
@@ -276,5 +267,5 @@ private List<String> split(String s)
276
267
}
277
268
278
269
}
279
-
270
+
280
271
}
0 commit comments