最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Spring security用戶URL權(quán)限FilterSecurityInterceptor使用解析

 更新時間:2019年12月12日 09:03:43   作者:二刀  
這篇文章主要介紹了Spring security用戶URL權(quán)限FilterSecurityInterceptor使用解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下

這篇文章主要介紹了Spring security用戶URL權(quán)限FilterSecurityInterceptor使用解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下

用戶通過瀏覽器發(fā)送URL地址,由FilterSecurityInterceptor判斷是否具有相應(yīng)的訪問權(quán)限。

對于用戶請求的方法權(quán)限,例如注解@PreAuthorize("hasRole('ADMIN')"),由MethodSecurityInterceptor判斷

兩個攔截器都繼承了AbstractSecurityInterceptor

代碼如下

/*
 * Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.springframework.security.web.access.intercept;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import org.springframework.security.access.SecurityMetadataSource;
import org.springframework.security.access.intercept.AbstractSecurityInterceptor;
import org.springframework.security.access.intercept.InterceptorStatusToken;
import org.springframework.security.web.FilterInvocation;
/**
 * Performs security handling of HTTP resources via a filter implementation.
 * 通過篩選器實現(xiàn)對HTTP資源的安全處理。
 * <p>
 * The <code>SecurityMetadataSource</code> required by this security interceptor is of
 * type {@link FilterInvocationSecurityMetadataSource}.
 * <p>
 *安全攔截器所需的SecurityMetadataSource類型是FilterInvocationSecurityMetadataSource
 *
 * Refer to {@link AbstractSecurityInterceptor} for details on the workflow.
 * </p>
 *
 * @author Ben Alex
 * @author Rob Winch
 */
