Search in sources :

Example 11 with KeyManagerClientException

use of org.wso2.carbon.apimgt.impl.kmclient.KeyManagerClientException in project carbon-apimgt by wso2.

the class AMDefaultKeyManagerImplTest method testTokenUnlimitedExpirationTime.

@Test
public void testTokenUnlimitedExpirationTime() throws KeyManagerClientException, APIManagementException {
    String accessToken = "155ddde3-68db-35b1-82dc-1247616b2da9";
    IntrospectInfo response = new IntrospectInfo();
    response.setActive(true);
    response.setExpiry(Long.MAX_VALUE);
    response.setIat(new Date().getTime());
    Mockito.when(introspectionClient.introspect(accessToken)).thenReturn(response);
    AccessTokenInfo info = keyManager.getTokenMetaData(accessToken);
    Assert.assertEquals(Long.MAX_VALUE, info.getValidityPeriod());
}
Also used : AccessTokenInfo(org.wso2.carbon.apimgt.api.model.AccessTokenInfo) IntrospectInfo(org.wso2.carbon.apimgt.impl.kmclient.model.IntrospectInfo) Date(java.util.Date) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 12 with KeyManagerClientException

use of org.wso2.carbon.apimgt.impl.kmclient.KeyManagerClientException in project carbon-apimgt by wso2.

the class AMDefaultKeyManagerImpl method registerScope.

/**
 * This method will be used to register a Scope in the authorization server.
 *
 * @param scope Scope to register
 * @throws APIManagementException if there is an error while registering a new scope.
 */
@Override
public void registerScope(Scope scope) throws APIManagementException {
    String scopeKey = scope.getKey();
    ScopeDTO scopeDTO = new ScopeDTO();
    scopeDTO.setName(scopeKey);
    scopeDTO.setDisplayName(scope.getName());
    scopeDTO.setDescription(scope.getDescription());
    if (StringUtils.isNotBlank(scope.getRoles()) && scope.getRoles().trim().split(",").length > 0) {
        scopeDTO.setBindings(Arrays.asList(scope.getRoles().trim().split(",")));
    }
    try (Response response = scopeClient.registerScope(scopeDTO)) {
        if (response.status() != HttpStatus.SC_CREATED) {
            String responseString = readHttpResponseAsString(response.body());
            throw new APIManagementException("Error occurred while registering scope: " + scopeKey + ". Error" + " Status: " + response.status() + " . Error Response: " + responseString);
        }
    } catch (KeyManagerClientException e) {
        handleException("Cannot register scope : " + scopeKey, e);
    }
}
Also used : Response(feign.Response) KeyManagerClientException(org.wso2.carbon.apimgt.impl.kmclient.KeyManagerClientException) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ScopeDTO(org.wso2.carbon.apimgt.impl.dto.ScopeDTO)

Example 13 with KeyManagerClientException

use of org.wso2.carbon.apimgt.impl.kmclient.KeyManagerClientException in project carbon-apimgt by wso2.

the class AMDefaultKeyManagerImpl method deleteScope.

/**
 * This method will be used to delete a Scope in the authorization server.
 *
 * @param scopeName Scope name
 * @throws APIManagementException if an error occurs while deleting the scope
 */
@Override
public void deleteScope(String scopeName) throws APIManagementException {
    try {
        Response response = scopeClient.deleteScope(scopeName);
        if (response.status() != HttpStatus.SC_OK) {
            String responseString = readHttpResponseAsString(response.body());
            String errorMessage = "Error occurred while deleting scope: " + scopeName + ". Error Status: " + response.status() + " . Error Response: " + responseString;
            throw new APIManagementException(errorMessage);
        }
    } catch (KeyManagerClientException ex) {
        handleException("Error occurred while deleting scope", ex);
    }
}
Also used : Response(feign.Response) KeyManagerClientException(org.wso2.carbon.apimgt.impl.kmclient.KeyManagerClientException) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException)

Aggregations

KeyManagerClientException (org.wso2.carbon.apimgt.impl.kmclient.KeyManagerClientException)10 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)7 OAuthApplicationInfo (org.wso2.carbon.apimgt.api.model.OAuthApplicationInfo)6 ClientInfo (org.wso2.carbon.apimgt.impl.kmclient.model.ClientInfo)6 Test (org.junit.Test)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 AccessTokenInfo (org.wso2.carbon.apimgt.api.model.AccessTokenInfo)3 Response (feign.Response)2 OAuthAppRequest (org.wso2.carbon.apimgt.api.model.OAuthAppRequest)2 ScopeDTO (org.wso2.carbon.apimgt.impl.dto.ScopeDTO)2 IntrospectInfo (org.wso2.carbon.apimgt.impl.kmclient.model.IntrospectInfo)2 PrivilegedCarbonContext (org.wso2.carbon.context.PrivilegedCarbonContext)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 UserInfoDTO (org.wso2.carbon.apimgt.impl.dto.UserInfoDTO)1 Claim (org.wso2.carbon.apimgt.impl.kmclient.model.Claim)1 ClaimsList (org.wso2.carbon.apimgt.impl.kmclient.model.ClaimsList)1 TokenInfo (org.wso2.carbon.apimgt.impl.kmclient.model.TokenInfo)1