﻿{"id":292,"date":"2015-07-22T16:59:15","date_gmt":"2015-07-22T08:59:15","guid":{"rendered":"http:\/\/blog.sway.com.cn\/?p=292"},"modified":"2015-07-22T16:59:15","modified_gmt":"2015-07-22T08:59:15","slug":"cas%e8%bf%94%e5%9b%9e%e6%9b%b4%e5%a4%9a%e7%94%a8%e6%88%b7%e4%bf%a1%e6%81%af","status":"publish","type":"post","link":"http:\/\/blog.sway.com.cn\/?p=292","title":{"rendered":"CAS\u8fd4\u56de\u66f4\u591a\u7528\u6237\u4fe1\u606f"},"content":{"rendered":"<p>1.\u4fee\u6539deployerConfigContext.xml\u6587\u4ef6<\/p>\n<p>&nbsp;<\/p>\n<p>2.\u4fee\u6539casServiceValidationSuccess.jsp\u6587\u4ef6<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>3.\u6700\u540e\u4fee\u6539client\u7aef\u7684web.xml\u6587\u4ef6:<\/p>\n<pre class=\"lang:default decode:true\">\t&lt;!-- ======================== \u5355\u70b9\u767b\u5f55\u5f00\u59cb ======================== --&gt;\r\n\t&lt;!-- \u7528\u4e8e\u5355\u70b9\u9000\u51fa\uff0c\u8be5\u8fc7\u6ee4\u5668\u7528\u4e8e\u5b9e\u73b0\u5355\u70b9\u767b\u51fa\u529f\u80fd\uff0c\u53ef\u9009\u914d\u7f6e --&gt;\r\n\t&lt;listener&gt;\r\n\t\t&lt;listener-class&gt;org.jasig.cas.client.session.SingleSignOutHttpSessionListener&lt;\/listener-class&gt;\r\n\t&lt;\/listener&gt;\r\n\t&lt;filter&gt;\r\n\t\t&lt;filter-name&gt;CAS Single Sign Out Filter&lt;\/filter-name&gt;\r\n\t\t&lt;filter-class&gt;org.jasig.cas.client.session.SingleSignOutFilter&lt;\/filter-class&gt;\r\n\t&lt;\/filter&gt;\r\n\t&lt;filter-mapping&gt;\r\n\t\t&lt;filter-name&gt;CAS Single Sign Out Filter&lt;\/filter-name&gt;\r\n\t\t&lt;url-pattern&gt;\/*&lt;\/url-pattern&gt;\r\n\t&lt;\/filter-mapping&gt;\r\n\r\n\t&lt;filter&gt;\r\n\t\t&lt;filter-name&gt;CAS Filter&lt;\/filter-name&gt;\r\n\t\t&lt;filter-class&gt;org.jasig.cas.client.authentication.AuthenticationFilter&lt;\/filter-class&gt;\r\n\t\t&lt;init-param&gt;\r\n\t\t\t&lt;param-name&gt;casServerLoginUrl&lt;\/param-name&gt;\r\n\t\t\t&lt;param-value&gt;http:\/\/localhost:8080\/cas&lt;\/param-value&gt;\r\n\t\t&lt;\/init-param&gt;\r\n\t\t&lt;init-param&gt;\r\n\t\t\t&lt;param-name&gt;serverName&lt;\/param-name&gt;\r\n\t\t\t&lt;param-value&gt;http:\/\/localhost:8080&lt;\/param-value&gt;\r\n\t\t&lt;\/init-param&gt;\r\n\t&lt;\/filter&gt;\r\n\t&lt;filter-mapping&gt;\r\n\t\t&lt;filter-name&gt;CAS Filter&lt;\/filter-name&gt;\r\n\t\t&lt;url-pattern&gt;\/*&lt;\/url-pattern&gt;\r\n\t&lt;\/filter-mapping&gt;\r\n\r\n\t&lt;!-- \u8be5\u8fc7\u6ee4\u5668\u8d1f\u8d23\u5bf9Ticket\u7684\u6821\u9a8c\u5de5\u4f5c\uff0c\u5fc5\u987b\u542f\u7528\u5b83 --&gt;\r\n\t&lt;filter&gt;\r\n\t\t&lt;filter-name&gt;CAS Validation Filter&lt;\/filter-name&gt;\r\n\t\t&lt;filter-class&gt;\r\n\t\t\torg.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter\r\n\t\t&lt;\/filter-class&gt;\r\n\t\t&lt;init-param&gt;\r\n\t\t\t&lt;param-name&gt;casServerUrlPrefix&lt;\/param-name&gt;\r\n\t\t\t&lt;param-value&gt;http:\/\/localhost:8080\/cas&lt;\/param-value&gt;\r\n\t\t&lt;\/init-param&gt;\r\n\t\t&lt;init-param&gt;\r\n\t\t\t&lt;param-name&gt;serverName&lt;\/param-name&gt;\r\n\t\t\t&lt;param-value&gt;http:\/\/localhost:8080&lt;\/param-value&gt;\r\n\t\t&lt;\/init-param&gt;\r\n\t\t&lt;init-param&gt;\r\n\t\t\t&lt;param-name&gt;encoding&lt;\/param-name&gt;\r\n\t\t\t&lt;param-value&gt;UTF-8&lt;\/param-value&gt;\r\n\t\t&lt;\/init-param&gt;\r\n\t&lt;\/filter&gt;\r\n\t&lt;filter-mapping&gt;\r\n\t\t&lt;filter-name&gt;CAS Validation Filter&lt;\/filter-name&gt;\r\n\t\t&lt;url-pattern&gt;\/*&lt;\/url-pattern&gt;\r\n\t&lt;\/filter-mapping&gt;\r\n\r\n\t&lt;!-- \u8be5\u8fc7\u6ee4\u5668\u8d1f\u8d23\u5b9e\u73b0HttpServletRequest\u8bf7\u6c42\u7684\u5305\u88f9\uff0c --&gt;\r\n\t&lt;!-- \u6bd4\u5982\u5141\u8bb8\u5f00\u53d1\u8005\u901a\u8fc7HttpServletRequest\u7684getRemoteUser()\u65b9\u6cd5\u83b7\u5f97SSO\u767b\u5f55\u7528\u6237\u7684\u767b\u5f55\u540d\uff0c\u53ef\u9009\u914d\u7f6e\u3002 --&gt;\r\n\r\n\t&lt;filter&gt;\r\n\t\t&lt;filter-name&gt;CAS HttpServletRequest Wrapper Filter&lt;\/filter-name&gt;\r\n\t\t&lt;filter-class&gt;\r\n\t\t\torg.jasig.cas.client.util.HttpServletRequestWrapperFilter\r\n\t\t&lt;\/filter-class&gt;\r\n\t&lt;\/filter&gt;\r\n\t&lt;filter-mapping&gt;\r\n\t\t&lt;filter-name&gt;CAS HttpServletRequest Wrapper Filter&lt;\/filter-name&gt;\r\n\t\t&lt;url-pattern&gt;\/*&lt;\/url-pattern&gt;\r\n\t&lt;\/filter-mapping&gt;\r\n\r\n\t&lt;!-- \u8be5\u8fc7\u6ee4\u5668\u4f7f\u5f97\u5f00\u53d1\u8005\u53ef\u4ee5\u901a\u8fc7org.jasig.cas.client.util.AssertionHolder\u6765\u83b7\u53d6\u7528\u6237\u7684\u767b\u5f55\u540d\u3002 --&gt;\r\n\t&lt;!-- \u6bd4\u5982AssertionHolder.getAssertion().getPrincipal().getName()\u3002\u6839\u636e\u5ba2\u6237\u7aef\u83b7\u53d6\u7684\u65b9\u5f0f\u53ef\u4ee5\u9009\u62e9\u4f7f\u7528\u8fd9\u4e24\u79cd --&gt;\r\n\r\n\r\n\t&lt;!-- &lt;filter&gt; &lt;filter-name&gt;CAS Assertion Thread Local Filter&lt;\/filter-name&gt; \r\n\t\t&lt;filter-class&gt;org.jasig.cas.client.util.AssertionThreadLocalFilter&lt;\/filter-class&gt; \r\n\t\t&lt;\/filter&gt; &lt;filter-mapping&gt; &lt;filter-name&gt;CAS Assertion Thread Local Filter&lt;\/filter-name&gt; \r\n\t\t&lt;url-pattern&gt;\/*&lt;\/url-pattern&gt; &lt;\/filter-mapping&gt; --&gt;\r\n\r\n\t&lt;!-- ======================== \u5355\u70b9\u767b\u5f55\u7ed3\u675f ======================== --&gt;<\/pre>\n<p>4.\u53ef\u4ee5\u7528\u4ee5\u4e0bjsp\u4ee3\u7801\u6765\u9a8c\u8bc1\u662f\u5426\u6210\u529f\u83b7\u53d6\u7528\u6237\u7684\u66f4\u591a\u4fe1\u606f:<\/p>\n<pre class=\"lang:default decode:true \">\t&lt;%\r\n\tout.write(\"request.getUserPrincipal()=\"+request.getUserPrincipal());\r\n\t%&gt;\r\n\t\r\n\t&lt;br\/&gt;&lt;br\/&gt;\r\n\r\n\r\n&lt;%\r\n\/\/HttpServletRequest request = ServletActionContext.getRequest();\r\n\/*\u83b7\u53d6\u5355\u70b9\u767b\u5f55\u670d\u52a1\u5668\u4f20\u9012\u8fc7\u6765\u7684\u7528\u6237\u4fe1\u606f*\/\r\nAttributePrincipal principal = (AttributePrincipal) request.getUserPrincipal();\r\nif (principal!=null) {\r\n\tout.write(\"principal\u4e0d\u4e3a\u7a7a...\");\r\n\tMap&lt;String, Object&gt; attributes = principal.getAttributes();\r\n\tfor (String key : attributes.keySet()) {\r\n\t\tSystem.out.println(key+\"=\"+attributes.get(key));\r\n\t}\r\n}else{\r\n\tout.write(\"principal\u4e3a\u7a7a...\");\r\n}\r\n%&gt;<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1.\u4fee\u6539deployerConfigContext.xml\u6587\u4ef6 &nbsp; 2 &hellip; <a href=\"http:\/\/blog.sway.com.cn\/?p=292\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[55],"tags":[56],"class_list":["post-292","post","type-post","status-publish","format-standard","hentry","category-sso","tag-cas"],"_links":{"self":[{"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/292","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=292"}],"version-history":[{"count":1,"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/292\/revisions"}],"predecessor-version":[{"id":293,"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/292\/revisions\/293"}],"wp:attachment":[{"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=292"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=292"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=292"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}