2016-04-26 11 views
0

OAuthAdminServiceを呼び出してWSO2 Identity Serverにアプリケーションを作成するJavaクライアントを開発しています。いくつかの掘り下げの後、私はregisterOAuthApplicationData()メソッドがISでアプリケーションを作成するために使用されるメソッドであることを発見しました。メソッドを呼び出す前に、AuthenticationAdminStub型のlogin()メソッドを使用してadminユーザーを認証しました。このような認証後registerOAuthApplicationData()メソッドWSO2 Identity Serverがプログラムでアプリケーションを作成して「不正アクセス試行」の警告を表示する

を印刷するコンソールを作る {org.wso2.carbon.server.admin.module.handlerに警告[2016年4月26日13:52577:08]。 IPアドレス 127.0.0.1からのサービスOAuthAdminService

へのアクセスを認証しようとすると、アプリケーションが作成取得されていない状態で[52,0577:08 2016年4月26日13] - 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

ありがとうございます.. –

関連する問題