2016-04-26 44 views
0

我正在开发一个Java客户端,它将通过调用OAuthAdminService在WSO2 Identity Server中创建应用程序。经过一番挖掘,我发现registerOAuthApplicationData()方法是用于在IS中创建应用程序的方法。在调用方法之前,我通过AuthenticationAdminStub类型的login()方法对admin用户进行了身份验证。即使这样的认证后的registerOAuthApplicationData()方法使IS控制台打印以编程方式创建应用程序的WSO2 Identity Server引发“非法访问尝试”警告

[2016年4月26日13:08:52577] WARN {org.wso2.carbon.server.admin.module.handler。 [:08:52,0577 2016年4月26日13]从IP地址127.0.0.1 尝试验证时访问服务OAuthAdminService

,并没有得到创建的应用程序 - 的AuthenticationHandler} 非法访问的尝试在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

您必须通过已验证的会话访问存根。

你可以试试下面。

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); 
    } 
} 
+0

It works .. Thank You .. –

相关问题