36
36
import org .apache .shiro .web .session .mgt .DefaultWebSessionManager ;
37
37
import org .apache .shiro .web .session .mgt .WebSessionManager ;
38
38
import org .springframework .beans .factory .annotation .Autowired ;
39
+ import org .springframework .beans .factory .annotation .Value ;
39
40
import org .springframework .boot .autoconfigure .condition .ConditionalOnProperty ;
40
41
import org .springframework .stereotype .Component ;
41
42
@@ -59,6 +60,9 @@ public class InlongShiroImpl implements InlongShiro {
59
60
@ Autowired
60
61
private UserService userService ;
61
62
63
+ @ Value ("${openapi.auth.enabled:false}" )
64
+ private Boolean openAPIAuthEnabled ;
65
+
62
66
@ Override
63
67
public WebSecurityManager getWebSecurityManager () {
64
68
return new DefaultWebSecurityManager ();
@@ -93,7 +97,6 @@ public ShiroFilterFactoryBean getShiroFilter(SecurityManager securityManager) {
93
97
// anon: can be accessed by anyone, authc: only authentication is successful can be accessed
94
98
Map <String , Filter > filters = new LinkedHashMap <>();
95
99
filters .put (FILTER_NAME_WEB , new AuthenticationFilter ());
96
- filters .put (FILTER_NAME_API , new OpenAPIFilter ());
97
100
shiroFilterFactoryBean .setFilters (filters );
98
101
Map <String , String > pathDefinitions = new LinkedHashMap <>();
99
102
// login, register request
@@ -107,7 +110,12 @@ public ShiroFilterFactoryBean getShiroFilter(SecurityManager securityManager) {
107
110
pathDefinitions .put ("/swagger-resources" , "anon" );
108
111
109
112
// openapi
110
- pathDefinitions .put ("/openapi/**/*" , FILTER_NAME_API );
113
+ if (openAPIAuthEnabled ) {
114
+ filters .put (FILTER_NAME_API , new OpenAPIFilter ());
115
+ pathDefinitions .put ("/openapi/**/*" , FILTER_NAME_API );
116
+ } else {
117
+ pathDefinitions .put ("/openapi/**/*" , "anon" );
118
+ }
111
119
112
120
// other web
113
121
pathDefinitions .put ("/**" , FILTER_NAME_WEB );
0 commit comments