- 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í)踐與體系構(gòu)建
- Web漏洞分析與防范實(shí)戰(zhàn):卷1
- 信息系統(tǒng)安全檢測與風(fēng)險評估
- 暗戰(zhàn)亮劍:黑客滲透與防御全程實(shí)錄
- INSTANT Metasploit Starter
- Mastering Kali Linux for Advanced Penetration Testing
- Learning Veeam? Backup & Replication for VMware vSphere
- 代碼審計:企業(yè)級Web代碼安全架構(gòu)
- 從0到1:CTFer成長之路
- 網(wǎng)絡(luò)安全能力成熟度模型:原理與實(shí)踐
- 先進(jìn)云安全研究與實(shí)踐
- 網(wǎng)絡(luò)用戶行為的安全可信分析與控制
- Cybersecurity Threats,Malware Trends,and Strategies
- 網(wǎng)絡(luò)空間安全:拒絕服務(wù)攻擊檢測與防御
- 黑客攻擊與防范實(shí)戰(zhàn)從入門到精通