Search in sources :

Example 86 with Artifacts

use of org.wso2.ei.dashboard.core.rest.model.Artifacts in project product-microgateway by wso2.

the class CommonUtils method extractResources.

/**
 * Extract resource artifacts from the jar file.
 * @param projectName project name.
 * @throws IOException
 */
public static void extractResources(String projectName) throws IOException {
    String path = Constants.RESOURCE_LOCATION + projectName + Constants.FORWARD_SLASH;
    CodeSource src = Validate.class.getProtectionDomain().getCodeSource();
    StringBuffer stringBuffer;
    if (src != null) {
        URL jar = src.getLocation();
        ZipInputStream zip = new ZipInputStream(jar.openStream());
        while (true) {
            ZipEntry e = zip.getNextEntry();
            if (e == null) {
                break;
            }
            String name = e.getName();
            if (name.startsWith(path) && name.endsWith(Constants.JSON_EXTENSION)) {
                String fileName = Paths.get(name).getFileName().toString();
                String apiName = fileName.substring(0, fileName.lastIndexOf(Constants.UNDER_SCORE));
                String apiVersion = fileName.substring(fileName.lastIndexOf(Constants.UNDER_SCORE) + 1, fileName.lastIndexOf(Constants.DOT));
                String serviceName = CommonUtils.getQualifiedServiceName(apiName, apiVersion);
                InputStream in = Validate.class.getResourceAsStream(Constants.FORWARD_SLASH + name);
                BufferedReader reader = new BufferedReader(new InputStreamReader(in));
                stringBuffer = new StringBuffer();
                String line;
                while ((line = reader.readLine()) != null) {
                    stringBuffer.append(line).append("\n");
                }
                openAPIMap.put(serviceName, stringBuffer.toString());
            }
        }
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) InputStreamReader(java.io.InputStreamReader) Validate(org.wso2.micro.gateway.core.validation.Validate) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) BufferedReader(java.io.BufferedReader) CodeSource(java.security.CodeSource) URL(java.net.URL)

Example 87 with Artifacts

use of org.wso2.ei.dashboard.core.rest.model.Artifacts in project product-is by wso2.

the class SPMetaDataTenantTestCase method addSPMetadataForTenant.

@Test(testName = "metaDataTestcase")
public void addSPMetadataForTenant() throws Exception {
    String filePath = FrameworkPathUtil.getSystemResourceLocation() + "artifacts" + File.separator + "IS" + File.separator + "saml" + File.separator + "sp-metadata.xml";
    byte[] encoded = Files.readAllBytes(Paths.get(filePath));
    String metadataXml = new String(encoded, StandardCharsets.UTF_8);
    // Load the metadata file to the client.
    SAMLSSOServiceProviderDTO samlssoServiceProviderDTO = ssoConfigServiceClient.uploadServiceProvider(metadataXml);
    Assert.assertEquals(samlssoServiceProviderDTO.getIssuer(), ISSUER);
    SAMLSSOServiceProviderDTO[] samlssoServiceProviderDTOs = ssoConfigServiceClient.getServiceProviders().getServiceProviders();
    SAMLSSOServiceProviderDTO samlssoServiceProviderDTOGet = null;
    for (SAMLSSOServiceProviderDTO serviceProviderDTO : samlssoServiceProviderDTOs) {
        if (ISSUER.equals(serviceProviderDTO.getIssuer())) {
            samlssoServiceProviderDTOGet = serviceProviderDTO;
        }
    }
    Assert.assertNotNull(samlssoServiceProviderDTOGet);
    Assert.assertEquals(samlssoServiceProviderDTOGet.getCertAlias(), CERT_ALIAS);
    KeyStoreAdminClient keyStoreAdminClient = new KeyStoreAdminClient(backendURL, ADMIN_USERNAME, ADMIN_PASSWORD);
    KeyStoreData[] keyStoreDataArray = keyStoreAdminClient.getKeyStores();
    Assert.assertTrue(keyStoreDataArray != null && keyStoreDataArray.length > 0);
    String[] storeEntries = keyStoreAdminClient.getStoreEntries("wso2-com.jks");
    Assert.assertTrue(storeEntries != null && storeEntries.length > 0);
    Assert.assertTrue(Arrays.asList(storeEntries).contains(CERT_ALIAS));
}
Also used : KeyStoreAdminClient(org.wso2.identity.integration.common.clients.KeyStoreAdminClient) SAMLSSOServiceProviderDTO(org.wso2.carbon.identity.sso.saml.stub.types.SAMLSSOServiceProviderDTO) KeyStoreData(org.wso2.carbon.security.mgt.stub.keystore.xsd.KeyStoreData) ISIntegrationTest(org.wso2.identity.integration.common.utils.ISIntegrationTest) Test(org.testng.annotations.Test)

