Search in sources :

Example 21 with KeyManagerConfigurationDTO

use of org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO in project carbon-apimgt by wso2.

the class APIAdminImpl method deleteKeyManagerConfigurationById.

@Override
public void deleteKeyManagerConfigurationById(String organization, KeyManagerConfigurationDTO kmConfig) throws APIManagementException {
    if (kmConfig != null) {
        if (!APIConstants.KeyManager.DEFAULT_KEY_MANAGER.equals(kmConfig.getName())) {
            deleteIdentityProvider(organization, kmConfig);
            apiMgtDAO.deleteKeyManagerConfigurationById(kmConfig.getUuid(), organization);
            new KeyMgtNotificationSender().notify(kmConfig, APIConstants.KeyManager.KeyManagerEvent.ACTION_DELETE);
        } else {
            throw new APIManagementException(APIConstants.KeyManager.DEFAULT_KEY_MANAGER + " couldn't delete", ExceptionCodes.INTERNAL_ERROR);
        }
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) KeyMgtNotificationSender(org.wso2.carbon.apimgt.impl.keymgt.KeyMgtNotificationSender)

Example 22 with KeyManagerConfigurationDTO

use of org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO in project carbon-apimgt by wso2.

the class ApplicationRegistrationSimpleWorkflowExecutorTest method init.

@Before
public void init() throws APIManagementException {
    PowerMockito.mockStatic(ApiMgtDAO.class);
    PowerMockito.mockStatic(KeyManagerHolder.class);
    apiMgtDAO = Mockito.mock(ApiMgtDAO.class);
    keyManager = Mockito.mock(KeyManager.class);
    application = new Application("test", new Subscriber("testUser"));
    oAuthAppRequest = new OAuthAppRequest();
    oAuthApplicationInfo = new OAuthApplicationInfo();
    oAuthAppRequest.setOAuthApplicationInfo(oAuthApplicationInfo);
    workflowDTO = new ApplicationRegistrationWorkflowDTO();
    workflowDTO.setWorkflowReference("1");
    workflowDTO.setApplication(application);
    workflowDTO.setAppInfoDTO(oAuthAppRequest);
    workflowDTO.setKeyManager("default");
    KeyManagerConfigurationDTO kmConfigDTO = new KeyManagerConfigurationDTO();
    kmConfigDTO.setOrganization("carbon.super");
    kmConfigDTO.setName("default");
    PowerMockito.when(apiMgtDAO.getKeyManagerConfigurationByUUID("default")).thenReturn(kmConfigDTO);
    PowerMockito.when(ApiMgtDAO.getInstance()).thenReturn(apiMgtDAO);
    PowerMockito.when(KeyManagerHolder.getKeyManagerInstance("carbon.super", "default")).thenReturn(keyManager);
    KeyManagerConfiguration keyManagerConfiguration = new KeyManagerConfiguration();
    Mockito.when(keyManager.getKeyManagerConfiguration()).thenReturn(keyManagerConfiguration);
    applicationRegistrationSimpleWorkflowExecutor = new ApplicationRegistrationSimpleWorkflowExecutor();
}
Also used : KeyManagerConfigurationDTO(org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO) ApplicationRegistrationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationRegistrationWorkflowDTO) Subscriber(org.wso2.carbon.apimgt.api.model.Subscriber) OAuthAppRequest(org.wso2.carbon.apimgt.api.model.OAuthAppRequest) OAuthApplicationInfo(org.wso2.carbon.apimgt.api.model.OAuthApplicationInfo) ApiMgtDAO(org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO) KeyManager(org.wso2.carbon.apimgt.api.model.KeyManager) Application(org.wso2.carbon.apimgt.api.model.Application) KeyManagerConfiguration(org.wso2.carbon.apimgt.api.model.KeyManagerConfiguration) Before(org.junit.Before)

Example 23 with KeyManagerConfigurationDTO

use of org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO in project carbon-apimgt by wso2.

the class KeymanagersApiServiceImpl method keymanagersGet.

public Response keymanagersGet(String xWSO2Tenant, MessageContext messageContext) {
    xWSO2Tenant = SubscriptionValidationDataUtil.validateTenantDomain(xWSO2Tenant, messageContext);
    try {
        APIAdmin apiAdmin = new APIAdminImpl();
        List<KeyManagerConfigurationDTO> keyManagerConfigurations = apiAdmin.getKeyManagerConfigurationsByOrganization(xWSO2Tenant);
        List<KeyManagerDTO> keyManagerDTOList = new ArrayList<>();
        for (KeyManagerConfigurationDTO keyManagerConfiguration : keyManagerConfigurations) {
            keyManagerDTOList.add(toKeyManagerDTO(xWSO2Tenant, keyManagerConfiguration));
        }
        return Response.ok(keyManagerDTOList).build();
    } catch (APIManagementException e) {
        RestApiUtil.handleInternalServerError("Error while retrieving key manager configurations", e, log);
    }
    return null;
}
Also used : KeyManagerConfigurationDTO(org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) ArrayList(java.util.ArrayList) KeyManagerDTO(org.wso2.carbon.apimgt.internal.service.dto.KeyManagerDTO) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl)

Example 24 with KeyManagerConfigurationDTO

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

Example 25 with KeyManagerConfigurationDTO

use of org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO in project carbon-apimgt by wso2.

the class KeyManagerMappingUtil method fromKeyManagerConfigurationDtoToKeyManagerInfoDto.

private static KeyManagerInfoDTO fromKeyManagerConfigurationDtoToKeyManagerInfoDto(KeyManagerConfigurationDTO configurationDto) {
    KeyManagerInfoDTO keyManagerInfoDTO = new KeyManagerInfoDTO();
    keyManagerInfoDTO.setName(configurationDto.getName());
    keyManagerInfoDTO.setDisplayName(configurationDto.getDisplayName());
    keyManagerInfoDTO.setDescription(configurationDto.getDescription());
    keyManagerInfoDTO.setId(configurationDto.getUuid());
    keyManagerInfoDTO.setEnabled(configurationDto.isEnabled());
    keyManagerInfoDTO.setType(configurationDto.getType());
    return keyManagerInfoDTO;
}
Also used : KeyManagerInfoDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.KeyManagerInfoDTO)

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