前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Springsecurity之AuthenticationEntryPoint

Springsecurity之AuthenticationEntryPoint

作者头像
克虏伯
发布2019-04-15 10:21:04
2.4K0
发布2019-04-15 10:21:04
举报

    注意:分析的版本是Springsecurity的4.3.x。

    在ExceptionTranslationFilter中使用到AuthenticationEntryPoint,当ExceptionTranslationFilter截获AuthenticationException

或者AccessDeniedException异常时,就会调用AuthenticationEntryPoint的commence。AuthenticationEntryPoint有很多实现类,我们来看下CasAuthenticationEntryPoint,这个与单点登录有关。先上一张图,如下图1所示。

                                                图1 CasAuthenticationEntryPoint的继承图

    如果查看Springsecurity的cas那部分的文档,会看到如下List-1所示的内容,

List-1

代码语言:javascript
复制
<bean id="casEntryPoint"class="org.springframework.security.cas.web.CasAuthenticationEntryPoint">
	<property name="loginUrl" value="https://localhost:9443/cas/login"/>
	<property name="serviceProperties" ref="serviceProperties"/>
</bean>

<bean id="serviceProperties" class="org.springframework.security.cas.ServiceProperties">
	<property name="service" value="https://localhost:8443/cas-sample/login/cas"/>
	<property name="sendRenew" value="false"/>
</bean>

    CasAuthenticationEntryPoint的commence方法中,如下List-2所示,方法createServiceUrl和createRedirectUrl是构建调用CAS server的url,方法preCommence是空方法体,最后设置respose的redirect地址,这样浏览器收到的是302状态码,然后浏览器访问List-2中的redirectUrl,redirectUrl的值是"https://localhost:9443/cas/login?service=https://localhost:8443/cas-sample/login/cas"。

List-2 

代码语言:javascript
复制
	public final void commence(final HttpServletRequest servletRequest, final HttpServletResponse response,
			final AuthenticationException authenticationException) throws IOException,
			ServletException {

		final String urlEncodedService = createServiceUrl(servletRequest, response);
		final String redirectUrl = createRedirectUrl(urlEncodedService);

		preCommence(servletRequest, response);

		response.sendRedirect(redirectUrl);
	}

    注:List-2中的createServiceUrl和createRedirectUrl在构造Http请求链接的时候,有点复杂,这里就不再细讲。

(adsbygoogle = window.adsbygoogle || []).push({});

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018/11/11 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档