0

wso2 esb に存在するバージョン プロキシ サービス用の Java クライアントを作成したいと考えています。ユーザー名トークン認証シナリオでバージョン プロキシを保護しました。これで、この保護されたプロキシ サービスを呼び出す Java クライアントの作成を開始しました。クライアント コードは次のとおりです。

package org.wso2.carbon.security.ws;

import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.axis2.description.AxisBinding;
import org.apache.axis2.description.AxisEndpoint;
import org.apache.axis2.rpc.client.RPCServiceClient;
import org.apache.neethi.Policy;

import javax.xml.namespace.QName;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Map;

public class HelloServiceClient {

    static {
        System.setProperty("javax.net.ssl.trustStore", "/path/to/keystore" + File.separator+ "wso2carbon.jks");
        System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon");
    }

    public static void main(String[] args) {
        try {

            int securityScenario = getSecurityScenario();

            String repository = "/path/to/repo" + File.separator + "repository";

            ConfigurationContext confContext =
                    ConfigurationContextFactory.
                            createConfigurationContextFromFileSystem(repository, null);

            String endPoint = "HelloServiceHttpSoap12Endpoint";
            if(securityScenario == 1){
                endPoint = "HelloServiceHttpsSoap12Endpoint";   // scenario 1 uses HelloServiceHttpsSoap12Endpoint
            }

            RPCServiceClient dynamicClient =
                    new RPCServiceClient(confContext,
                                         new URL("http://pc213712:8281/services/Version?wsdl"),
                                         new QName("http://version.services.core.carbon.wso2.org", "Version"),
                                         endPoint);

            //Engage Modules
            dynamicClient.engageModule("rampart");
            dynamicClient.engageModule("addressing");

            //TODO : Change the port to monitor the messages through TCPMon
            if(securityScenario != 1){
                dynamicClient.getOptions().setTo(new EndpointReference("http://pc213712:8281/services/Version/"));
            }

            //Get the policy from the binding and append the rampartconfig assertion
            Map endPoints = dynamicClient.getAxisService().getEndpoints();
            AxisBinding axisBinding = ((AxisEndpoint) endPoints.values().iterator().next()).getBinding();
            Policy policy = axisBinding.getEffectivePolicy();
            **policy.addAssertion(RampartConfigBuilder.createRampartConfig(securityScenario));**
            axisBinding.applyPolicy(policy);

            //Invoke the service
            Object[] returnArray = dynamicClient.invokeBlocking(new QName("http://www.wso2.org/types","greet"),
                                                                new Object[]{"Alice"},
                                                                new Class[]{String.class});

            System.out.println((String) returnArray[0]);

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    private static int getSecurityScenario() {
        int scenarioNumber = 0;
        while (scenarioNumber < 1 || scenarioNumber > 15) {
            System.out.print("Insert the security scenario no : ");
            String inputString = readOption();
            try {
                scenarioNumber = new Integer(inputString);
            } catch (Exception e) {
                System.out.println("invalid input, insert a integer between 1 and 15");
            }
            if(scenarioNumber < 1 || scenarioNumber > 15){
                System.out.println("Scenario number should be between 1 and 15");
            }
        }
        return scenarioNumber;
    }
    private static String readOption() {
        try {
            BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
            String str;
            while ((str = console.readLine()).equals("")) {
            }
            return str;
        } catch (Exception e) {
            return null;
        }
    }
}

しかし、上記のコードでは、次の 1 行に感銘を受けました。

policy.addAssertion(RampartConfigBuilder.createRampartConfig(securityScenario));

ここで私のrampart_core jarでRampartConfigBuilderクラスを取得していますが、このクラス内にはcreateRampartConfigと呼ばれるメソッドはありません。そのため、Rampart 構成を作成できません。この問題を解決するにはどうすればよいですか? あなたの解決策を楽しみにしています。前もって感謝します

4

0 に答える 0