在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/Java/ cas 5.2.4使用REST API返回401 Unauthorized 錯(cuò)誤

cas 5.2.4使用REST API返回401 Unauthorized 錯(cuò)誤,求解

按照官網(wǎng)文檔中關(guān)于 REST Protocol 說(shuō)明,加入了依賴。

<dependency>
    <groupId>org.apereo.cas</groupId>
    <artifactId>cas-server-support-rest</artifactId>
    <version>${cas.version}</version>
</dependency>

但是使用PostMan模擬請(qǐng)求時(shí),會(huì)遇到401 Unauthorized 錯(cuò)誤,無(wú)解中...

clipboard.png

另外,控制臺(tái)報(bào)錯(cuò)信息為:

Authentication has failed. Credentials may be incorrect or CAS cannot find authentication handler that supports [zhangsan] of type [UsernamePasswordCredential]

因?yàn)榈顷戇壿嬛刑砑恿蓑?yàn)證碼,也就是自定義Credential和處理Handler了,表單登陸正常,但就是Rest API不行,第一步TGT都無(wú)法獲取,求助各位大神!

回答
編輯回答
朕略傻

已經(jīng)解決了,原因是:CAS Server自帶的REST API,僅支持默認(rèn)UsernamePasswordCredential,我的項(xiàng)目中自定義擴(kuò)展了UsernamePasswordCredential,所以需要在自定義驗(yàn)證Handler中做個(gè)判斷,如果請(qǐng)求的Credential類型為org.apereo.cas.authentication.UsernamePasswordCredential, 就是REST請(qǐng)求來(lái)的,直接返回對(duì)應(yīng)的UsernamePasswordCredential對(duì)象即可。

2017年3月20日 03:13