Search in sources :

Example 1 with Token

use of io.jans.as.model.uma.wrapper.Token in project jans by JanssenProject.

the class UmaClient method request.

@SuppressWarnings("java:S1874")
public static Token request(final String tokenUrl, final String umaClientId, final String umaClientSecret, UmaScopeType scopeType, ClientHttpEngine engine, String... scopeArray) {
    StringBuilder scope = new StringBuilder(scopeType.getValue());
    if (scopeArray != null && scopeArray.length > 0) {
        for (String s : scopeArray) {
            scope.append(" ").append(s);
        }
    }
    TokenClient tokenClient = new TokenClient(tokenUrl);
    if (engine != null) {
        tokenClient.setExecutor(engine);
    }
    TokenResponse response = tokenClient.execClientCredentialsGrant(scope.toString(), 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(io.jans.as.client.TokenResponse) Token(io.jans.as.model.uma.wrapper.Token) TokenClient(io.jans.as.client.TokenClient)

Example 2 with Token

use of io.jans.as.model.uma.wrapper.Token in project jans by JanssenProject.

the class UmaClient method request.

public static Token request(final String tokenUrl, final TokenRequest tokenRequest) {
    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(io.jans.as.client.TokenResponse) Token(io.jans.as.model.uma.wrapper.Token) TokenClient(io.jans.as.client.TokenClient)

Example 3 with Token

use of io.jans.as.model.uma.wrapper.Token in project jans by JanssenProject.

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(io.jans.as.model.common.IntrospectionResponse) IntrospectionService(io.jans.as.client.service.IntrospectionService) Token(io.jans.as.model.uma.wrapper.Token) Parameters(org.testng.annotations.Parameters) BaseTest(io.jans.as.client.BaseTest) Test(org.testng.annotations.Test)

Example 4 with Token

use of io.jans.as.model.uma.wrapper.Token in project jans by JanssenProject.

the class AuthUtil method requestAccessToken.

public Token requestAccessToken(final String tokenUrl, final String clientId, final List<String> scopes) {
    log.debug("Access Token Request - tokenUrl:{}, clientId:{}, scopes:{}", tokenUrl, clientId, scopes);
    // Get clientSecret
    String clientSecret = this.getClientDecryptPassword(clientId);
    // distinct scopes
    Set<String> scopesSet = new HashSet<>(scopes);
    StringBuilder scope = new StringBuilder(ScopeType.OPENID.getValue());
    for (String s : scopesSet) {
        scope.append(" ").append(s);
    }
    log.debug("Scope required  - {}", scope);
    TokenResponse tokenResponse = AuthClientFactory.requestAccessToken(tokenUrl, clientId, clientSecret, scope.toString());
    if (tokenResponse != null) {
        log.debug("Token Response - tokenScope: {}, tokenAccessToken: {} ", tokenResponse.getScope(), tokenResponse.getAccessToken());
        final String accessToken = tokenResponse.getAccessToken();
        final Integer expiresIn = tokenResponse.getExpiresIn();
        if (Util.allNotBlank(accessToken)) {
            return new Token(null, null, accessToken, ScopeType.OPENID.getValue(), expiresIn);
        }
    }
    return null;
}
Also used : TokenResponse(io.jans.as.client.TokenResponse) Token(io.jans.as.model.uma.wrapper.Token) HashSet(java.util.HashSet)

Example 5 with Token

use of io.jans.as.model.uma.wrapper.Token in project jans by JanssenProject.

the class ObtainPatProvider method requestPat.

public Token requestPat(final String tokenUrl, final String umaClientId, final String umaClientSecret, String... scopeArray) throws Exception {
    String scope = UmaScopeType.PROTECTION.getValue();
    if (scopeArray != null && scopeArray.length > 0) {
        for (String s : scopeArray) {
            scope = scope + " " + s;
        }
    }
    TokenClient tokenClient = new TokenClient(tokenUrl);
    tokenClient.setExecutor(serviceProvider.getClientEngine());
    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, UmaScopeType.PROTECTION.getValue(), expiresIn);
        }
    }
    return null;
}
Also used : TokenResponse(io.jans.as.client.TokenResponse) Token(io.jans.as.model.uma.wrapper.Token) TokenClient(io.jans.as.client.TokenClient)

Aggregations

Token (io.jans.as.model.uma.wrapper.Token)14 Parameters (org.testng.annotations.Parameters)7 Test (org.testng.annotations.Test)7 BaseTest (io.jans.as.client.BaseTest)6 TokenResponse (io.jans.as.client.TokenResponse)5 TokenClient (io.jans.as.client.TokenClient)4 IntrospectionService (io.jans.as.client.service.IntrospectionService)4 IntrospectionResponse (io.jans.as.model.common.IntrospectionResponse)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 TokenRequest (io.jans.as.client.TokenRequest)2 StatService (io.jans.as.client.service.StatService)2 AuthorizationRequest (io.jans.as.client.AuthorizationRequest)1 AuthorizationResponse (io.jans.as.client.AuthorizationResponse)1 AuthorizeClient (io.jans.as.client.AuthorizeClient)1 Holder (io.jans.as.model.common.Holder)1 ResponseType (io.jans.as.model.common.ResponseType)1 Jwt (io.jans.as.model.jwt.Jwt)1 RPTResponse (io.jans.as.model.uma.RPTResponse)1 RptIntrospectionResponse (io.jans.as.model.uma.RptIntrospectionResponse)1 BaseTest (io.jans.as.server.BaseTest)1