主题
Saml2.0集成文档
Saml协议集成需要的jar(依赖文件夹下有全部jar)
修改web.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/securityContext.xml
</param-value>
</context-param>
<servlet>
<servlet-name>saml</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>saml</servlet-name>
<url-pattern>/saml/web/*</url-pattern>
</servlet-mapping>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/error.jsp</location>
</error-page>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
拷贝demo中的配置
sp/WEB-INF/sp.properties
host.name demo域名或者IP:端口 例:ids.wisedu.com或者172.20.6.22:8080
idp.metadata 认证端元数据地址 例:/etc/cas/config/saml/idp-metadata.xml
sp.metadata 集成客户端元数据地址 例:/metadata/sp-metadata.xml
拷贝securityContext.xml,saml-servlet.xml文件(至WEB-INF下)
客户端集成需要注册或者新增sp-metadata.xml
但需要修改几个地方:
1、将ID 改成集成客户端域名,entityID改成域名+上下文,例如
https://saml.example.com/sp1

2、将AssertionConsumerService Location 改成 客户端域名+ /sp/saml/SSO,例如
https://saml.example.com/sp/saml/SSO1

获取用户信息
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
SAMLCredential credential = (SAMLCredential) authentication.getCredentials();
Map<String, Object> map = credential.attributes;
cn = (String)map.get("cn");1
2
3
4
2
3
4

