Search in sources :

Example 1 with ClientInterface

use of io.jans.ca.client.ClientInterface in project jans by JanssenProject.

the class CheckAccessTokenTest method test.

@Parameters({ "host", "redirectUrls", "userId", "userSecret", "opHost" })
@Test
public void test(String host, String redirectUrls, String userId, String userSecret, String opHost) {
    ClientInterface client = Tester.newClient(host);
    String nonce = CoreUtils.secureRandomString();
    String state = CoreUtils.secureRandomString();
    RegisterSiteResponse site = RegisterSiteTest.registerSite(client, opHost, redirectUrls);
    GetTokensByCodeResponse2 response = GetTokensByCodeTest.tokenByCode(client, site, opHost, userId, userSecret, site.getClientId(), redirectUrls, nonce, state);
    final CheckAccessTokenParams params = new CheckAccessTokenParams();
    params.setAccessToken(response.getAccessToken());
    params.setIdToken(response.getIdToken());
    params.setRpId(site.getRpId());
    final CheckAccessTokenResponse checkR = client.checkAccessToken(Tester.getAuthorization(site), null, params);
    assertNotNull(checkR);
    assertTrue(checkR.isActive());
    assertNotNull(checkR.getExpiresAt());
    assertNotNull(checkR.getIssuedAt());
}
Also used : CheckAccessTokenResponse(io.jans.ca.common.response.CheckAccessTokenResponse) CheckAccessTokenParams(io.jans.ca.common.params.CheckAccessTokenParams) ClientInterface(io.jans.ca.client.ClientInterface) RegisterSiteResponse(io.jans.ca.common.response.RegisterSiteResponse) GetTokensByCodeResponse2(io.jans.ca.client.GetTokensByCodeResponse2) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Example 2 with ClientInterface

use of io.jans.ca.client.ClientInterface in project jans by JanssenProject.

the class DifferentAuthServerTest method getUserInfo_withDifferentAuthServer.

@Parameters({ "host", "opHost", "authServer", "redirectUrls", "clientId", "clientSecret", "userId", "userSecret" })
@Test
public void getUserInfo_withDifferentAuthServer(String host, String opHost, String authServer, String redirectUrls, String clientId, String clientSecret, String userId, String userSecret) {
    ClientInterface client = Tester.newClient(host);
    RegisterSiteResponse site = RegisterSiteTest.registerSite(client, opHost, redirectUrls);
    RegisterSiteResponse authServerResp = RegisterSiteTest.registerSite(client, authServer, redirectUrls);
    final GetTokensByCodeResponse2 tokens = requestTokens(client, opHost, site, authServerResp, userId, userSecret, site.getClientId(), redirectUrls);
    GetUserInfoParams params = new GetUserInfoParams();
    params.setRpId(site.getRpId());
    params.setAccessToken(tokens.getAccessToken());
    params.setIdToken(tokens.getIdToken());
    final JsonNode resp = client.getUserInfo(Tester.getAuthorization(authServerResp), authServerResp.getRpId(), params);
    assertNotNull(resp);
    assertNotNull(resp.get("sub"));
}
Also used : GetUserInfoParams(io.jans.ca.common.params.GetUserInfoParams) JsonNode(com.fasterxml.jackson.databind.JsonNode) ClientInterface(io.jans.ca.client.ClientInterface) RegisterSiteResponse(io.jans.ca.common.response.RegisterSiteResponse) GetTokensByCodeResponse2(io.jans.ca.client.GetTokensByCodeResponse2) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Example 3 with ClientInterface

use of io.jans.ca.client.ClientInterface in project jans by JanssenProject.

the class GetIssuerTest method hostnameInputTest.

@Parameters({ "host", "opHost", "hostnameWebfingerInput" })
@Test
public void hostnameInputTest(String host, String opHost, String hostnameWebfingerInput) {
    ClientInterface client = Tester.newClient(host);
    final GetIssuerParams params = new GetIssuerParams();
    params.setResource(hostnameWebfingerInput);
    params.setOpHost(opHost);
    final GetIssuerResponse resp = client.getIssuer(params);
    assertNotNull(resp);
    assertEquals(resp.getSubject(), hostnameWebfingerInput);
    resp.getLinks().forEach((link) -> {
        assertEquals(link.getHref(), opHost);
    });
}
Also used : GetIssuerResponse(io.jans.ca.common.response.GetIssuerResponse) GetIssuerParams(io.jans.ca.common.params.GetIssuerParams) ClientInterface(io.jans.ca.client.ClientInterface) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Example 4 with ClientInterface

use of io.jans.ca.client.ClientInterface in project jans by JanssenProject.

the class GetIssuerTest method emailInputTest.

