generator-jhipster: SecurityUtils .getCurrentUserLogin in a microservice returns "null" with OAuth2 and Okta
Overview of the issue
Calling SecurityUtils.getCurrentUserLogin() in a microservice returns null instead of the user login
Motivation for or Use Case
It should be possible to retrieve the user from the security context
Reproduce the error
Use SecurityUtils.getCurrentUserLogin() in a microservice using Okta for the authentication
Related issues
Suggest a Fix
} else if (authentication instanceof JwtAuthenticationToken) {
return (String) ((JwtAuthenticationToken)authentication).getToken().getClaims().get("preferred_username");
} else if (authentication.getPrincipal() instanceof DefaultOidcUser) {
preferred_username doesn’t exist when using Okta, is it specific to Keycloak?
JHipster Version(s)
store@0.0.0 /Users/theo/Documents/perso/oauth2/store
└── generator-jhipster@6.5.1
JDL for the Entity configuration(s) entityName.json files generated in the .jhipster directory
JDL entity definitions
application {
config {
baseName gateway,
packageName com.jhipster.gateway,
applicationType gateway,
authenticationType oauth2,
prodDatabaseType postgresql,
serviceDiscoveryType eureka
}
entities Product
}
application {
config {
baseName store,
packageName com.jhipster.store,
applicationType microservice,
authenticationType oauth2,
prodDatabaseType postgresql,
serviceDiscoveryType eureka
serverPort 8081
}
entities Product
}
entity Product {
title String
}
microservice Product with store
Environment and Tools
openjdk version “11.0.4” 2019-07-16 OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.4+11) OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.4+11, mixed mode)
git version 2.23.0
node: v10.17.0
npm: 6.11.3
yeoman: 3.1.1
Docker version 19.03.5, build 633a0ea
docker-compose version 1.24.1, build 4667896b
Browsers and Operating System
- Checking this box is mandatory (this is just to show you read everything)
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 27 (25 by maintainers)
@mraible I think it’s because
groupsis an ArrayNode soasText()doesn’t work.I did a new commit https://github.com/Falydoor/jhipster-oauth2/commit/16bf5c4df1279c6ce076b58cea011d7026313f63, maybe that’s more clear!