我正在使用grails spring安全插件。當我登錄時,我獲取用戶名和標記和角色作爲json響應。隨着這些屬性,我想獲得一些其他的屬性,如名字,姓氏等。我怎樣才能得到這些值作爲JSON響應登錄到應用程序使用Grails的春天安全休息插件?當使用grails spring security rest插件登錄時獲取用戶詳細信息
1
A
回答
1
可以添加標記的權利要求,我一般會建議對修改所述插件代碼,但
可以(通過重寫它或優選地)通過在
AbstractJwtTokenGenerator
增加新的權利要求添加期望的細節
JWTClaimsSet generateClaims(UserDetails details, String serializedPrincipal, Integer expiration) {
JWTClaimsSet claimsSet = new JWTClaimsSet()
claimsSet.setSubject(details.username)
log.debug "Setting expiration to ${expiration}"
Date now = new Date()
claimsSet.setIssueTime(now)
use(TimeCategory) {
claimsSet.setExpirationTime(now + expiration.seconds)
}
claimsSet.setCustomClaim('roles', details.authorities?.collect { it.authority })
claimsSet.setCustomClaim('principal', serializedPrincipal)
//claimsSet.setCustomClaim('username', details.getUsername()) //added customized user name claim
log.debug "Generated claim set: ${claimsSet.toJSONObject().toString()}"
return claimsSet
}
注:主題在claimsSet.setSubject(details.username)
已經包含了用戶名
+1
謝謝。我會試試這個 – Jagadeesh
0
據docs:
如果你想呈現更多的信息在你的JSON響應, 你必須:
配置替代的UserDetailsService的bean獲取你想要的更多信息,以及把它放在一個主要的對象。
配置從restAuthenticationToken.principal對象中讀取該信息的替代accessTokenJsonRenderer。
相關問題
- 1. 當前用戶登錄詳細信息
- 2. 使用Spring Security登錄登錄時的用戶代理信息
- 3. 在用戶登錄Facebook後獲取用戶詳細信息
- 4. 獲取最後登錄詳細信息
- 5. ActiveDirectoryLdapAuthenticationProvider:獲取用戶詳細信息
- 6. 獲取已登錄的用戶詳細信息在sharepoint c#webpart
- 7. Twitter集成 - 如何獲取用戶登錄詳細信息?
- 8. 通過會話獲取登錄用戶的詳細信息
- 9. 獲取登錄用戶的詳細信息
- 10. 從Push API登錄獲取用戶詳細信息
- 11. SugarCRM,通過AJAX調用獲取當前登錄的用戶詳細信息
- 12. 如何獲取當前登錄的用戶詳細信息zend框架
- 13. 如何在WordPress中獲取博客的當前登錄用戶詳細信息?
- 14. 模擬Grails Spring Security登錄用戶
- 15. SPNEGO獲取用戶詳細信息
- 16. 從log.nsf獲取用戶詳細信息
- 17. 從MGTwitterEngine獲取用戶詳細信息
- 18. Get-ADGroupMember獲取用戶詳細信息?
- 19. 從Mule Services中訪問Spring Security用戶詳細信息
- 20. Grails 3和Spring Security:當用戶未登錄時返回401
- 21. Grails:如何獲取有關當前登錄用戶的信息?
- 22. 獲取登錄來自Firebase實時數據庫的用戶詳細信息
- 23. Yetanotherforum獲得登錄用戶的詳細信息
- 24. 試用版登錄詳細信息
- 25. 使用自定義用戶詳細信息服務自動登錄的問題
- 26. 在登錄時檢查用戶詳細信息Android
- 27. 使用cURL獲取用戶facebook用戶詳細信息
- 28. Grails Spring Security Core Plugin與Vs. Grails的Spring Security的REST插件
- 29. 獲取用戶的全名登錄使用C#的Windows登錄詳細信息窗體應用程序
- 30. Magento產品詳細信息 - 用戶登錄+客戶組限制?
據我知道你需要索賠添加到令牌用戶的詳細信息,您可以用'springSecurityService?.currentUser',並從中獲取用戶詳細信息有 – shaydel
在登錄時本身我想得到的細節,而不是使另一個請求登錄用戶 – Jagadeesh
@Jagadeesh你解決了嗎? – mrabbani