use of org.eclipse.vorto.repository.oauth.internal.JwtToken in project vorto by eclipse.
the class BoschIoTSuiteOAuthProviderAuthCode method createAuthentication.
private OAuth2Authentication createAuthentication(JwtToken accessToken) {
Map<String, Object> tokenPayload = accessToken.getPayloadMap();
Optional<String> email = Optional.ofNullable((String) tokenPayload.get(JWT_EMAIL));
Optional<String> name = Optional.ofNullable((String) tokenPayload.get(JWT_NAME)).map(str -> str.split("@")[0]);
String userId = getUserId(tokenPayload).orElseThrow(() -> new InvalidTokenException("Cannot generate a userId from your provided token. Maybe 'sub' or 'client_id' is not present in JWT token?"));
return Optional.ofNullable(userAccountService.getUser(userId)).map(user -> createAuthentication(this.clientId, userId, name.orElse(userId), email.orElse(null), userNamespaceRoleService.getRolesOnAllNamespaces(user))).orElse(null);
}
Aggregations