Search in sources :

Example 41 with GrantType

use of io.jans.as.model.common.GrantType in project jans by JanssenProject.

the class TokenRestWebServiceWithRSAlgEmbeddedTest method requestAccessTokenWithClientSecretJwtRS512Step1.

@Parameters({ "registerPath", "redirectUris", "clientJwksUri" })
@Test
public void requestAccessTokenWithClientSecretJwtRS512Step1(final String registerPath, final String redirectUris, final String jwksUri) throws Exception {
    Builder request = ResteasyClientBuilder.newClient().target(url.toString() + registerPath).request();
    RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "jans test app", StringUtils.spaceSeparatedToList(redirectUris));
    registerRequest.setJwksUri(jwksUri);
    registerRequest.setTokenEndpointAuthMethod(AuthenticationMethod.PRIVATE_KEY_JWT);
    registerRequest.addCustomAttribute("jansTrustedClnt", "true");
    List<GrantType> grantTypes = Arrays.asList(GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS);
    registerRequest.setGrantTypes(grantTypes);
    String registerRequestContent = ServerUtil.toPrettyJson(registerRequest.getJSONParameters());
    Response response = request.post(Entity.json(registerRequestContent));
    String entity = response.readEntity(String.class);
    showResponse("requestAccessTokenWithClientSecretJwtRS512Step1", response, entity);
    assertEquals(response.getStatus(), 201, "Unexpected response code. " + entity);
    assertNotNull(entity, "Unexpected result: " + entity);
    try {
        JSONObject jsonObj = new JSONObject(entity);
        assertTrue(jsonObj.has(RegisterResponseParam.CLIENT_ID.toString()));
        assertTrue(jsonObj.has(CLIENT_SECRET.toString()));
        assertTrue(jsonObj.has(REGISTRATION_ACCESS_TOKEN.toString()));
        assertTrue(jsonObj.has(REGISTRATION_CLIENT_URI.toString()));
        assertTrue(jsonObj.has(CLIENT_ID_ISSUED_AT.toString()));
        assertTrue(jsonObj.has(CLIENT_SECRET_EXPIRES_AT.toString()));
        clientId3 = jsonObj.getString(RegisterResponseParam.CLIENT_ID.toString());
        clientSecret3 = jsonObj.getString(CLIENT_SECRET.toString());
    } catch (JSONException e) {
        e.printStackTrace();
        fail(e.getMessage() + "\nResponse was: " + entity);
    }
}
Also used : Response(javax.ws.rs.core.Response) RegisterRequest(io.jans.as.client.RegisterRequest) JSONObject(org.json.JSONObject) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) JSONException(org.json.JSONException) GrantType(io.jans.as.model.common.GrantType) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(io.jans.as.server.BaseTest)

Example 42 with GrantType

use of io.jans.as.model.common.GrantType in project jans by JanssenProject.

the class UserInfoRestWebServiceEmbeddedTest method requestUserInfoHS256Step1.

@Parameters({ "registerPath", "redirectUris" })
@Test
public void requestUserInfoHS256Step1(final String registerPath, final String redirectUris) throws Exception {
    Builder request = ResteasyClientBuilder.newClient().target(url.toString() + registerPath).request();
    List<ResponseType> responseTypes = Arrays.asList(ResponseType.TOKEN);
    RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "jans test app", StringUtils.spaceSeparatedToList(redirectUris));
    registerRequest.setResponseTypes(responseTypes);
    registerRequest.setUserInfoSignedResponseAlg(SignatureAlgorithm.HS256);
    registerRequest.addCustomAttribute("jansTrustedClnt", "true");
    List<GrantType> grantTypes = Arrays.asList(GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS);
    registerRequest.setGrantTypes(grantTypes);
    String registerRequestContent = ServerUtil.toPrettyJson(registerRequest.getJSONParameters());
    Response response = request.post(Entity.json(registerRequestContent));
    String entity = response.readEntity(String.class);
    showResponse("requestUserInfoHS256Step1", response, entity);
    assertEquals(response.getStatus(), 201, "Unexpected response code. " + entity);
    assertNotNull(entity, "Unexpected result: " + entity);
    try {
        JSONObject jsonObj = new JSONObject(entity);
        assertTrue(jsonObj.has(RegisterResponseParam.CLIENT_ID.toString()));
        assertTrue(jsonObj.has(RegisterResponseParam.CLIENT_SECRET.toString()));
        assertTrue(jsonObj.has(RegisterResponseParam.REGISTRATION_ACCESS_TOKEN.toString()));
        assertTrue(jsonObj.has(RegisterResponseParam.REGISTRATION_CLIENT_URI.toString()));
        assertTrue(jsonObj.has(RegisterResponseParam.CLIENT_ID_ISSUED_AT.toString()));
        assertTrue(jsonObj.has(RegisterResponseParam.CLIENT_SECRET_EXPIRES_AT.toString()));
        clientId1 = jsonObj.getString(RegisterResponseParam.CLIENT_ID.toString());
        clientSecret1 = jsonObj.getString(RegisterResponseParam.CLIENT_SECRET.toString());
    } catch (JSONException e) {
        e.printStackTrace();
        fail(e.getMessage() + "\nResponse was: " + entity);
    }
}
Also used : Response(javax.ws.rs.core.Response) RegisterRequest(io.jans.as.client.RegisterRequest) JSONObject(org.json.JSONObject) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) JSONException(org.json.JSONException) GrantType(io.jans.as.model.common.GrantType) ResponseType(io.jans.as.model.common.ResponseType) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(io.jans.as.server.BaseTest)