@Parameters({ "host", "opHost", "emailWebfingerInput" })
@Test(enabled = false)
public void emailInputTest(String host, String opHost, String emailWebfingerInput) {
    ClientInterface client = Tester.newClient(host);
    final GetIssuerParams params = new GetIssuerParams();
    params.setResource(emailWebfingerInput);
    params.setOpHost(opHost);
    final GetIssuerResponse resp = client.getIssuer(params);
    assertNotNull(resp);
    assertEquals(resp.getSubject(), emailWebfingerInput);
    resp.getLinks().forEach((link) -> {
        assertEquals(link.getHref(), opHost);
    });
}
Also used : GetIssuerResponse(io.jans.ca.common.response.GetIssuerResponse) GetIssuerParams(io.jans.ca.common.params.GetIssuerParams) ClientInterface(io.jans.ca.client.ClientInterface) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Example 5 with ClientInterface

use of io.jans.ca.client.ClientInterface in project jans by JanssenProject.

the class IntrospectAccessTokenTest method introspectAccessToken.

@Parameters({ "host", "opHost", "redirectUrls" })
@Test
public void introspectAccessToken(String host, String opHost, String redirectUrls) {
    ClientInterface client = Tester.newClient(host);
    RegisterSiteResponse setupResponse = SetupClientTest.setupClient(client, opHost, redirectUrls);
    final GetClientTokenParams params = new GetClientTokenParams();
    params.setOpHost(opHost);
    params.setScope(Lists.newArrayList("openid", "jans_client_api"));
    params.setClientId(setupResponse.getClientId());
    params.setClientSecret(setupResponse.getClientSecret());
    GetClientTokenResponse tokenResponse = client.getClientToken(params);
    assertNotNull(tokenResponse);
    notEmpty(tokenResponse.getAccessToken());
    IntrospectAccessTokenParams introspectParams = new IntrospectAccessTokenParams();
    introspectParams.setRpId(setupResponse.getRpId());
    introspectParams.setAccessToken(tokenResponse.getAccessToken());
    IntrospectAccessTokenResponse introspectionResponse = client.introspectAccessToken("Bearer " + tokenResponse.getAccessToken(), null, introspectParams);
    assertNotNull(introspectionResponse);
    assertTrue(introspectionResponse.isActive());
    assertNotNull(introspectionResponse.getIssuedAt());
    assertNotNull(introspectionResponse.getExpiresAt());
    assertTrue(introspectionResponse.getExpiresAt() >= introspectionResponse.getIssuedAt());
}
Also used : IntrospectAccessTokenParams(io.jans.ca.common.params.IntrospectAccessTokenParams) IntrospectAccessTokenResponse(io.jans.ca.common.response.IntrospectAccessTokenResponse) ClientInterface(io.jans.ca.client.ClientInterface) RegisterSiteResponse(io.jans.ca.common.response.RegisterSiteResponse) GetClientTokenResponse(io.jans.ca.common.response.GetClientTokenResponse) GetClientTokenParams(io.jans.ca.common.params.GetClientTokenParams) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Aggregations

ClientInterface (io.jans.ca.client.ClientInterface)67 Parameters (org.testng.annotations.Parameters)64 Test (org.testng.annotations.Test)64 RegisterSiteResponse (io.jans.ca.common.response.RegisterSiteResponse)58 GetTokensByCodeResponse2 (io.jans.ca.client.GetTokensByCodeResponse2)21 GetAuthorizationUrlParams (io.jans.ca.common.params.GetAuthorizationUrlParams)8 GetAuthorizationUrlResponse (io.jans.ca.common.response.GetAuthorizationUrlResponse)8 RpGetRptResponse (io.jans.ca.common.response.RpGetRptResponse)7 RsCheckAccessResponse (io.jans.ca.common.response.RsCheckAccessResponse)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 RpGetRptParams (io.jans.ca.common.params.RpGetRptParams)4 RsProtectParams2 (io.jans.ca.client.RsProtectParams2)3 GetIssuerParams (io.jans.ca.common.params.GetIssuerParams)3 RpGetClaimsGatheringUrlParams (io.jans.ca.common.params.RpGetClaimsGatheringUrlParams)3 GetIssuerResponse (io.jans.ca.common.response.GetIssuerResponse)3 RpGetClaimsGatheringUrlResponse (io.jans.ca.common.response.RpGetClaimsGatheringUrlResponse)3 BadRequestException (javax.ws.rs.BadRequestException)3 CorrectRptIntrospectionResponse (io.jans.ca.common.introspection.CorrectRptIntrospectionResponse)2 GetDiscoveryParams (io.jans.ca.common.params.GetDiscoveryParams)2 GetJwksParams (io.jans.ca.common.params.GetJwksParams)2