use of io.jans.ca.plugin.adminui.model.auth.UserInfoResponse in project jans by JanssenProject.
the class OAuth2Resource method getUserInfo.
@POST
@Path(OAUTH2_API_USER_INFO)
@Produces(MediaType.APPLICATION_JSON)
public Response getUserInfo(@Valid @NotNull UserInfoRequest userInfoRequest) {
try {
log.info("Get User-Info request to Auth Server.");
UserInfoResponse userInfoResponse = oAuth2Service.getUserInfo(userInfoRequest);
log.info("Get User-Info received from Auth Server.");
return Response.ok(userInfoResponse).build();
} catch (ApplicationException e) {
log.error(ErrorResponse.GET_USER_INFO_ERROR.getDescription(), e);
return Response.status(e.getErrorCode()).entity(e.getMessage()).build();
} catch (Exception e) {
log.error(ErrorResponse.GET_USER_INFO_ERROR.getDescription(), e);
return Response.serverError().entity(e.getMessage()).build();
}
}
use of io.jans.ca.plugin.adminui.model.auth.UserInfoResponse in project jans by JanssenProject.
the class OAuth2Service method getUserInfo.
public UserInfoResponse getUserInfo(UserInfoRequest userInfoRequest) throws ApplicationException {
ApacheHttpClient43Engine engine = new ApacheHttpClient43Engine();
try {
log.debug("Getting User-Info from auth-server: {}", userInfoRequest.getAccessToken());
AUIConfiguration auiConfiguration = auiConfigurationService.getAUIConfiguration();
String accessToken = org.apache.logging.log4j.util.Strings.isNotBlank(userInfoRequest.getAccessToken()) ? userInfoRequest.getAccessToken() : null;
if (Strings.isNullOrEmpty(userInfoRequest.getCode()) && Strings.isNullOrEmpty(accessToken)) {
log.error(ErrorResponse.CODE_OR_TOKEN_REQUIRED.getDescription());
throw new ApplicationException(Response.Status.BAD_REQUEST.getStatusCode(), ErrorResponse.CODE_OR_TOKEN_REQUIRED.getDescription());
}
if (org.apache.logging.log4j.util.Strings.isNotBlank(userInfoRequest.getCode()) && org.apache.logging.log4j.util.Strings.isBlank(accessToken)) {
TokenResponse tokenResponse = getAccessToken(userInfoRequest.getCode());
accessToken = tokenResponse.getAccessToken();
}
log.debug("Access Token : {}", accessToken);
MultivaluedMap<String, String> body = new MultivaluedHashMap<>();
body.putSingle("access_token", accessToken);
ResteasyClient client = ((ResteasyClientBuilder) ClientBuilder.newBuilder()).httpEngine(engine).build();
ResteasyWebTarget target = client.target(UriBuilder.fromPath(auiConfiguration.getAuthServerUserInfoEndpoint()));
Response response = target.request().header("Authorization", "Bearer " + accessToken).post(Entity.form(body));
log.debug("User-Info response status code: {}", response.getStatus());
if (response.getStatus() == 200) {
String entity = response.readEntity(String.class);
log.debug("User-Info response entity: {}", entity);
final Jwt jwtUserInfo = Jwt.parse(entity);
log.debug("User-Info response jwtUserInfo: {}", jwtUserInfo);
UserInfoResponse userInfoResponse = new UserInfoResponse();
userInfoResponse.setClaims(getClaims(jwtUserInfo));
userInfoResponse.setJwtUserInfo(entity);
log.debug("User-Info response userInfoResponse: {}", userInfoResponse);
return userInfoResponse;
}
} catch (ApplicationException e) {
log.error(ErrorResponse.GET_USER_INFO_ERROR.getDescription());
throw e;
} catch (Exception e) {
log.error(ErrorResponse.GET_USER_INFO_ERROR.getDescription(), e);
throw new ApplicationException(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), ErrorResponse.GET_USER_INFO_ERROR.getDescription());
} finally {
if (engine != null) {
engine.close();
}
}
return null;
}
Aggregations