无法在CAS客户端

时间:2017-05-01 09:25:21

标签: java spring-boot cas

我正在尝试在我的一个应用程序中为SSO设置CAS。 我已经用CAS 5.x版本设置了CAS服务器,这对我来说很好。现在我想在CAS客户端中获取用户的详细信息,如电子邮件,角色,姓名等,以维护用户的会话。

请在下面找到CAS服务器的application.properties:

##
# CAS Server Context Configuration
#
server.context-path=/cas
server.port=8443

logging.level.org.apereo=DEBUG
cas.authn.accept.users=


#database connection credentials

cas.authn.jdbc.query[0].sql=SELECT password FROM user WHERE email=?
cas.authn.jdbc.query[0].healthQuery=SELECT 1 FROM DB.user
cas.authn.jdbc.query[0].isolateInternalQueries=false
cas.authn.jdbc.query[0].url=jdbc:mysql://172.16.25.137:3306/DB
cas.authn.jdbc.query[0].failFast=true
cas.authn.jdbc.query[0].isolationLevelName=ISOLATION_READ_COMMITTED
cas.authn.jdbc.query[0].dialect=org.hibernate.dialect.MySQL5Dialect
cas.authn.jdbc.query[0].leakThreshold=10
cas.authn.jdbc.query[0].propagationBehaviorName=PROPAGATION_REQUIRED
cas.authn.jdbc.query[0].user=envision
cas.authn.jdbc.query[0].maxAgeDays=180
cas.authn.jdbc.query[0].password=envision@123
cas.authn.jdbc.query[0].driverClass=com.mysql.jdbc.Driver

cas.authn.jdbc.query[0].passwordEncoder.type=BCRYPT
cas.authn.jdbc.query[0].passwordEncoder.characterEncoding=UTF-8
cas.authn.jdbc.query[0].fieldPassword=password

cas.authn.accept.users=
cas.authn.accept.passwordEncoder.type=BCRYPT
cas.authn.accept.passwordEncoder.characterEncoding=UTF-8
cas.authn.accept.passwordEncoder.encodingAlgorithm=BCryptPasswordEncoder
cas.authn.accept.passwordEncoder.secret=
cas.authn.accept.passwordEncoder.strength=16

server.ssl.key-store=file:/etc/cas/thekeystore
server.ssl.key-store-password=changeit
server.ssl.key-password=changeit
server.max-http-header-size=2097152
server.max-http-post-size=2097152
server.use-forward-headers=true

server.tomcat.basedir=build/tomcat
server.tomcat.accesslog.enabled=true
server.tomcat.accesslog.pattern=%t %a "%r" %s (%D ms)
server.tomcat.accesslog.suffix=.log
server.tomcat.max-threads=5
server.tomcat.port-header=X-Forwarded-Port
server.tomcat.protocol-header=X-Forwarded-Proto
server.tomcat.protocol-header-https-value=https
server.tomcat.remote-ip-header=X-FORWARDED-FOR
server.tomcat.uri-encoding=UTF-8
server.error.include-stacktrace=ALWAYS

spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
spring.http.encoding.force=true

endpoints.enabled=true
endpoints.sensitive=true
management.context-path=/status
endpoints.restart.enabled=false
endpoints.shutdown.enabled=false




# CAS Log4j Configuration
#
# logging.config=file:/etc/cas/log4j2.xml
server.context-parameters.isLog4jAutoInitializationDisabled=true

cas.authn.oauth.refreshToken.timeToKillInSeconds=2592000
cas.authn.oauth.code.timeToKillInSeconds=30
cas.authn.oauth.code.numberOfUses=1
cas.authn.oauth.accessToken.timeToKillInSeconds=7200
cas.authn.oauth.accessToken.maxTimeToLiveInSeconds=28800

# Attributes that you wish to resolve for the principal
cas.authn.attributeRepository.attributes.uid=email
cas.authn.attributeRepository.attributes.displayName=first_name
cas.authn.attributeRepository.attributes.cn=email

请在下面找到代码以获取AttributePrincipal的详细信息:

AttributePrincipal principal = (AttributePrincipal) request.getUserPrincipal();
        if(principal != null){
         Map<String, Object> attributes = principal.getAttributes();
         if(attributes != null){
         for (Map.Entry<String, Object> entry : attributes.entrySet())
         {
             System.out.println(entry.getKey() + "/" + entry.getValue());
         }
         }
        }

请建议我是否需要在server.properties服务器中设置任何其他属性,或者我是否需要在客户端应用程序中实现任何接口以获取用户的属性。

1 个答案:

答案 0 :(得分:0)

我认为您需要在application.properties中设置cas.authn.attributeRepository.jdbc *属性以获取用户在jdbc模式下的属性。