Example 43 with GrantType

use of io.jans.as.model.common.GrantType in project jans by JanssenProject.

the class TokenRestWebServiceWithHSAlgEmbeddedTest method requestAccessTokenWithClientSecretJwtHS256Step1.

@Parameters({ "registerPath", "redirectUris", "clientJwksUri" })
@Test
public void requestAccessTokenWithClientSecretJwtHS256Step1(final String registerPath, final String redirectUris, final String jwksUri) throws Exception {
    Builder request = ResteasyClientBuilder.newClient().target(url.toString() + registerPath).request();
    RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "jans test app", StringUtils.spaceSeparatedToList(redirectUris));
    registerRequest.setJwksUri(jwksUri);
    registerRequest.setTokenEndpointAuthMethod(AuthenticationMethod.CLIENT_SECRET_JWT);
    registerRequest.addCustomAttribute("jansTrustedClnt", "true");
    List<GrantType> grantTypes = Arrays.asList(GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS);
    registerRequest.setGrantTypes(grantTypes);
    String registerRequestContent = ServerUtil.toPrettyJson(registerRequest.getJSONParameters());
    Response response = request.post(Entity.json(registerRequestContent));
    String entity = response.readEntity(String.class);
    showResponse("requestAccessTokenWithClientSecretJwtHS256Step1", response, entity);
    assertEquals(response.getStatus(), 201, "Unexpected response code. " + entity);
    assertNotNull(entity, "Unexpected result: " + entity);
    try {
        JSONObject jsonObj = new JSONObject(entity);
        assertTrue(jsonObj.has(RegisterResponseParam.CLIENT_ID.toString()));
        assertTrue(jsonObj.has(CLIENT_SECRET.toString()));
        assertTrue(jsonObj.has(REGISTRATION_ACCESS_TOKEN.toString()));
        assertTrue(jsonObj.has(REGISTRATION_CLIENT_URI.toString()));
        assertTrue(jsonObj.has(CLIENT_ID_ISSUED_AT.toString()));
        assertTrue(jsonObj.has(CLIENT_SECRET_EXPIRES_AT.toString()));
        clientId1 = jsonObj.getString(RegisterResponseParam.CLIENT_ID.toString());
        clientSecret1 = jsonObj.getString(CLIENT_SECRET.toString());
    } catch (JSONException e) {
        e.printStackTrace();
        fail(e.getMessage() + "\nResponse was: " + entity);
    }
}
Also used : Response(javax.ws.rs.core.Response) RegisterRequest(io.jans.as.client.RegisterRequest) JSONObject(org.json.JSONObject) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) JSONException(org.json.JSONException) GrantType(io.jans.as.model.common.GrantType) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(io.jans.as.server.BaseTest)

Example 44 with GrantType

use of io.jans.as.model.common.GrantType in project jans by JanssenProject.

the class TokenRestWebServiceWithHSAlgEmbeddedTest method requestAccessTokenWithClientSecretJwtHS512Step1.

@Parameters({ "registerPath", "redirectUris", "clientJwksUri" })
@Test
public void requestAccessTokenWithClientSecretJwtHS512Step1(final String registerPath, final String redirectUris, final String jwksUri) throws Exception {
    Builder request = ResteasyClientBuilder.newClient().target(url.toString() + registerPath).request();
    RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "jans test app", StringUtils.spaceSeparatedToList(redirectUris));
    registerRequest.setJwksUri(jwksUri);
    registerRequest.setTokenEndpointAuthMethod(AuthenticationMethod.CLIENT_SECRET_JWT);
    registerRequest.addCustomAttribute("jansTrustedClnt", "true");
    List<GrantType> grantTypes = Arrays.asList(GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS);
    registerRequest.setGrantTypes(grantTypes);
    String registerRequestContent = ServerUtil.toPrettyJson(registerRequest.getJSONParameters());
    Response response = request.post(Entity.json(registerRequestContent));
    String entity = response.readEntity(String.class);
    showResponse("requestAccessTokenWithClientSecretJwtHS512Step1", response, entity);
    assertEquals(response.getStatus(), 201, "Unexpected response code. " + entity);
    assertNotNull(entity, "Unexpected result: " + entity);
    try {
        JSONObject jsonObj = new JSONObject(entity);
        assertTrue(jsonObj.has(RegisterResponseParam.CLIENT_ID.toString()));
        assertTrue(jsonObj.has(CLIENT_SECRET.toString()));
        assertTrue(jsonObj.has(REGISTRATION_ACCESS_TOKEN.toString()));
        assertTrue(jsonObj.has(REGISTRATION_CLIENT_URI.toString()));
        assertTrue(jsonObj.has(CLIENT_ID_ISSUED_AT.toString()));
        assertTrue(jsonObj.has(CLIENT_SECRET_EXPIRES_AT.toString()));
        clientId3 = jsonObj.getString(RegisterResponseParam.CLIENT_ID.toString());
        clientSecret3 = jsonObj.getString(CLIENT_SECRET.toString());
    } catch (JSONException e) {
        e.printStackTrace();
        fail(e.getMessage() + "\nResponse was: " + entity);
    }
}
Also used : Response(javax.ws.rs.core.Response) RegisterRequest(io.jans.as.client.RegisterRequest) JSONObject(org.json.JSONObject) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) JSONException(org.json.JSONException) GrantType(io.jans.as.model.common.GrantType) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(io.jans.as.server.BaseTest)