Example 88 with Artifacts

use of org.wso2.ei.dashboard.core.rest.model.Artifacts in project product-is by wso2.

the class SPMetadataTestCase method addSPMetadata.

@Test
public void addSPMetadata() throws Exception {
    String filePath = FrameworkPathUtil.getSystemResourceLocation() + "artifacts" + File.separator + "IS" + File.separator + "saml" + File.separator + "sp-metadata.xml";
    byte[] encoded = Files.readAllBytes(Paths.get(filePath));
    String metadataXml = new String(encoded, StandardCharsets.UTF_8);
    SAMLSSOServiceProviderDTO samlssoServiceProviderDTO = ssoConfigServiceClient.uploadServiceProvider(metadataXml);
    Assert.assertEquals(samlssoServiceProviderDTO.getIssuer(), ISSUER);
    Assert.assertEquals(samlssoServiceProviderDTO.getDefaultAssertionConsumerUrl(), ACSs[0]);
    Assert.assertEquals(samlssoServiceProviderDTO.getAssertionConsumerUrls(), ACSs);
    SAMLSSOServiceProviderDTO[] samlssoServiceProviderDTOs = ssoConfigServiceClient.getServiceProviders().getServiceProviders();
    SAMLSSOServiceProviderDTO samlssoServiceProviderDTOGet = null;
    for (SAMLSSOServiceProviderDTO serviceProviderDTO : samlssoServiceProviderDTOs) {
        if (ISSUER.equals(serviceProviderDTO.getIssuer())) {
            samlssoServiceProviderDTOGet = serviceProviderDTO;
        }
    }
    Assert.assertNotNull(samlssoServiceProviderDTOGet);
    Assert.assertEquals(samlssoServiceProviderDTOGet.getDefaultAssertionConsumerUrl(), ACSs[0]);
    Assert.assertEquals(samlssoServiceProviderDTOGet.getAssertionConsumerUrls(), ACSs);
    Assert.assertEquals(samlssoServiceProviderDTOGet.getNameIDFormat(), NAMEIDFORMAT);
    Assert.assertEquals(samlssoServiceProviderDTOGet.getDoSignAssertions(), WANTASSERTIONSSIGNED);
    Assert.assertEquals(samlssoServiceProviderDTOGet.getDoValidateSignatureInRequests(), ISAAUTHNREQUESTSSIGNED);
    Assert.assertEquals(samlssoServiceProviderDTOGet.getSloRequestURL(), SLOREQUESTURL);
    Assert.assertEquals(samlssoServiceProviderDTOGet.getSloResponseURL(), SLORESPONSEURL);
}
Also used : SAMLSSOServiceProviderDTO(org.wso2.carbon.identity.sso.saml.stub.types.SAMLSSOServiceProviderDTO) ISIntegrationTest(org.wso2.identity.integration.common.utils.ISIntegrationTest) Test(org.testng.annotations.Test)

Aggregations

File (java.io.File)23 IOException (java.io.IOException)18 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)18 ArrayList (java.util.ArrayList)17 CAppArtifacts (org.wso2.ei.dashboard.core.rest.model.CAppArtifacts)16 Operation (io.swagger.v3.oas.annotations.Operation)15 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)15 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)15 Response (javax.ws.rs.core.Response)15 Artifact (org.wso2.carbon.application.deployer.config.Artifact)15 Artifacts (org.wso2.ei.dashboard.core.rest.model.Artifacts)15 DeploymentException (org.apache.axis2.deployment.DeploymentException)11 CappFile (org.wso2.carbon.application.deployer.config.CappFile)11 Deployer (org.apache.axis2.deployment.Deployer)10 ArtifactSynchronizerException (org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.exception.ArtifactSynchronizerException)10 Organization (org.wso2.carbon.apimgt.persistence.dto.Organization)10 InputStream (java.io.InputStream)9 FileInputStream (java.io.FileInputStream)7 APIRuntimeArtifactDto (org.wso2.carbon.apimgt.impl.dto.APIRuntimeArtifactDto)7 APIPersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException)7