public class FilterSecurityInterceptor extends AbstractSecurityInterceptor implements
		Filter {
	// ~ Static fields/initializers
	// =====================================================================================
	private static final String FILTER_APPLIED = "__spring_security_filterSecurityInterceptor_filterApplied";
	// ~ Instance fields
	// ================================================================================================
	/**
	*securityMetadataSource 中包含了一個HashMap,map中保存了用戶請求的Http.Method和相應(yīng)的URL地址
	*例如在Spring boot中,可能是如下的配置,參考圖1
	*securityMetadataSource中的內(nèi)容,參考圖2
	*/
	private FilterInvocationSecurityMetadataSource securityMetadataSource;
	private Boolean observeOncePerRequest = true;
	// ~ Methods
	// ========================================================================================================
	/**
	 * Not used (we rely on IoC container lifecycle services instead)
	 *
	 * @param arg0 ignored
	 *
	 * @throws ServletException never thrown
	 */
	public void init(FilterConfig arg0) throws ServletException {
	}
	/**
	 * Not used (we rely on IoC container lifecycle services instead)
	 */
	public void destroy() {
	}
	/**
	 * Method that is actually called by the filter chain. Simply delegates to the
	 * {@link #invoke(FilterInvocation)} method.
	 *
	 * @param request the servlet request
	 * @param response the servlet response
	 * @param chain the filter chain
	 *
	 * @throws IOException if the filter chain fails
	 * @throws ServletException if the filter chain fails
	 *
	 *
	 *通過責(zé)任鏈?zhǔn)秸{(diào)用,執(zhí)行doFilter方法
	 *FilterInvocation中保存了filter相關(guān)的信息,比如request,response,chain
	 *通過invoke方法處理具體的url過濾
	 */
	public void doFilter(ServletRequest request, ServletResponse response,
				FilterChain chain) throws IOException, ServletException {
		FilterInvocation fi = new FilterInvocation(request, response, chain);
		invoke(fi);
	}
	public FilterInvocationSecurityMetadataSource getSecurityMetadataSource() {
		return this.securityMetadataSource;
	}
	public SecurityMetadataSource obtainSecurityMetadataSource() {
		return this.securityMetadataSource;
	}
	public void setSecurityMetadataSource(FilterInvocationSecurityMetadataSource newSource) {
		this.securityMetadataSource = newSource;
	}
	public Class<?> getSecureObjectClass() {
		return FilterInvocation.class;
	}
	public void invoke(FilterInvocation fi) throws IOException, ServletException {
		//獲取當(dāng)前http請求的地址,比如說“/login”
		if ((fi.getRequest() != null)
						&& (fi.getRequest().getAttribute(FILTER_APPLIED) != null)
						&& observeOncePerRequest) {
			// filter already applied to this request and user wants us to observe
			// once-per-request handling, so don't re-do security checking
			fi.getChain().doFilter(fi.getRequest(), fi.getResponse());
		} else {
			// first time this request being called, so perform security checking
			if (fi.getRequest() != null) {
				fi.getRequest().setAttribute(FILTER_APPLIED, Boolean.TRUE);
			}
			//這里做主要URL比對,將當(dāng)前URL與securityMetadataSource(我們自己配置)中的URL過濾條件進行比對
			//首先判斷當(dāng)前URL是permit的還是需要驗證的
			//若需要驗證,嘗試加載保存在SecurityContextHolder.getContext()中的已登錄信息
			//調(diào)用AbstractSecurityInterceptor中的AccessDecisionManager對象的decide方法
			//如果對于配置中需要登錄才可訪問的URL,已經(jīng)查找到登錄信息,則執(zhí)行下一個Filter
			InterceptorStatusToken token = super.beforeInvocation(fi);
			try {
				fi.getChain().doFilter(fi.getRequest(), fi.getResponse());
			}
			finally {
				super.finallyInvocation(token);
			}
			super.afterInvocation(token, null);
		}
	}
	/**
	 * Indicates whether once-per-request handling will be observed. By default this is
	 * <code>true</code>, meaning the <code>FilterSecurityInterceptor</code> will only
	 * execute once-per-request. Sometimes users may wish it to execute more than once per
	 * request, such as when JSP forwards are being used and filter security is desired on
	 * each included fragment of the HTTP request.
	 *
	 * @return <code>true</code> (the default) if once-per-request is honoured, otherwise
	 * <code>false</code> if <code>FilterSecurityInterceptor</code> will enforce
	 * authorizations for each and every fragment of the HTTP request.
	 */
	public Boolean isObserveOncePerRequest() {
		return observeOncePerRequest;
	}
	public void setObserveOncePerRequest(Boolean observeOncePerRequest) {
		this.observeOncePerRequest = observeOncePerRequest;
	}
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • java中的內(nèi)存溢出方式

    java中的內(nèi)存溢出方式

    文章介紹了如何使用jmap和IBMHeapAnalyzer等工具分析OutOfMemoryError: Compressedclassspace錯誤,發(fā)現(xiàn)問題出在/org/pf4j/PluginClassLoader加載了大量類
    2024-12-12
  • 關(guān)于Java?float和double精度范圍大小

    關(guān)于Java?float和double精度范圍大小

    這篇文章主要介紹了關(guān)于Java?float和double精度范圍大小,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-12-12
  • Spring AOP手動實現(xiàn)簡單動態(tài)代理的代碼

    Spring AOP手動實現(xiàn)簡單動態(tài)代理的代碼

    今天小編就為大家分享一篇關(guān)于Spring AOP手動實現(xiàn)簡單動態(tài)代理的代碼,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2019-03-03
  • Java中的@Repeatable注解的作用詳解

    Java中的@Repeatable注解的作用詳解

    這篇文章主要介紹了Java中的@Repeatable注解的作用詳解,@Repeatable注解是用來標(biāo)注一個注解在同一個地方可重復(fù)使用的一個注解,使被他注釋的注解可以在同一個地方重復(fù)使用,需要的朋友可以參考下
    2024-01-01
  • springboot jpa 延遲加載問題的2種解決

    springboot jpa 延遲加載問題的2種解決

    這篇文章主要介紹了springboot jpa 延遲加載問題的2種解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-07-07
  • 詳解Java中多線程異常捕獲Runnable的實現(xiàn)

    詳解Java中多線程異常捕獲Runnable的實現(xiàn)

    這篇文章主要介紹了詳解Java中多線程異常捕獲Runnable的實現(xiàn)的相關(guān)資料,希望通過本文能幫助到大家,讓大家理解掌握這樣的知識,需要的朋友可以參考下
    2017-10-10
  • SpringBoot多環(huán)境開發(fā)與日志小結(jié)

    SpringBoot多環(huán)境開發(fā)與日志小結(jié)

    這篇文章主要介紹了SpringBoot多環(huán)境開發(fā)與日志,下面給大家說一下如何基于多環(huán)境開發(fā)做配置獨立管理,務(wù)必掌握,需要的朋友可以參考下
    2022-08-08
  • 使用Java Servlet生成動態(tài)二維碼的實現(xiàn)步驟

    使用Java Servlet生成動態(tài)二維碼的實現(xiàn)步驟

    在現(xiàn)代互聯(lián)網(wǎng)時代,二維碼廣泛應(yīng)用于各個領(lǐng)域,包括支付、認(rèn)證、信息傳遞等,在Web開發(fā)中,通過Java Servlet生成動態(tài)二維碼是一個常見的需求,本文將介紹如何使用Java Servlet結(jié)合Google的ZXing庫生成動態(tài)二維碼,需要的朋友可以參考下
    2023-11-11
  • JavaCV實現(xiàn)獲取視頻每幀并保存

    JavaCV實現(xiàn)獲取視頻每幀并保存

    這篇文章主要為大家詳細(xì)介紹了JavaCV實現(xiàn)獲取視頻每幀并保存,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-07-07
  • spring中@Autowired自動注入依賴項的使用

    spring中@Autowired自動注入依賴項的使用

    當(dāng)使用@Autowired注解時,它可以自動注入依賴項,例如其他類的實例,本文就來詳細(xì)的介紹一下,具有一定的參考價值,感興趣的可以了解一下
    2023-09-09

最新評論

八宿县| 高平市| 宜昌市| 宁都县| 托克托县| 宁夏| 镇原县| 抚远县| 襄城县| 射洪县| 石嘴山市| 太原市| 南皮县| 嘉定区| 江都市| 曲沃县| 沁源县| 安化县| 土默特右旗| 三穗县| 潜江市| 诸城市| 固原市| 沂源县| 平安县| 嘉祥县| 霍林郭勒市| 阳江市| 高青县| 泰州市| 大余县| 郁南县| 晋城| 特克斯县| 松桃| 桐城市| 名山县| 澄城县| 廊坊市| 大关县| 泸州市|