- Hands-On Spring Security 5 for Reactive Applications
- Tomcy John
- 169字
- 2021-07-23 18:59:24
Web URL
Spring Security can be used to set up URL-based authorization. HTTP Security configured can be used with Spring Security configuration to achieve the desired authorization. In many examples that we have gone through so far, we have seen pattern matching authorization. Here is one such example:
- AntPathRequestMatcher: Uses an Ant-style pattern for URL matching:
http
.antMatcher("/rest/**")
.httpBasic()
.disable()
.authorizeRequests()
.antMatchers("/rest/movie/**", "/rest/ticket/**", "/index")
.hasRole("ROLE_USER");
In the preceding code snippet, the /rest URL's basic authentication is disabled, and for other URLs (/rest/movie, /rest/ticket and /index), users with the USER role have access. The snippet also shows single match (using antMatcher) and multiple matches (using antMatchers).
- MvcRequestMatcher: This uses Spring MVC to match the path and then extracts variables. The matching is relative to the servlet path.
- RegexRequestMatcher: This uses a regular expression to match the URL. It can also be used to match the HTTP method, if needed. The matching is case-sensitive and takes the form (servletPath + pathInfo + queryString):
http
.authorizeRequests()
.regexMatchers("^((?!(/rest|/advSearch)).)*$").hasRole("ADMIN")
.regexMatchers("^((?!(/rest|/basicSearch)).)*$").access("hasRole(USER)")
.anyRequest()
.authenticated()
.and()
.httpBasic();
推薦閱讀
- 數(shù)據(jù)恢復(fù)方法及案例分析
- Kali Linux CTF Blueprints
- API安全實(shí)戰(zhàn)
- 黑客攻防與電腦安全從新手到高手(微視頻+火力升級(jí)版)
- Penetration Testing with Perl
- .NET安全攻防指南(上冊(cè))
- 數(shù)字化轉(zhuǎn)型浪潮下的數(shù)據(jù)安全最佳實(shí)踐指南
- Testing and Securing Android Studio Applications
- 云原生安全技術(shù)實(shí)踐指南
- 隱私計(jì)算
- Falco云原生安全:Falco原理、實(shí)踐與擴(kuò)展
- 華為防火墻實(shí)戰(zhàn)指南
- Practical Internet of Things Security
- 隱私保護(hù)機(jī)器學(xué)習(xí)
- Instant OSSEC Host-based Intrusion Detection System