More user information is returned in cas4.0 session.

Source: Internet
Author: User

More user information is returned in cas4.0 session.

Implementation ideas:
Added the AccoutAttributeDao class to inherit StubPersonAttributeDao and override the getPerson method. In actual application, we only need to modify the content in the getPersion method and modify the query statement according to the actual situation. Which fields are stored by attributes. put.
Note:: Use URLEncoder. encode to encode Chinese characters, and use URLDecode. decode to decode them.

// Uid corresponds to the username on the login page
Public IPersonAttributes getPerson (String uid ){
String SQL = "";
SQL = "select * from sys_right_user where user_account =? ";
Final Map values = jdbcTemplate. queryForMap (SQL, uid );
Map <String, List <Object> attributes = new HashMap <String, List <Object> ();
List <Object> o = Collections. singletonList (Object) URLEncoder. encode (String. valueOf (values. get ("user_name "))));

Attributes. put ("username", o );
Attributes. put ("email", Collections. singletonList (Object) values. get ("email ")));
Attributes. put ("mobile", Collections. singletonList (Object) values. get ("mobile ")));
Attributes. put ("userid", Collections. singletonList (Object) values. get ("user_id ")));
Return new AttributeNamedPersonImpl (attributes );
}

Modify the attributeRepository class in deployerConfigContext. xml:
Configure jdbcTemplate
<Bean id = "attributeRepository" class = "org. jasig. services. persondir. support. AccoutAttributeDao">
<Property name = "jdbcTemplate" ref = "jdbcTemplate"> </property>
</Bean>
<Bean id = "jdbcTemplate" class = "org. springframework. jdbc. core. JdbcTemplate">
<Property name = "dataSource">
<Ref bean = "queryDatabaseDataSource"/>
</Property>
</Bean>

Modify \ view \ jsp \ protocol \ 2.0 \ casServiceValidationSuccess. jsp. Refer to the page in the attachment.
How to get the variable:
Object object = session. getAttribute ("_ const_cas_assertion _");
Assertion assertion = (Assertion) object;
Map <String, Object> map = assertion. getPrincipal (). getAttributes ()
Use map. get ("email.

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.