Search in sources :

Example 31 with KeyManagerConfigurationDTO

use of org.wso2.carbon.apimgt.rest.api.admin.v1.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;
}
Also used : KeyManagerConfigurationDTO(org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO) KeyManagerListDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.KeyManagerListDTO) ArrayList(java.util.ArrayList) KeyManagerInfoDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.KeyManagerInfoDTO)

Example 32 with KeyManagerConfigurationDTO

use of org.wso2.carbon.apimgt.rest.api.admin.v1.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;
}
Also used : JsonArray(com.google.gson.JsonArray) HashMap(java.util.HashMap) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) ArrayList(java.util.ArrayList) List(java.util.List) KeyManagerInfoDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.KeyManagerInfoDTO)

Example 33 with KeyManagerConfigurationDTO

use of org.wso2.carbon.apimgt.rest.api.admin.v1.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);
}
Also used : ServiceReferenceHolder(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) KeyManagerConfigurationDTO(org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO) ApplicationRegistrationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationRegistrationWorkflowDTO) ConfigurationContextService(org.wso2.carbon.utils.ConfigurationContextService) Subscriber(org.wso2.carbon.apimgt.api.model.Subscriber) OAuthAppRequest(org.wso2.carbon.apimgt.api.model.OAuthAppRequest) ServiceClient(org.apache.axis2.client.ServiceClient) OAuthApplicationInfo(org.wso2.carbon.apimgt.api.model.OAuthApplicationInfo) Application(org.wso2.carbon.apimgt.api.model.Application) KeyManager(org.wso2.carbon.apimgt.api.model.KeyManager) KeyManagerConfiguration(org.wso2.carbon.apimgt.api.model.KeyManagerConfiguration) Before(org.junit.Before)

Example 34 with KeyManagerConfigurationDTO

use of org.wso2.carbon.apimgt.rest.api.admin.v1.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();
}
Also used : KeyManagerConfigurationDTO(org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO) APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl)

Example 35 with KeyManagerConfigurationDTO

use of org.wso2.carbon.apimgt.rest.api.admin.v1.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());
}
Also used : KeyManagerConfigurationDTO(org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO) IdpKeyMangerPurge(org.wso2.carbon.apimgt.cleanup.service.IdpKeyMangerPurge) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

KeyManagerConfigurationDTO (org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO)43 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)30 Gson (com.google.gson.Gson)16 ArrayList (java.util.ArrayList)13 HashMap (java.util.HashMap)12 OAuthApplicationInfo (org.wso2.carbon.apimgt.api.model.OAuthApplicationInfo)11 JSONObject (org.json.simple.JSONObject)10 JsonObject (com.google.gson.JsonObject)9 PreparedStatement (java.sql.PreparedStatement)9 KeyManager (org.wso2.carbon.apimgt.api.model.KeyManager)9 OAuthAppRequest (org.wso2.carbon.apimgt.api.model.OAuthAppRequest)9 Map (java.util.Map)8 APIAdmin (org.wso2.carbon.apimgt.api.APIAdmin)8 APIAdminImpl (org.wso2.carbon.apimgt.impl.APIAdminImpl)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 Connection (java.sql.Connection)7 SQLException (java.sql.SQLException)7 IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)7 LinkedHashMap (java.util.LinkedHashMap)6 Application (org.wso2.carbon.apimgt.api.model.Application)6