Search in sources :

Example 6 with Token

use of org.gluu.oxauth.model.uma.wrapper.Token in project oxAuth by GluuFederation.

the class IntrospectionWsHttpTest method introspectWithValidAuthorizationButInvalidTokenShouldReturnActiveFalse.

@Test
@Parameters({ "umaPatClientId", "umaPatClientSecret" })
public void introspectWithValidAuthorizationButInvalidTokenShouldReturnActiveFalse(final String umaPatClientId, final String umaPatClientSecret) throws Exception {
    final Token authorization = UmaClient.requestPat(tokenEndpoint, umaPatClientId, umaPatClientSecret, clientEngine(true));
    final IntrospectionService introspectionService = ClientFactory.instance().createIntrospectionService(introspectionEndpoint, clientEngine(true));
    final IntrospectionResponse introspectionResponse = introspectionService.introspectToken("Bearer " + authorization.getAccessToken(), "invalid_token");
    assertNotNull(introspectionResponse);
    assertFalse(introspectionResponse.isActive());
}
Also used : IntrospectionResponse(org.gluu.oxauth.model.common.IntrospectionResponse) IntrospectionService(org.gluu.oxauth.client.service.IntrospectionService) Token(org.gluu.oxauth.model.uma.wrapper.Token) Parameters(org.testng.annotations.Parameters) BaseTest(org.gluu.oxauth.BaseTest) Test(org.testng.annotations.Test)

Example 7 with Token

use of org.gluu.oxauth.model.uma.wrapper.Token in project oxAuth by GluuFederation.

the class StatWSTest method statPost.

@Test(enabled = false)
@Parameters({ "umaPatClientId", "umaPatClientSecret" })
public void statPost(final String umaPatClientId, final String umaPatClientSecret) throws Exception {
    final Token authorization = UmaClient.requestPat(tokenEndpoint, umaPatClientId, umaPatClientSecret);
    final StatService service = ClientFactory.instance().createStatService(issuer + "/oxauth/restv1/internal/stat");
    final JsonNode node = service.statPost(authorization.getAccessToken(), "202101", null);
    assertTrue(node != null && node.hasNonNull("response"));
}
Also used : Token(org.gluu.oxauth.model.uma.wrapper.Token) JsonNode(com.fasterxml.jackson.databind.JsonNode) StatService(org.gluu.oxauth.client.service.StatService) Parameters(org.testng.annotations.Parameters) BaseTest(org.gluu.oxauth.BaseTest) Test(org.testng.annotations.Test)

Example 8 with Token

use of org.gluu.oxauth.model.uma.wrapper.Token in project oxAuth by GluuFederation.

the class StatWSTest method stat.

@Test(enabled = false)
@Parameters({ "umaPatClientId", "umaPatClientSecret" })
public void stat(final String umaPatClientId, final String umaPatClientSecret) throws Exception {
    final Token authorization = UmaClient.requestPat(tokenEndpoint, umaPatClientId, umaPatClientSecret);
    final StatService service = ClientFactory.instance().createStatService(issuer + "/oxauth/restv1/internal/stat");
    final JsonNode node = service.stat("Bearer " + authorization.getAccessToken(), "202101", null);
    assertTrue(node != null && node.hasNonNull("response"));
}
Also used : Token(org.gluu.oxauth.model.uma.wrapper.Token) JsonNode(com.fasterxml.jackson.databind.JsonNode) StatService(org.gluu.oxauth.client.service.StatService) Parameters(org.testng.annotations.Parameters) BaseTest(org.gluu.oxauth.BaseTest) Test(org.testng.annotations.Test)

Example 9 with Token

use of org.gluu.oxauth.model.uma.wrapper.Token in project oxAuth by GluuFederation.

the class TTokenRequest method newTokenByRefreshToken.

