Source:
public String assertUser(RestRequest request){ return executePrivilegedAction(new PrivilegedAction<String>() { @Override public String run() { String username = null; final String user = getUser(request); final String token = getBearerToken(request); ConfigBuilder builder = new ConfigBuilder().withOauthToken(token); try (DefaultOpenShiftClient osClient = new DefaultOpenShiftClient(builder.build())) { LOGGER.debug("Verifying user matches the given token.", user); Request okRequest = new Request.Builder() .addHeader(AUTHORIZATION_HEADER, "Bearer " + token) .url(osClient.getMasterUrl() + "oapi/v1/users/~") .build(); Response response = null; try { response = osClient.getHttpClient().newCall(okRequest).execute(); final String body = response.body().string(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Response: code '{}' {}", response.code(), body); } if(response.code() != RestStatus.OK.getStatus()) { throw new ElasticsearchSecurityException("Could not authenticate with given token", RestStatus.UNAUTHORIZED); } Map<String, Object> userResponse = XContentHelper.convertToMap(XContentFactory.xContent(body), body, false); if(userResponse.containsKey("metadata") && ((Map)userResponse.get("metadata")).containsKey("name")) { username = (String) ((Map)userResponse.get("metadata")).get("name"); } }catch (Exception e) { LOGGER.error("Exception trying to assertUser '{}'", e, user); } if(StringUtils.isNotBlank(username) && StringUtils.isNotBlank(user) && !user.equals(username)) { String message = String.format("The given username '%s' does not match the username '%s' associated with the token provided with the request.", user, username); LOGGER.debug(message); } } if (null == username) { throw new ElasticsearchSecurityException("Could not determine username from token", RestStatus.UNAUTHORIZED); } return username; } }); }

Target:
public String assertUser(RestRequest request){ return executePrivilegedAction(new PrivilegedAction<String>() { @Override public String run() { String username = null; final String user = getUser(request); final String token = getBearerToken(request); ConfigBuilder builder = new ConfigBuilder().withOauthToken(token); try (DefaultOpenShiftClient osClient = new DefaultOpenShiftClient(builder.build())) { LOGGER.debug("Verifying user matches the given token.", user); Request okRequest = new Request.Builder() .addHeader(AUTHORIZATION_HEADER, "Bearer " + token) .url(osClient.getMasterUrl() + "oapi/v1/users/~") .build(); Response response = null; try { response = osClient.getHttpClient().newCall(okRequest).execute(); final String body = response.body().string(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Response: code '{}' {}", response.code(), body); } if(response.code() != RestStatus.OK.getStatus()) { throw new ElasticsearchSecurityException("", RestStatus.UNAUTHORIZED); } Map<String, Object> userResponse = XContentHelper.convertToMap(XContentFactory.xContent(body), body, false); if(userResponse.containsKey("metadata") && ((Map)userResponse.get("metadata")).containsKey("name")) { username = (String) ((Map)userResponse.get("metadata")).get("name"); } }catch (Exception e) { LOGGER.error("Exception trying to assertUser '{}'", e, user); } if(StringUtils.isNotBlank(username) && StringUtils.isNotBlank(user) && !user.equals(username)) { String message = String.format("The given username '%s' does not match the username '%s' associated with the token provided with the request.", user, username); LOGGER.debug(message); } } if (null == username) { throw new ElasticsearchSecurityException("", RestStatus.UNAUTHORIZED); } return username; } }); }