Search in sources :

Example 1 with Token

use of org.xdi.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.xdi.oxauth.model.uma.wrapper.Token) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Example 2 with Token

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

the class UmaClient method request.

public static Token request(final String tokenUrl, final TokenRequest tokenRequest) throws Exception {
    if (tokenRequest.getGrantType() != GrantType.CLIENT_CREDENTIALS) {
        return null;
    }
    TokenClient tokenClient = new TokenClient(tokenUrl);
    tokenClient.setRequest(tokenRequest);
    TokenResponse response = tokenClient.exec();
    if (response.getStatus() == 200) {
        final String patToken = response.getAccessToken();
        final Integer expiresIn = response.getExpiresIn();
        if (Util.allNotBlank(patToken)) {
            return new Token(null, null, patToken, response.getScope(), expiresIn);
        }
    }
    return null;
}
Also used : TokenResponse(org.xdi.oxauth.client.TokenResponse) Token(org.xdi.oxauth.model.uma.wrapper.Token) TokenClient(org.xdi.oxauth.client.TokenClient)

Example 3 with Token

use of org.xdi.oxauth.model.uma.wrapper.Token in project oxTrust by GluuFederation.

the class PassportRestWebService method processAuthorization.

protected Response processAuthorization(String authorization) {
    if (!pasportUmaProtectionService.isEnabled()) {
        log.info("UMA authentication is disabled");
        return getErrorResponse(Response.Status.FORBIDDEN, "Passport configuration was disabled");
    }
    Token patToken;
    try {
        patToken = pasportUmaProtectionService.getPatToken();
    } catch (UmaProtectionException ex) {
        return getErrorResponse(Response.Status.FORBIDDEN, "Failed to obtain PAT token");
    }
    Pair<Boolean, Response> rptTokenValidationResult = umaPermissionService.validateRptToken(patToken, authorization, pasportUmaProtectionService.getUmaResourceId(), pasportUmaProtectionService.getUmaScope());
    if (rptTokenValidationResult.getFirst()) {
        if (rptTokenValidationResult.getSecond() != null) {
            return rptTokenValidationResult.getSecond();
        }
    } else {
        return getErrorResponse(Response.Status.FORBIDDEN, "Invalid GAT/RPT token");
    }
    return null;
}
Also used : PassportConfigResponse(org.gluu.oxtrust.model.passport.PassportConfigResponse) Response(javax.ws.rs.core.Response) UmaProtectionException(org.gluu.oxtrust.exception.UmaProtectionException) Token(org.xdi.oxauth.model.uma.wrapper.Token)

Example 4 with Token

use of org.xdi.oxauth.model.uma.wrapper.Token in project oxTrust by GluuFederation.

the class BaseScimWebService method processAuthorization.

protected Response processAuthorization(String authorization) throws Exception {
    boolean authorized = getAuthorizedUser();
    if (!authorized) {
        if (!scimUmaProtectionService.isEnabled()) {
            return getErrorResponse("User isn't authorized", Response.Status.FORBIDDEN.getStatusCode());
        }
        Token patToken = scimUmaProtectionService.getPatToken();
        Pair<Boolean, Response> rptTokenValidationResult = umaPermissionService.validateRptToken(patToken, authorization, scimUmaProtectionService.getUmaResourceId(), scimUmaProtectionService.getUmaScope());
        if (rptTokenValidationResult.getFirst()) {
            if (rptTokenValidationResult.getSecond() != null) {
                return rptTokenValidationResult.getSecond();
            }
        } else {
            return getErrorResponse("User isn't authorized", Response.Status.FORBIDDEN.getStatusCode());
        }
    }
    return null;
}
Also used : VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) Response(javax.ws.rs.core.Response) Token(org.xdi.oxauth.model.uma.wrapper.Token) GluuBoolean(org.xdi.ldap.model.GluuBoolean)

Example 5 with Token

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

the class UmaClient method request.

public static Token request(final String tokenUrl, final String umaClientId, final String umaClientSecret, UmaScopeType scopeType, String... scopeArray) throws Exception {
    String scope = scopeType.getValue();
    if (scopeArray != null && scopeArray.length > 0) {
        for (String s : scopeArray) {
            scope = scope + " " + s;
        }
    }
    TokenClient tokenClient = new TokenClient(tokenUrl);
    TokenResponse response = tokenClient.execClientCredentialsGrant(scope, umaClientId, umaClientSecret);
    if (response.getStatus() == 200) {
        final String patToken = response.getAccessToken();
        final Integer expiresIn = response.getExpiresIn();
        if (Util.allNotBlank(patToken)) {
            return new Token(null, null, patToken, scopeType.getValue(), expiresIn);
        }
    }
    return null;
}
Also used : TokenResponse(org.xdi.oxauth.client.TokenResponse) Token(org.xdi.oxauth.model.uma.wrapper.Token) TokenClient(org.xdi.oxauth.client.TokenClient)

Aggregations

Token (org.xdi.oxauth.model.uma.wrapper.Token)10 Response (javax.ws.rs.core.Response)5 Parameters (org.testng.annotations.Parameters)3 Test (org.testng.annotations.Test)3 BaseTest (org.xdi.oxauth.BaseTest)3 UmaProtectionException (org.gluu.oxtrust.exception.UmaProtectionException)2 GluuBoolean (org.xdi.ldap.model.GluuBoolean)2 VirtualListViewResponse (org.xdi.ldap.model.VirtualListViewResponse)2 TokenClient (org.xdi.oxauth.client.TokenClient)2 TokenResponse (org.xdi.oxauth.client.TokenResponse)2 IOException (java.io.IOException)1 Builder (javax.ws.rs.client.Invocation.Builder)1 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)1 JSONException (org.codehaus.jettison.json.JSONException)1 JSONObject (org.codehaus.jettison.json.JSONObject)1 PassportConfigResponse (org.gluu.oxtrust.model.passport.PassportConfigResponse)1 ErrorResponse (org.gluu.oxtrust.model.scim2.ErrorResponse)1 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)1 TokenRequest (org.xdi.oxauth.client.TokenRequest)1 IntrospectionService (org.xdi.oxauth.client.service.IntrospectionService)1