public Token newTokenByRefreshToken(final String tokenPath, final Token p_oldToken, final String umaClientId, final String umaClientSecret) {
    if (p_oldToken == null || StringUtils.isBlank(p_oldToken.getRefreshToken()) || StringUtils.isBlank(tokenPath)) {
        throw new IllegalArgumentException("Refresh token or tokenPath is empty.");
    }
    final Holder<Token> t = new Holder<Token>();
    try {
        TokenRequest tokenRequest = new TokenRequest(GrantType.REFRESH_TOKEN);
        tokenRequest.setAuthUsername(umaClientId);
        tokenRequest.setAuthPassword(umaClientSecret);
        tokenRequest.setRefreshToken(p_oldToken.getRefreshToken());
        tokenRequest.setScope(p_oldToken.getScope());
        Builder request = ResteasyClientBuilder.newClient().target(baseUri.toString() + tokenPath).request();
        request.header("Authorization", "Basic " + tokenRequest.getEncodedCredentials());
        Response response = request.post(Entity.form(new MultivaluedHashMap<String, String>(tokenRequest.getParameters())));
        String entity = response.readEntity(String.class);
        BaseTest.showResponse("TTokenClient.requestToken() :", response, entity);
        assertEquals(response.getStatus(), 200, "Unexpected response code.");
        try {
            JSONObject jsonObj = new JSONObject(entity);
            assertTrue(jsonObj.has("access_token"), "Unexpected result: access_token not found");
            assertTrue(jsonObj.has("token_type"), "Unexpected result: token_type not found");
            assertTrue(jsonObj.has("refresh_token"), "Unexpected result: refresh_token not found");
            // assertTrue(jsonObj.has("id_token"), "Unexpected result:
            // id_token not found");
            String accessToken = jsonObj.getString("access_token");
            String refreshToken = jsonObj.getString("refresh_token");
            // String idToken = jsonObj.getString("id_token");
            final Token newToken = new Token();
            newToken.setAccessToken(accessToken);
            newToken.setRefreshToken(refreshToken);
            t.setT(newToken);
        } catch (JSONException e) {
            e.printStackTrace();
            fail(e.getMessage() + "\nResponse was: " + entity);
        } catch (Exception e) {
            e.printStackTrace();
            fail(e.getMessage());
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
    return t.getT();
}
Also used : RPTResponse(org.gluu.oxauth.model.uma.RPTResponse) RptIntrospectionResponse(org.gluu.oxauth.model.uma.RptIntrospectionResponse) Response(javax.ws.rs.core.Response) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) JSONObject(org.json.JSONObject) Holder(org.gluu.oxauth.model.common.Holder) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) TokenRequest(org.gluu.oxauth.client.TokenRequest) JSONException(org.json.JSONException) Token(org.gluu.oxauth.model.uma.wrapper.Token) JSONException(org.json.JSONException) IOException(java.io.IOException)

Example 10 with Token

use of org.gluu.oxauth.model.uma.wrapper.Token in project oxAuth by GluuFederation.

the class ObtainPatWSTest method requestNewPatByRefreshTokne.

@Test(dependsOnMethods = "requestPat")
@Parameters({ "tokenPath", "umaPatClientId", "umaPatClientSecret" })
public void requestNewPatByRefreshTokne(String tokenPath, String umaPatClientId, String umaPatClientSecret) {
    final Token newPat = TUma.newTokenByRefreshToken(url, tokenPath, pat, umaPatClientId, umaPatClientSecret);
    UmaTestUtil.assert_(newPat);
}
Also used : Token(org.gluu.oxauth.model.uma.wrapper.Token) Parameters(org.testng.annotations.Parameters) BaseTest(org.gluu.oxauth.BaseTest) Test(org.testng.annotations.Test)

Aggregations

Token (org.gluu.oxauth.model.uma.wrapper.Token)12 BaseTest (org.gluu.oxauth.BaseTest)7 Parameters (org.testng.annotations.Parameters)7 Test (org.testng.annotations.Test)7 IntrospectionService (org.gluu.oxauth.client.service.IntrospectionService)4 IntrospectionResponse (org.gluu.oxauth.model.common.IntrospectionResponse)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 Response (javax.ws.rs.core.Response)2 TokenClient (org.gluu.oxauth.client.TokenClient)2 TokenRequest (org.gluu.oxauth.client.TokenRequest)2 TokenResponse (org.gluu.oxauth.client.TokenResponse)2 StatService (org.gluu.oxauth.client.service.StatService)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Builder (javax.ws.rs.client.Invocation.Builder)1 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)1 AuthorizationRequest (org.gluu.oxauth.client.AuthorizationRequest)1 AuthorizationResponse (org.gluu.oxauth.client.AuthorizationResponse)1 AuthorizeClient (org.gluu.oxauth.client.AuthorizeClient)1 UmaException (org.gluu.oxauth.client.uma.exception.UmaException)1