use of io.jans.as.client.UserInfoRequest in project jans by JanssenProject.
the class UserInfoRestWebServiceEmbeddedTest method requestUserInfoStep2PasswordFlow.
@Parameters({ "userInfoPath" })
@Test(dependsOnMethods = "requestUserInfoStep1PasswordFlow")
public void requestUserInfoStep2PasswordFlow(final String userInfoPath) throws Exception {
Builder request = ResteasyClientBuilder.newClient().target(url.toString() + userInfoPath).request();
request.header("Authorization", "Bearer " + accessToken4);
request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
io.jans.as.client.UserInfoRequest userInfoRequest = new io.jans.as.client.UserInfoRequest(null);
Response response = request.post(Entity.form(new MultivaluedHashMap<String, String>(userInfoRequest.getParameters())));
String entity = response.readEntity(String.class);
showResponse("requestUserInfoStep2PasswordFlow", response, entity);
assertEquals(response.getStatus(), 200, "Unexpected response code.");
assertTrue(response.getHeaderString("Cache-Control") != null && response.getHeaderString("Cache-Control").equals("no-store, private"), "Unexpected result: " + response.getHeaderString("Cache-Control"));
assertTrue(response.getHeaderString("Pragma") != null && response.getHeaderString("Pragma").equals(Constants.NO_CACHE), "Unexpected result: " + response.getHeaderString("Pragma"));
assertNotNull(entity, "Unexpected result: " + entity);
try {
JSONObject jsonObj = new JSONObject(entity);
assertTrue(jsonObj.has(JwtClaimName.SUBJECT_IDENTIFIER));
assertTrue(jsonObj.has(JwtClaimName.NAME));
assertTrue(jsonObj.has(JwtClaimName.GIVEN_NAME));
assertTrue(jsonObj.has(JwtClaimName.FAMILY_NAME));
assertTrue(jsonObj.has(JwtClaimName.EMAIL));
} catch (JSONException e) {
e.printStackTrace();
fail(e.getMessage() + "\nResponse was: " + entity);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of io.jans.as.client.UserInfoRequest in project jans by JanssenProject.
the class UserInfoRestWebServiceEmbeddedTest method requestUserInfoInvalidSchema.
@Parameters({ "userInfoPath" })
@Test
public void requestUserInfoInvalidSchema(final String userInfoPath) throws Exception {
Builder request = ResteasyClientBuilder.newClient().target(url.toString() + userInfoPath).request();
request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
io.jans.as.client.UserInfoRequest userInfoRequest = new io.jans.as.client.UserInfoRequest("INVALID_ACCESS_TOKEN");
Map<String, String> userInfoParameters = userInfoRequest.getParameters();
userInfoParameters.put("schema", "INVALID_SCHEMA");
Response response = request.post(Entity.form(new MultivaluedHashMap<String, String>(userInfoRequest.getParameters())));
String entity = response.readEntity(String.class);
showResponse("requestUserInfoInvalidSchema", response, entity);
assertEquals(response.getStatus(), 400, "Unexpected response code.");
assertNotNull(entity, "Unexpected result: " + entity);
try {
JSONObject jsonObj = new JSONObject(entity);
assertTrue(jsonObj.has("error"), "The error type is null");
assertTrue(jsonObj.has("error_description"), "The error description is null");
} catch (JSONException e) {
e.printStackTrace();
fail(e.getMessage() + "\nResponse was: " + entity);
}
}
Aggregations