"Test water CAS-4.0.3" section No. 05 _cas user information returned by the service-side customization

Source: Internet
Author: User

/** * @see------------------------------------------------------------------------------------------------------- -----------------* @see CAS server custom returned user information * @see The returned user information is <bean id= "in Deployerconfigcontext.xml" attributerepository > Configuration * @see since you want to customize the returned user information, then inherit the Org.jasig.services.persondir.support.StubPersonAttributeDao is good * @see 1. Create Com.msxf.sso.authentication extends Stubpersonattributedao and make a replication Getperson () method * @see Use @component (value= " Attributerepository ") defines its Beanid * @see 2. Comment <bean id=" attributerepository "in Deployerconfigcontext.xml > and < Util:map id= "Attrrepobackingmap" > Configuration * @see 3. Modify the \web-inf\view\jsp\protocol\2.0\casservicevalidationsuccess.jsp ( Do not change 3.0 below) * @see specific changes, see the code posted below * @see In addition, the information returned to the client is defined by the Org.jasig.services.persondir.IPersonAttributeDao interface * @see Stubpersonattributedao is one of the Ipersonattributedao implementations, other implementations such as Singlerowjdbcpersonattributedao/ldappersonattributedao * @ See so can also be configured in Deployerconfigcontext.xml <bean id= "Attributerepository" > Implemented as SinglerowjdbcpersonattribuTedao * @see <bean id= "attributerepository" class= " Org.jasig.services.persondir.support.jdbc.SingleRowJdbcPersonAttributeDao "> * @see personally feel that this is not very flexible, so do not post the sample code, Have fun to see http://pkaq.github.io/2015/01/14/CAS/* @see------------------------------------------------------------- -----------------------------------------------------------* @create 2015-7-20 PM 4:59:08 * @author Xuan Yu 

The following is a custom control of the returned user information Userstubpersonattributedao.java

Package Com.msxf.sso.authentication;import Java.io.unsupportedencodingexception;import Java.net.URLEncoder;import Java.util.collections;import Java.util.hashmap;import Java.util.list;import Java.util.map;import Javax.annotation.resource;import Org.jasig.services.persondir.ipersonattributes;import Org.jasig.services.persondir.support.attributenamedpersonimpl;import Org.jasig.services.persondir.support.stubpersonattributedao;import org.springframework.stereotype.Component; Import com.msxf.sso.model.user;/** * Customized information returned to the client * @create 2015-7-18 PM 5:52:56 * @author Xuan Yu The following is the Userdaojdbc.java of the query database used
Package Com.msxf.sso.authentication;import Java.sql.resultset;import Java.sql.sqlexception;import Javax.annotation.resource;import Javax.sql.datasource;import Org.springframework.dao.emptyresultdataaccessexception;import Org.springframework.jdbc.core.jdbctemplate;import Org.springframework.jdbc.core.rowmapper;import Org.springframework.stereotype.repository;import Com.msxf.sso.model.User; @Repositorypublic class Userdaojdbc {private static final String sql_user_verify = "Select COUNT (*) From Permission_operator WHERE operator_login=? and OPERATOR_PWD=SHA1 (?) "; private static final String sql_user_get = "SELECT * from Permission_operator WHERE operator_login=?"; Private JdbcTemplate jdbctemplate; @Resourcepublic void Setdatasource (DataSource DataSource) {this.jdbctemplate = new JdbcTemplate (DataSource);} /** * Verify the username and password are correct * @create 2015-7-17 pm 3:56:54 * @author Jade Here are the User.java used
Package Com.msxf.sso.model;public class User {private string usercode;private string Username;private string Usernameplain;public String Getusercode () {return usercode;} public void Setusercode (String usercode) {this.usercode = Usercode;} Public String GetUserName () {return username;} public void Setusername (String username) {this.username = username;} Public String Getusernameplain () {return usernameplain;} public void Setusernameplain (String usernameplain) {this.usernameplain = Usernameplain;}}
here is the modified section of Deployerconfigcontext.xml
<!--comment out the default attributerepository implementation with custom Userstubpersonattributedao-   <!--    <bean id= " Attributerepository "class=" Org.jasig.services.persondir.support.StubPersonAttributeDao "           p:backingmap-ref=" Attrrepobackingmap "/>      <util:map id=" Attrrepobackingmap ">       <entry key=" UID "value=" UID "/>       <entry key= "edupersonaffiliation" value= "edupersonaffiliation"/> <entry        key= "GroupMembership" Value= "Groupmembership"/>   </util:map>
here's \web-inf\view\jsp\protocol\2.0\casservicevalidationsuccess.jsp .
<%--Licensed to Jasig under one or more contributor license agreements.    See the NOTICE file distributed with this work for additional information regarding copyright ownership. Jasig licenses this file to you under the Apache License, Version 2.0 (the "License");  You are not a use of this file except in compliance with the License. Obtain a copy of the License at the following location:http://www.apache.org/licenses/license-2.0 Unle SS required by applicable law or agreed to in writing, software distributed under the License are 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.--%><%@ page Session= "false" contenttype= "application/xml; Charset=utf-8 "%><%@ taglib prefix=" C "uri=" Http://java.sun.com/jsp/jstl/core "%><%@ taglib uri="/http/ Java.sun.com/jsp/jstl/functiONS "prefix=" FN "%><cas:serviceresponse xmlns:cas= ' Http://www.yale.edu/tp/cas ' ><cas: Authenticationsuccess><cas:user>${fn:escapexml (assertion.primaryAuthentication.principal.id)}</cas :user> <c:if test= "${not Empty Pgtiou}" > <cas:proxygrantingticket>${pgtiou}</cas:proxygran tingticket> </c:if> <c:if test= "${fn:length (assertion.chainedauthentications) > 1}" > < cas:proxies> <c:foreach var= "proxy" items= "${assertion.chainedauthentications}" varstatus= "LoopStatus" be gin= "0" end= "${fn:length (assertion.chainedauthentications)-2}" step= "1" > <cas:proxy>${fn:escapexml ( proxy.principal.id)}</cas:proxy> </c:forEach> </cas:proxies> </c:if> &lt The new part of%--is as follows: Casserver validation succeeds, the page is responsible for generating XML information that interacts with the client. The default casservicevalidationsuccess.jsp includes only the user name and does not provide additional property information. Therefore, the page needs to be extended--%><c:if test= "${fn:length (assertion.chainedauthentications[fn:lengtH (assertion.chainedauthentications) -1].principal.attributes) > 0} "><cas:attributes><c:foreach var= "attr" items= "${assertion.chainedauthentications[fn:length (assertion.chainedauthentications)-1]. Principal.attributes} "><cas:${fn:escapexml (Attr.key)}>${fn:escapexml (attr.value)}&LT;/CAS:${FN: EscapeXML (Attr.key)}></c:foreach></cas:attributes></c:if></cas:authenticationsuccess ></cas:serviceResponse>
Finally, the client gets the index.jsp of the custom user information returned by the server .
<%@ page pageencoding= "UTF-8"%><%@ page import= "java.util.Map"%><%@ page import= "Java.net.URLDecoder" %><%@ page import= "org.jasig.cas.client.util.AssertionHolder"%><%@ page import= " Org.jasig.cas.client.authentication.AttributePrincipal "%><body style=" Background-color: #CBE0C9; " ><span style= "color:red; font-size:32px; Font-weight:bold; " > Client Login succeeded </span></body>


For details on how the client is configured (including through spring), see the next blog post.

Today, the headache is still a fever, tomorrow again the client configuration method.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

"Test water CAS-4.0.3" section No. 05 _cas user information returned by the service-side customization

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.