我已经设置了一个名为" UserCenter"的应用程序。这是.yo-rc.json
{
"generator-jhipster": {
"jhipsterVersion": "3.12.0",
"baseName": "UserCenter",
"packageName": "com.company.test.user",
"packageFolder": "com/company/test/user",
"serverPort": "19090",
"authenticationType": "oauth2",
"hibernateCache": "hazelcast",
"clusteredHttpSession": false,
"websocket": false,
"databaseType": "sql",
"devDatabaseType": "mysql",
"prodDatabaseType": "mysql",
"searchEngine": false,
"messageBroker": false,
"buildTool": "maven",
"enableSocialSignIn": false,
"useSass": true,
"applicationType": "monolith",
"testFrameworks": [
"gatling"
],
"jhiPrefix": "jhi",
"enableTranslation": true,
"nativeLanguage": "zh-cn",
"languages": [
"zh-cn",
"en"
],
"serviceDiscoveryType": false
}
}
另一个名为" MsgCenter"这是.yo-rc.json
{
"generator-jhipster": {
"jhipsterVersion": "3.12.0",
"baseName": "MsgCenter",
"packageName": "com.company.test.msg",
"packageFolder": "com/company/test/msg",
"serverPort": "19002",
"authenticationType": "session-based",
"hibernateCache": "hazelcast",
"clusteredHttpSession": false,
"websocket": false,
"databaseType": "sql",
"devDatabaseType": "mysql",
"prodDatabaseType": "mysql",
"searchEngine": false,
"messageBroker": false,
"buildTool": "maven",
"enableSocialSignIn": true,
"useSass": true,
"applicationType": "monolith",
"testFrameworks": [
"gatling"
],
"jhiPrefix": "jhi",
"enableTranslation": true,
"nativeLanguage": "zh-cn",
"languages": [
"zh-cn",
"en"
],
"serviceDiscoveryType": false,
"skipUserManagement": true
}
}
我想让MsgCenter通过UserCenter Oauth2登录。我怎么去?
添加信息: 我找到了这个页面How to perform actions on successful login via OAuth2 in jhipster
我不确定。
答案 0 :(得分:1)
使用当前设置,第二个名为" MsgCenter"的应用程序最初配置为拥有自己的用户管理。目前,没有为monoliths的oauth2 authserver自动生成的计数器部分(JHipster的默认选项)。
如何通过执行以下步骤将MsgCenter转换为oauth2资源服务器:
首先,将WebSecurityConfiguration更改为ResourceServerConfiguration(使用@EnableResourceServer
)。如果您使用UAA方案生成JHipster微服务,则有示例如何执行此操作。但是,而不是JWT,你做正常的"通过用户信息URI的方式,并像这样配置
security:
oauth2:
client:
clientId: jhipsterOauth2SampleApplicationapp
clientSecret: my-secret-token-to-change-in-production # if still default
accessTokenUri: http://UserCenterUrl/oauth/access_token
userAuthorizationUri: http://UserCenterUrl/dialog/oauth
resource:
userInfoUri: http://UserCenterUrl/account
请参阅https://spring.io/blog/2015/02/03/sso-with-oauth2-angular-js-and-spring-security-part-v及其后的链接
在第二步中,您应该从MsgCenter中删除用户管理,因为不再需要它。
此方法使用授权流,资源服务器通过用户信息uri检索用户详细信息。
另一种方法是使用JWT令牌。 JHipster提供完整的oauth2设置,其中microservice UAA setup中的授权和资源服务器相互连接,这可能会帮助您作为示例代码来查找正确的实现。