WSO2 Identity Server以编程方式创建一个抛出“非法访问尝试”警告的应用程序

时间:2016-04-26 09:26:09

标签: wso2is

我正在开发一个Java客户端,它将通过调用OAuthAdminService在WSO2 Identity Server中创建一个应用程序。经过一番挖掘后,我发现registerOAuthApplicationData()方法是用于在IS中创建应用程序的方法。在调用该方法之前,我已经通过AuthenticationAdminStub类型的login()方法对admin用户进行了身份验证。即使在这种认证之后,registerOAuthApplicationData()方法也会使IS控制台打印

  

[2016-04-26 13:08:52,577]警告   {org.wso2.carbon.server.admin.module.handler.AuthenticationHandler} -   从IP地址[2016-04-26 13:08:52,0577]进行非法访问尝试   127.0.0.1尝试验证对服务OAuthAdminService的访问权限

并且未在IS数据库中创建应用程序。

我尝试的代码如下

import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.axis2.transport.http.HTTPConstants;
import org.wso2.carbon.authenticator.proxy.AuthenticationAdminStub;
import org.wso2.carbon.identity.oauth.OAuthAdminServicePortTypeProxy;
import org.wso2.carbon.identity.oauth.dto.xsd.OAuthConsumerAppDTO;

    public class IdentityClientOne {    


            private final static String SERVER_URL = "https://localhost:9443/services/";
            private final static String APP_ID = "myapp";

            /**
             * @param args
             */
            public static void main(String[] args) {

                AuthenticationAdminStub authstub = null;
                ConfigurationContext configContext = null;

                System.setProperty("javax.net.ssl.trustStore", "wso2carbon.jks");
                System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon");

                try {
                    configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(
                            "repo", "repo/conf/client.axis2.xml");
                    authstub = new AuthenticationAdminStub(configContext, SERVER_URL
                            + "AuthenticationAdmin");

                    // Authenticates as a user having rights to add users.
                    if (authstub.login("admin", "admin", APP_ID)) {
                        System.out.println("admin authenticated");


                        OAuthConsumerAppDTO consumerApp = new OAuthConsumerAppDTO("Oauth-2.0",
                                "sample_app",
                                "",
                                "authorization_code implicit password client_credentials refresh_token urn:ietf:params:oauth:grant-type:saml2-bearer iwa:ntlm","","","");


                        OAuthAdminServicePortTypeProxy OAuthAdminProxy = new OAuthAdminServicePortTypeProxy();
                        OAuthAdminProxy.registerOAuthApplicationData(consumerApp);

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

    }

请帮忙做些什么?

1 个答案:

答案 0 :(得分:1)

您必须通过经过身份验证的会话访问存根。

你能在下面试试。

public class Test {
    private final static String SERVER_URL = "https://localhost:9443/services/";

    public static void main(String[] args) throws RemoteException, OAuthAdminServiceException {

        OAuthAdminServiceStub stub = new OAuthAdminServiceStub(null, SERVER_URL + "OAuthAdminService");

        ServiceClient client = stub._getServiceClient();
        authenticate(client);

        OAuthConsumerAppDTO consumerAppDTO = new OAuthConsumerAppDTO();
        consumerAppDTO.setApplicationName("sample-app");
        consumerAppDTO.setCallbackUrl("http://localhost:8080/playground2/oauth2client");
        consumerAppDTO.setOAuthVersion("OAuth-2.0");
        consumerAppDTO.setGrantTypes("authorization_code implicit password client_credentials refresh_token "
                                     + "urn:ietf:params:oauth:grant-type:saml2-bearer iwa:ntlm");

        stub.registerOAuthApplicationData(consumerAppDTO);
    }

    public static void authenticate(ServiceClient client) {
        Options option = client.getOptions();
        HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();
        auth.setUsername("admin");
        auth.setPassword("admin");
        auth.setPreemptiveAuthentication(true);
        option.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, auth);
        option.setManageSession(true);
    }
}