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());
}
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);
}
}
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);
}
}
Aggregations