use of org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO in project carbon-apimgt by wso2.
the class KeyManagerMappingUtil method toKeyManagerListDto.
public static KeyManagerListDTO toKeyManagerListDto(List<KeyManagerConfigurationDTO> keyManagerConfigurations) {
KeyManagerListDTO keyManagerListDTO = new KeyManagerListDTO();
List<KeyManagerInfoDTO> keyManagerInfoDTOList = new ArrayList<>();
for (KeyManagerConfigurationDTO keyManagerConfigurationDTO : keyManagerConfigurations) {
keyManagerInfoDTOList.add(fromKeyManagerConfigurationDtoToKeyManagerInfoDto(keyManagerConfigurationDTO));
}
keyManagerListDTO.setList(keyManagerInfoDTOList);
keyManagerListDTO.setCount(keyManagerInfoDTOList.size());
return keyManagerListDTO;
}
use of org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO in project carbon-apimgt by wso2.
the class KeyManagerMappingUtil method fromKeyManagerConfigurationDtoToKeyManagerInfoDto.
public static KeyManagerInfoDTO fromKeyManagerConfigurationDtoToKeyManagerInfoDto(KeyManagerConfigurationDTO keyManagerConfigurationDTO) {
KeyManagerInfoDTO keyManagerInfoDTO = new KeyManagerInfoDTO();
keyManagerInfoDTO.setId(keyManagerConfigurationDTO.getUuid());
keyManagerInfoDTO.setName(keyManagerConfigurationDTO.getName());
keyManagerInfoDTO.setDescription(keyManagerConfigurationDTO.getDescription());
keyManagerInfoDTO.setDisplayName(keyManagerConfigurationDTO.getDisplayName());
keyManagerInfoDTO.setEnabled(keyManagerConfigurationDTO.isEnabled());
keyManagerInfoDTO.setType(keyManagerConfigurationDTO.getType());
keyManagerInfoDTO.setAlias(keyManagerConfigurationDTO.getAlias());
keyManagerInfoDTO.setTokenType(KeyManagerInfoDTO.TokenTypeEnum.valueOf(keyManagerConfigurationDTO.getTokenType()));
JsonObject jsonObject = fromConfigurationMapToJson(keyManagerConfigurationDTO.getAdditionalProperties());
JsonElement grantTypesElement = jsonObject.get(APIConstants.KeyManager.AVAILABLE_GRANT_TYPE);
if (grantTypesElement instanceof JsonArray) {
keyManagerInfoDTO.setAvailableGrantTypes(new Gson().fromJson(grantTypesElement, List.class));
}
if (jsonObject.has(APIConstants.KeyManager.ENABLE_OAUTH_APP_CREATION)) {
keyManagerInfoDTO.setEnableOAuthAppCreation(jsonObject.get(APIConstants.KeyManager.ENABLE_OAUTH_APP_CREATION).getAsBoolean());
}
if (jsonObject.has(APIConstants.KeyManager.ENABLE_TOKEN_GENERATION)) {
keyManagerInfoDTO.setEnableTokenGeneration(jsonObject.get(APIConstants.KeyManager.ENABLE_TOKEN_GENERATION).getAsBoolean());
}
if (jsonObject.has(APIConstants.KeyManager.ENABLE_MAP_OAUTH_CONSUMER_APPS)) {
keyManagerInfoDTO.setEnableMapOAuthConsumerApps(jsonObject.get(APIConstants.KeyManager.ENABLE_MAP_OAUTH_CONSUMER_APPS).getAsBoolean());
}
if (jsonObject.has(APIConstants.KeyManager.ENABLE_TOKEN_ENCRYPTION)) {
keyManagerInfoDTO.setEnableTokenEncryption(jsonObject.get(APIConstants.KeyManager.ENABLE_TOKEN_ENCRYPTION).getAsBoolean());
}
if (jsonObject.has(APIConstants.KeyManager.ENABLE_TOKEN_HASH)) {
keyManagerInfoDTO.setEnableTokenHashing(jsonObject.get(APIConstants.KeyManager.ENABLE_TOKEN_HASH).getAsBoolean());
}
if (jsonObject.has(APIConstants.KeyManager.DISPLAY_TOKEN_ENDPOINT) && !jsonObject.get(APIConstants.KeyManager.DISPLAY_TOKEN_ENDPOINT).isJsonNull() && !jsonObject.get(APIConstants.KeyManager.DISPLAY_TOKEN_ENDPOINT).getAsString().trim().isEmpty()) {
keyManagerInfoDTO.setTokenEndpoint(jsonObject.get(APIConstants.KeyManager.DISPLAY_TOKEN_ENDPOINT).getAsString());
} else {
if (jsonObject.has(APIConstants.KeyManager.TOKEN_ENDPOINT)) {
keyManagerInfoDTO.setTokenEndpoint(jsonObject.get(APIConstants.KeyManager.TOKEN_ENDPOINT).getAsString());
}
}
if (jsonObject.has(APIConstants.KeyManager.DISPLAY_REVOKE_ENDPOINT) && !jsonObject.get(APIConstants.KeyManager.DISPLAY_REVOKE_ENDPOINT).isJsonNull() && !jsonObject.get(APIConstants.KeyManager.DISPLAY_REVOKE_ENDPOINT).getAsString().trim().isEmpty()) {
keyManagerInfoDTO.setRevokeEndpoint(jsonObject.get(APIConstants.KeyManager.DISPLAY_REVOKE_ENDPOINT).getAsString());
} else {
if (jsonObject.has(APIConstants.KeyManager.REVOKE_ENDPOINT)) {
keyManagerInfoDTO.setRevokeEndpoint(jsonObject.get(APIConstants.KeyManager.REVOKE_ENDPOINT).getAsString());
}
}
Map<String, String> additionalProperties = new HashMap<>();
if (keyManagerConfigurationDTO.getAdditionalProperties().containsKey(APIConstants.KeyManager.PRODUCTION_TOKEN_ENDPOINT)) {
additionalProperties.put(APIConstants.KeyManager.PRODUCTION_TOKEN_ENDPOINT, (String) keyManagerConfigurationDTO.getAdditionalProperties().get(APIConstants.KeyManager.PRODUCTION_TOKEN_ENDPOINT));
}
if (keyManagerConfigurationDTO.getAdditionalProperties().containsKey(APIConstants.KeyManager.PRODUCTION_REVOKE_ENDPOINT)) {
additionalProperties.put(APIConstants.KeyManager.PRODUCTION_REVOKE_ENDPOINT, (String) keyManagerConfigurationDTO.getAdditionalProperties().get(APIConstants.KeyManager.PRODUCTION_REVOKE_ENDPOINT));
}
if (keyManagerConfigurationDTO.getAdditionalProperties().containsKey(APIConstants.KeyManager.SANDBOX_TOKEN_ENDPOINT)) {
additionalProperties.put(APIConstants.KeyManager.SANDBOX_TOKEN_ENDPOINT, (String) keyManagerConfigurationDTO.getAdditionalProperties().get(APIConstants.KeyManager.SANDBOX_TOKEN_ENDPOINT));
}
if (keyManagerConfigurationDTO.getAdditionalProperties().containsKey(APIConstants.KeyManager.SANDBOX_REVOKE_ENDPOINT)) {
additionalProperties.put(APIConstants.KeyManager.SANDBOX_REVOKE_ENDPOINT, (String) keyManagerConfigurationDTO.getAdditionalProperties().get(APIConstants.KeyManager.SANDBOX_REVOKE_ENDPOINT));
}
keyManagerInfoDTO.setAdditionalProperties(additionalProperties);
keyManagerInfoDTO.setApplicationConfiguration(fromKeyManagerConfigurationDto(keyManagerConfigurationDTO.getType()));
return keyManagerInfoDTO;
}
use of org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO in project carbon-apimgt by wso2.
the class ApplicationRegistrationWSWorkflowExecutorTest method init.
@Before
public void init() throws Exception {
ServiceReferenceHolder serviceReferenceHolder = TestUtils.getServiceReferenceHolder();
ConfigurationContextService configurationContextService = Mockito.mock(ConfigurationContextService.class);
configurationContext = Mockito.mock(ConfigurationContext.class);
PowerMockito.when(serviceReferenceHolder.getContextService()).thenReturn(configurationContextService);
PowerMockito.when(configurationContextService.getClientConfigContext()).thenReturn(configurationContext);
serviceClient = Mockito.mock(ServiceClient.class);
PowerMockito.whenNew(ServiceClient.class).withAnyArguments().thenReturn(serviceClient);
applicationRegistrationWSWorkflowExecutor = new ApplicationRegistrationWSWorkflowExecutor();
apiMgtDAO = TestUtils.getApiMgtDAO();
application = new Application("test", new Subscriber("testUser"));
application.setCallbackUrl(callBaclURL);
application.setTier("Unlimited");
PowerMockito.mockStatic(KeyManagerHolder.class);
keyManager = Mockito.mock(KeyManager.class);
KeyManagerConfiguration keyManagerConfiguration = new KeyManagerConfiguration();
Mockito.when(keyManager.getKeyManagerConfiguration()).thenReturn(keyManagerConfiguration);
PowerMockito.when(KeyManagerHolder.getKeyManagerInstance("carbon.super", "default")).thenReturn(keyManager);
OAuthApplicationInfo oAuthApplicationInfo = new OAuthApplicationInfo();
PowerMockito.when(keyManager.createApplication((OAuthAppRequest) Mockito.anyObject())).thenReturn(oAuthApplicationInfo);
OAuthAppRequest oAuthAppRequest = new OAuthAppRequest();
oAuthAppRequest.setOAuthApplicationInfo(oAuthApplicationInfo);
workflowDTO = new ApplicationRegistrationWorkflowDTO();
workflowDTO.setWorkflowReference("1");
workflowDTO.setApplication(application);
workflowDTO.setCallbackUrl(callBaclURL);
workflowDTO.setTenantDomain("carbon.super");
workflowDTO.setUserName("testUser");
workflowDTO.setExternalWorkflowReference("testUser");
workflowDTO.setKeyType("PRODUCTION");
workflowDTO.setAppInfoDTO(oAuthAppRequest);
KeyManagerConfigurationDTO kmConfigDTO = new KeyManagerConfigurationDTO();
kmConfigDTO.setOrganization("carbon.super");
kmConfigDTO.setName("default");
PowerMockito.when(apiMgtDAO.getKeyManagerConfigurationByUUID("default")).thenReturn(kmConfigDTO);
}
use of org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO in project carbon-apimgt by wso2.
the class KeyManagersApiServiceImpl method getAllKeyManagers.
@Override
public Response getAllKeyManagers(MessageContext messageContext) throws APIManagementException {
String organization = RestApiUtil.getOrganization(messageContext);
APIAdmin apiAdmin = new APIAdminImpl();
List<KeyManagerConfigurationDTO> keyManagerConfigurations = apiAdmin.getKeyManagerConfigurationsByOrganization(organization);
return Response.ok(KeyManagerMappingUtil.toKeyManagerListDto(keyManagerConfigurations)).build();
}
use of org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO in project carbon-apimgt by wso2.
the class IdpKmPurgeTest method testOrganizationRemoval.
@Test
public void testOrganizationRemoval() throws APIManagementException, UserStoreException {
PowerMockito.mockStatic(APIUtil.class);
PowerMockito.mockStatic(OrganizationPurgeDAO.class);
PowerMockito.when(OrganizationPurgeDAO.getInstance()).thenReturn(organizationPurgeDAO);
PowerMockito.mockStatic(ApiMgtDAO.class);
PowerMockito.when(ApiMgtDAO.getInstance()).thenReturn(apiMgtDAO);
KeyManagerConfigurationDTO kmConfig = Mockito.mock(KeyManagerConfigurationDTO.class);
List<KeyManagerConfigurationDTO> keyManagerList = new ArrayList<>();
keyManagerList.add(kmConfig);
Mockito.doReturn(keyManagerList).when(amAdmin).getKeyManagerConfigurationsByOrganization("testOrg");
Mockito.doNothing().when(organizationPurgeDAO).deleteKeyManagerConfigurationList(keyManagerList, "testOrg");
Mockito.doReturn(true).when(organizationPurgeDAO).keyManagerOrganizationExist(Mockito.anyString());
Mockito.doNothing().when(amAdmin).deleteIdentityProvider("testOrg", kmConfig);
Mockito.when(APIUtil.isInternalOrganization("testOrg")).thenReturn(true);
IdpKeyMangerPurge kmPurge = new IdpKeyManagerPurgeWrapper(organizationPurgeDAO);
LinkedHashMap<String, String> subtaskResult = kmPurge.purge("testOrg");
for (Map.Entry<String, String> entry : subtaskResult.entrySet()) {
Assert.assertEquals(entry.getKey() + " is not successful", APIConstants.OrganizationDeletion.COMPLETED, entry.getValue());
}
Mockito.verify(organizationPurgeDAO, Mockito.times(1)).deleteKeyManagerConfigurationList(Matchers.anyListOf(KeyManagerConfigurationDTO.class), Mockito.any());
}
Aggregations