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.