Example 45 with GrantType

use of io.jans.as.model.common.GrantType in project jans by JanssenProject.

the class UserAuthenticationFilterEmbeddedTest method requestAccessTokenCustomAuth4Step1.

@Parameters({ "registerPath", "redirectUris", "clientJwksUri" })
@Test
public void requestAccessTokenCustomAuth4Step1(final String registerPath, final String redirectUris, final String jwksUri) throws Exception {
    Builder request = ResteasyClientBuilder.newClient().target(url.toString() + registerPath).request();
    io.jans.as.client.RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "jans test app", StringUtils.spaceSeparatedToList(redirectUris));
    registerRequest.setJwksUri(jwksUri);
    registerRequest.setTokenEndpointAuthMethod(AuthenticationMethod.CLIENT_SECRET_JWT);
    registerRequest.addCustomAttribute("jansTrustedClnt", "true");
    List<GrantType> grantTypes = Arrays.asList(GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS);
    registerRequest.setGrantTypes(grantTypes);
    String registerRequestContent = ServerUtil.toPrettyJson(registerRequest.getJSONParameters());
    Response response = request.post(Entity.json(registerRequestContent));
    String entity = response.readEntity(String.class);
    showResponse("requestAccessTokenCustomAuth4Step1", response, entity);
    assertEquals(response.getStatus(), 201, "Unexpected response code. " + entity);
    assertNotNull(entity, "Unexpected result: " + entity);
    try {
        JSONObject jsonObj = new JSONObject(entity);
        assertTrue(jsonObj.has(RegisterResponseParam.CLIENT_ID.toString()));
        assertTrue(jsonObj.has(CLIENT_SECRET.toString()));
        assertTrue(jsonObj.has(REGISTRATION_ACCESS_TOKEN.toString()));
        assertTrue(jsonObj.has(REGISTRATION_CLIENT_URI.toString()));
        assertTrue(jsonObj.has(CLIENT_ID_ISSUED_AT.toString()));
        assertTrue(jsonObj.has(CLIENT_SECRET_EXPIRES_AT.toString()));
        clientId4 = jsonObj.getString(RegisterResponseParam.CLIENT_ID.toString());
        clientSecret4 = jsonObj.getString(CLIENT_SECRET.toString());
    } catch (JSONException e) {
        e.printStackTrace();
        fail(e.getMessage() + "\nResponse was: " + entity);
    }
}
Also used : Response(javax.ws.rs.core.Response) RegisterRequest(io.jans.as.client.RegisterRequest) JSONObject(org.json.JSONObject) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) JSONException(org.json.JSONException) GrantType(io.jans.as.model.common.GrantType) RegisterRequest(io.jans.as.client.RegisterRequest) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(io.jans.as.server.BaseTest)

Aggregations

GrantType (io.jans.as.model.common.GrantType)102 Parameters (org.testng.annotations.Parameters)92 Test (org.testng.annotations.Test)89 RegisterRequest (io.jans.as.client.RegisterRequest)81 RegisterResponse (io.jans.as.client.RegisterResponse)64 BaseTest (io.jans.as.client.BaseTest)58 RegisterClient (io.jans.as.client.RegisterClient)55 TokenClient (io.jans.as.client.TokenClient)53 TokenResponse (io.jans.as.client.TokenResponse)53 TokenRequest (io.jans.as.client.TokenRequest)46 AuthCryptoProvider (io.jans.as.model.crypto.AuthCryptoProvider)43 ResponseType (io.jans.as.model.common.ResponseType)32 JSONObject (org.json.JSONObject)29 Response (javax.ws.rs.core.Response)26 JSONException (org.json.JSONException)26 BaseTest (io.jans.as.server.BaseTest)25 Builder (javax.ws.rs.client.Invocation.Builder)25 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)25 ClientInfoClient (io.jans.as.client.ClientInfoClient)16 ClientInfoResponse (io.jans.as.client.ClientInfoResponse)16