directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From plusplusjia...@apache.org
Subject directory-kerby git commit: DIRKRB-543 Add XDR to remote kadmin to implement addPrincipal. Contributed by Yan.
Date Mon, 25 Apr 2016 05:49:32 GMT
Repository: directory-kerby
Updated Branches:
  refs/heads/kadmin-remote a608a4606 -> c1e324d73


DIRKRB-543 Add XDR to remote kadmin to implement addPrincipal. Contributed by Yan.


Project: http://git-wip-us.apache.org/repos/asf/directory-kerby/repo
Commit: http://git-wip-us.apache.org/repos/asf/directory-kerby/commit/c1e324d7
Tree: http://git-wip-us.apache.org/repos/asf/directory-kerby/tree/c1e324d7
Diff: http://git-wip-us.apache.org/repos/asf/directory-kerby/diff/c1e324d7

Branch: refs/heads/kadmin-remote
Commit: c1e324d73fecab2d8e3e4203bd8d42172830a1dc
Parents: a608a46
Author: plusplusjiajia <jiajia.li@intel.com>
Authored: Mon Apr 25 13:54:32 2016 +0800
Committer: plusplusjiajia <jiajia.li@intel.com>
Committed: Mon Apr 25 13:54:32 2016 +0800

----------------------------------------------------------------------
 .../admin/server/kadmin/AdminServerHandler.java | 33 +++++--
 .../kerb/admin/admin/AdminServerTest.java       |  4 +-
 .../kerb/admin/kadmin/remote/AdminHandler.java  | 18 ++--
 .../admin/kadmin/remote/RemoteKadminImpl.java   |  6 +-
 .../kadmin/remote/impl/DefaultAdminHandler.java |  5 +-
 .../remote/request/AddPrincipalRequest.java     | 75 +++++++++++++++-
 .../kadmin/remote/request/AdminRequest.java     | 22 +++--
 .../kerberos/kerb/admin/tool/AdminMessage.java  |  4 +
 .../kerb/admin/tool/AdminMessageCode.java       | 91 ++++++++++++++++++++
 .../kerb/admin/tool/AdminMessageEnum.java       | 43 +++++++++
 .../kerberos/kerb/admin/admin/AdminTest.java    | 10 +--
 11 files changed, 264 insertions(+), 47 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/c1e324d7/kerby-kerb/kerb-admin-server/src/main/java/org/apache/kerby/kerberos/kerb/admin/server/kadmin/AdminServerHandler.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-admin-server/src/main/java/org/apache/kerby/kerberos/kerb/admin/server/kadmin/AdminServerHandler.java
b/kerby-kerb/kerb-admin-server/src/main/java/org/apache/kerby/kerberos/kerb/admin/server/kadmin/AdminServerHandler.java
index f9235ae..6f7dde0 100644
--- a/kerby-kerb/kerb-admin-server/src/main/java/org/apache/kerby/kerberos/kerb/admin/server/kadmin/AdminServerHandler.java
+++ b/kerby-kerb/kerb-admin-server/src/main/java/org/apache/kerby/kerberos/kerb/admin/server/kadmin/AdminServerHandler.java
@@ -20,9 +20,13 @@
 package org.apache.kerby.kerberos.kerb.admin.server.kadmin;
 
 import org.apache.kerby.kerberos.kerb.admin.tool.AddPrincipalRep;
+import org.apache.kerby.kerberos.kerb.admin.tool.AdminMessageCode;
 import org.apache.kerby.kerberos.kerb.admin.tool.KadminCode;
 import org.apache.kerby.kerberos.kerb.KrbException;
 import org.apache.kerby.kerberos.kerb.admin.tool.AdminMessage;
+import org.apache.kerby.xdr.XdrFieldInfo;
+import org.apache.kerby.xdr.type.XdrString;
+import org.apache.kerby.xdr.type.XdrStructType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -57,24 +61,35 @@ public class AdminServerHandler {
      */
     public ByteBuffer handleMessage(ByteBuffer receivedMessage,
                                     InetAddress remoteAddress) throws KrbException, IOException
{
-        AdminMessage requestMessage = KadminCode.decodeMessage(receivedMessage);
-        System.out.println("receive message type: " + requestMessage.getAdminMessageType());
-        String receiveMsg = new String(requestMessage.getMessageBuffer().array());
+        XdrStructType decoded = new AdminMessageCode();
+        decoded.decode(receivedMessage);
+        XdrFieldInfo[] fieldInfos = decoded.getValue().getXdrFieldInfos();
+        System.out.println("receive message type: " + fieldInfos[0].getValue());
+        System.out.println("receive message paramNum: " + fieldInfos[1].getValue());
+        String receiveMsg = (String) fieldInfos[2].getValue();
         System.out.println("server handleMessage: " + receiveMsg);
         String[] principal = receiveMsg.split("@");
         System.out.println("clientName: " + principal[0]);
         System.out.println("realm: " + principal[1]);
 
         /**Add principal to backend here*/
-        //LocalKadmin localKadmin = new LocalKadminImpl(adminServerContext.getAdminServerSetting()
-        // .getAdminServerConfig(),
-         //       adminServerContext.getAdminServerSetting().getBackendConfig());
+        //LocalKadmin localKadmin = new LocalKadminImpl(adminServerContext.getAdminServerSetting());
         //localKadmin.addPrincipal(principal[0]);
 
         String message = "add principal of " + principal[0];
-        AdminMessage replyMessage = new AddPrincipalRep();
-        replyMessage.setMessageBuffer(ByteBuffer.wrap(message.getBytes()));
-        ByteBuffer responseMessage = KadminCode.encodeMessage(replyMessage);
+        //content to reply remain to construct
+        AdminMessage addPrincipalRep = new AddPrincipalRep();
+        /** encode admin message:
+         *  encode type
+         *  encode paranum
+         *  encode principal name
+         *  (encode koptions)
+         *  (encode passsword)
+         */
+        XdrString value = new XdrString(message);
+        addPrincipalRep.setMessageBuffer(ByteBuffer.wrap(value.encode()));
+        System.out.println("value length:" + addPrincipalRep.getMessageBuffer().capacity());
+        ByteBuffer responseMessage = KadminCode.encodeMessage(addPrincipalRep);
 
         return responseMessage;
 

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/c1e324d7/kerby-kerb/kerb-admin-server/src/test/java/org/apache/kerby/kerberos/kerb/admin/admin/AdminServerTest.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-admin-server/src/test/java/org/apache/kerby/kerberos/kerb/admin/admin/AdminServerTest.java
b/kerby-kerb/kerb-admin-server/src/test/java/org/apache/kerby/kerberos/kerb/admin/admin/AdminServerTest.java
index 520aa9c..654327e 100644
--- a/kerby-kerb/kerb-admin-server/src/test/java/org/apache/kerby/kerberos/kerb/admin/admin/AdminServerTest.java
+++ b/kerby-kerb/kerb-admin-server/src/test/java/org/apache/kerby/kerberos/kerb/admin/admin/AdminServerTest.java
@@ -33,8 +33,8 @@ public class AdminServerTest {
         adminServer.setAllowUdp(false);
         adminServer.setAllowTcp(true);
         adminServer.setAdminTcpPort(65417);
-        adminServer.init();
+        /*adminServer.init();
         adminServer.start();
-        System.out.println("Server started!");
+        System.out.println("Server started!");*/
     }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/c1e324d7/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/AdminHandler.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/AdminHandler.java
b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/AdminHandler.java
index dcd9eee..9238110 100644
--- a/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/AdminHandler.java
+++ b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/AdminHandler.java
@@ -21,10 +21,9 @@ package org.apache.kerby.kerberos.kerb.admin.kadmin.remote;
 
 import org.apache.kerby.kerberos.kerb.KrbException;
 import org.apache.kerby.kerberos.kerb.admin.kadmin.remote.request.AdminRequest;
-import org.apache.kerby.kerberos.kerb.admin.tool.AdminMessage;
-import org.apache.kerby.kerberos.kerb.admin.tool.AdminMessageType;
 import org.apache.kerby.kerberos.kerb.admin.tool.AdminReq;
 import org.apache.kerby.kerberos.kerb.admin.tool.KadminCode;
+import org.apache.kerby.xdr.type.XdrString;
 
 import java.io.IOException;
 import java.nio.ByteBuffer;
@@ -69,20 +68,15 @@ public abstract class AdminHandler {
      */
     public void onResponseMessage(AdminRequest adminRequest,
                                   ByteBuffer responseMessage) throws KrbException {
-        AdminMessage replyMessage = null;
+
         try {
-            replyMessage = KadminCode.decodeMessage(responseMessage);
+            XdrString decoded = new XdrString();
+            decoded.decode(responseMessage);
+            String reply = decoded.getValue();
+            System.out.println(reply);
         } catch (IOException e) {
             throw new KrbException("Kadmin decoding message failed", e);
         }
-        AdminMessageType messageType = replyMessage.getAdminMessageType();
-        if (messageType == AdminMessageType.AD_REP
-                && adminRequest.getAdminReq().getAdminMessageType() == AdminMessageType.AD_REQ)
{
-            String receiveMsg = new String(replyMessage.getMessageBuffer().array());
-            System.out.println("Admin receive message success: " + receiveMsg);
-        } else {
-            throw new RuntimeException("Receive wrong reply");
-        }
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/c1e324d7/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/RemoteKadminImpl.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/RemoteKadminImpl.java
b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/RemoteKadminImpl.java
index 0d8291d..dc8e1f8 100644
--- a/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/RemoteKadminImpl.java
+++ b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/RemoteKadminImpl.java
@@ -89,7 +89,11 @@ public class RemoteKadminImpl implements Kadmin {
     @Override
     public void addPrincipal(String principal,
                              KOptions kOptions) throws KrbException {
-
+        AdminRequest adRequest = new AddPrincipalRequest(principal, kOptions);
+        //wrap buffer problem
+        adRequest.setTransport(transport);
+        AdminHandler adminHandler = new DefaultAdminHandler();
+        adminHandler.handleRequest(adRequest);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/c1e324d7/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/impl/DefaultAdminHandler.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/impl/DefaultAdminHandler.java
b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/impl/DefaultAdminHandler.java
index eed8b55..d0e1d07 100644
--- a/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/impl/DefaultAdminHandler.java
+++ b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/impl/DefaultAdminHandler.java
@@ -30,11 +30,12 @@ import java.nio.ByteBuffer;
 public class DefaultAdminHandler extends AdminHandler {
 
     /**
-     * {@inheritDoc}
+     * Use super.handleRequest to send message
+     * and use this to receive message.
      */
     @Override
     public void handleRequest(AdminRequest adminRequest) throws KrbException {
-        //
+        /**super is used to send message*/
         super.handleRequest(adminRequest);
 
         KrbTransport transport = adminRequest.getTransport();

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/c1e324d7/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/request/AddPrincipalRequest.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/request/AddPrincipalRequest.java
b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/request/AddPrincipalRequest.java
index 0198b62..cc2a447 100644
--- a/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/request/AddPrincipalRequest.java
+++ b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/request/AddPrincipalRequest.java
@@ -19,29 +19,96 @@
  */
 package org.apache.kerby.kerberos.kerb.admin.kadmin.remote.request;
 
+import org.apache.kerby.KOptions;
 import org.apache.kerby.kerberos.kerb.KrbException;
-import org.apache.kerby.kerberos.kerb.admin.kadmin.remote.AdminContext;
 import org.apache.kerby.kerberos.kerb.admin.tool.AddPrincipalReq;
+import org.apache.kerby.kerberos.kerb.admin.tool.AdminMessageCode;
+import org.apache.kerby.kerberos.kerb.admin.tool.AdminMessageType;
+import org.apache.kerby.xdr.XdrDataType;
+import org.apache.kerby.xdr.XdrFieldInfo;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
 
 /**
  * AddPrincipal request
  */
 public class AddPrincipalRequest extends AdminRequest {
 
-    public AddPrincipalRequest(AdminContext context) {
-        super(context);
-    }
+    private KOptions kOptions;
+    private String password;
 
     public AddPrincipalRequest(String principal) {
         super(principal);
     }
 
+    public AddPrincipalRequest(String principal, KOptions kOptions) {
+        super(principal);
+        this.kOptions = kOptions;
+    }
+
+    public AddPrincipalRequest(String princial, KOptions kOptions, String password) {
+        super(princial);
+        this.kOptions = kOptions;
+        this.password = password;
+    }
+
+
     @Override
     public void process() throws KrbException {
         super.process();
+        /**replace this with encode in handler*/
         AddPrincipalReq addPrincipalReq = new AddPrincipalReq();
+        /** encode admin message:
+         *  encode type
+         *  encode paranum
+         *  encode principal name
+         *  (encode koptions)
+         *  (encode passsword)
+         */
+        int paramNum = getParamNum();
+        XdrFieldInfo[] xdrFieldInfos = new XdrFieldInfo[paramNum + 2];
+        xdrFieldInfos[0] = new XdrFieldInfo(0, XdrDataType.ENUM, AdminMessageType.AD_REQ);
+        xdrFieldInfos[1] = new XdrFieldInfo(1, XdrDataType.INTEGER, paramNum);
+        xdrFieldInfos[2] = new XdrFieldInfo(2, XdrDataType.STRING, getPrincipal());
+        if (paramNum == 2 && kOptions != null) {
+            xdrFieldInfos[3] = new XdrFieldInfo(3, XdrDataType.STRUCT, kOptions); /////koption
+        } else if (paramNum == 2 && password != null) {
+            xdrFieldInfos[3] = new XdrFieldInfo(3, XdrDataType.STRING, password);
+        } else if (paramNum == 3) {
+            xdrFieldInfos[3] = new XdrFieldInfo(3, XdrDataType.STRUCT, kOptions); ////koption
+            xdrFieldInfos[4] = new XdrFieldInfo(4, XdrDataType.STRING, password);
+        }
+        AdminMessageCode value = new AdminMessageCode(xdrFieldInfos);
+        byte[] encodeBytes;
+        try {
+            encodeBytes = value.encode();
+        } catch (IOException e) {
+            throw new KrbException("Xdr encode error when generate add principal request.",
e);
+        }
+        ByteBuffer messageBuffer = ByteBuffer.wrap(encodeBytes);
+        addPrincipalReq.setMessageBuffer(messageBuffer);
+
+
+
+
         setAdminReq(addPrincipalReq);
 
     }
 
+    public int getParamNum() {
+        int paramNum = 0;
+        if (getPrincipal() == null) {
+            throw new RuntimeException("Principal name missing.");
+        }
+        if (kOptions == null && password == null) {
+            paramNum = 1;
+        } else if (kOptions == null || password == null) {
+            paramNum = 2;
+        } else {
+            paramNum = 3;
+        }
+        return paramNum;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/c1e324d7/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/request/AdminRequest.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/request/AdminRequest.java
b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/request/AdminRequest.java
index 3b82298..2cd821a 100644
--- a/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/request/AdminRequest.java
+++ b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/request/AdminRequest.java
@@ -20,32 +20,30 @@
 package org.apache.kerby.kerberos.kerb.admin.kadmin.remote.request;
 
 import org.apache.kerby.kerberos.kerb.KrbException;
-import org.apache.kerby.kerberos.kerb.admin.kadmin.remote.AdminContext;
 import org.apache.kerby.kerberos.kerb.transport.KrbTransport;
 import org.apache.kerby.kerberos.kerb.admin.tool.AdminReq;
 
 public class AdminRequest {
     private String principal;
+    //private KOptions kOptions;
     private KrbTransport transport;
     private AdminReq adminReq;
 
-    private AdminContext context;
+    //private AdminContext context;
 
-    public AdminRequest(AdminContext context) {
-        this.context = context;
-    }
+    //public AdminRequest(AdminContext context) {
+        //this.context = context;
+    //}
 
     public AdminRequest(String principal) {
         this.principal = principal;
     }
 
-    public AdminContext getContext() {
-        return context;
-    }
+    //public AdminRequest(String principal, KOptions kOptions) {
+        // this.principal = principal;
+        //this.kOptions = kOptions;
+    //}
 
-    public void setContext(AdminContext context) {
-        this.context = context;
-    }
 
     public String getPrincipal() {
         return principal;
@@ -64,7 +62,7 @@ public class AdminRequest {
     }
 
     public void process() throws KrbException {
-        //
+        //encoding and set adminReq
 
     }
 

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/c1e324d7/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/tool/AdminMessage.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/tool/AdminMessage.java
b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/tool/AdminMessage.java
index 473437d..d83631b 100644
--- a/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/tool/AdminMessage.java
+++ b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/tool/AdminMessage.java
@@ -23,6 +23,10 @@ import java.nio.ByteBuffer;
 
 /**
  * Deal with messages sent and received between Kadmin and Kadmin Server.
+ *       (MSB)                   (LSB)
+ *      +-------+-------+-------+-------+
+ *      |msg_type |para_num |prin_name |...(koptions, password) |
+ *      +-------+-------+-------+-------+
  */
 public class AdminMessage {
     private AdminMessageType adminMessageType;

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/c1e324d7/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/tool/AdminMessageCode.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/tool/AdminMessageCode.java
b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/tool/AdminMessageCode.java
new file mode 100644
index 0000000..98c0482
--- /dev/null
+++ b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/tool/AdminMessageCode.java
@@ -0,0 +1,91 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.kerby.kerberos.kerb.admin.tool;
+
+import org.apache.kerby.KOptions;
+import org.apache.kerby.xdr.XdrDataType;
+import org.apache.kerby.xdr.XdrFieldInfo;
+import org.apache.kerby.xdr.type.*;
+
+/**
+ * An extend XdrStructType to encode and decode AdminMessage.
+ */
+public class AdminMessageCode extends XdrStructType {
+    public AdminMessageCode() {
+        super(XdrDataType.STRUCT);
+    }
+
+    public AdminMessageCode(XdrFieldInfo[] fieldInfos) {
+        super(XdrDataType.STRUCT, fieldInfos);
+    }
+
+    protected  void getStructTypeInstance(final XdrType[] fields, final XdrFieldInfo[] fieldInfos)
{
+        for (int i = 0; i < fieldInfos.length; i++) {
+            switch (fieldInfos[i].getDataType()) {
+                case INTEGER:
+                    fields[i] = new XdrInteger((Integer) fieldInfos[i].getValue());
+                    break;
+                case ENUM:
+                    fields[i] = new AdminMessageEnum((AdminMessageType) fieldInfos[i].getValue());
+                    break;
+                case STRING:
+                    fields[i] = new XdrString((String) fieldInfos[i].getValue());
+                    break;
+                default:
+                    fields[i] = null;
+            }
+
+        }
+    }
+
+    @Override
+    protected XdrStructType fieldsToValues(AbstractXdrType[] fields) {
+        int paramNum = (int) fields[1].getValue();
+        XdrFieldInfo[] xdrFieldInfos = new XdrFieldInfo[paramNum + 2];
+        xdrFieldInfos[0] = new XdrFieldInfo(0, XdrDataType.ENUM, fields[0].getValue());
+        xdrFieldInfos[1] = new XdrFieldInfo(1, XdrDataType.INTEGER, fields[1].getValue());
+        xdrFieldInfos[2] = new XdrFieldInfo(2, XdrDataType.STRING, fields[2].getValue());
+        if (paramNum == 2 && fields[3].getValue() instanceof KOptions) {
+            xdrFieldInfos[3] = new XdrFieldInfo(3, XdrDataType.STRUCT, fields[3].getValue());
/////koption
+        } else if (paramNum == 2 && fields[3].getValue() instanceof String) {
+            xdrFieldInfos[3] = new XdrFieldInfo(3, XdrDataType.STRING, fields[3].getValue());
+        } else if (paramNum == 3) {
+            xdrFieldInfos[3] = new XdrFieldInfo(3, XdrDataType.STRUCT, fields[3].getValue());
////koption
+            xdrFieldInfos[4] = new XdrFieldInfo(4, XdrDataType.STRING, fields[4].getValue());
+        }
+        return new AdminMessageCode(xdrFieldInfos);
+    }
+
+    @Override
+    protected AbstractXdrType[] getAllFields() {
+        AbstractXdrType[] fields = new AbstractXdrType[3];
+        fields[0] = new AdminMessageEnum();
+        fields[1] = new XdrInteger();
+        fields[2] = new XdrString();
+        //fields3,4
+        return fields;
+    }
+
+
+
+
+
+
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/c1e324d7/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/tool/AdminMessageEnum.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/tool/AdminMessageEnum.java
b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/tool/AdminMessageEnum.java
new file mode 100644
index 0000000..286b508
--- /dev/null
+++ b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/tool/AdminMessageEnum.java
@@ -0,0 +1,43 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.kerby.kerberos.kerb.admin.tool;
+
+import org.apache.kerby.xdr.EnumType;
+import org.apache.kerby.xdr.type.XdrEnumerated;
+
+/**
+ * An extend XdrEnumerate to encode and decode AdminMessageType.
+ */
+public class AdminMessageEnum extends XdrEnumerated<AdminMessageType> {
+    public AdminMessageEnum() {
+        super(null);
+    }
+
+    public AdminMessageEnum(AdminMessageType value) {
+        super(value);
+    }
+    @Override
+    protected EnumType[] getAllEnumValues() {
+        return AdminMessageType.values();
+    }
+
+
+
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/c1e324d7/kerby-kerb/kerb-admin/src/test/java/org/apache/kerby/kerberos/kerb/admin/admin/AdminTest.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-admin/src/test/java/org/apache/kerby/kerberos/kerb/admin/admin/AdminTest.java
b/kerby-kerb/kerb-admin/src/test/java/org/apache/kerby/kerberos/kerb/admin/admin/AdminTest.java
index 7e46620..56a061d 100644
--- a/kerby-kerb/kerb-admin/src/test/java/org/apache/kerby/kerberos/kerb/admin/admin/AdminTest.java
+++ b/kerby-kerb/kerb-admin/src/test/java/org/apache/kerby/kerberos/kerb/admin/admin/AdminTest.java
@@ -25,9 +25,9 @@ import org.junit.Test;
 
 public class AdminTest {
     private final String kdcRealm = "TEST.COM";
-    private final String clientPrincipalName = "alice";
-    private final String clientPrincipal =
-            clientPrincipalName + "@" + kdcRealm;
+    //private final String clientPrincipalName = "alice";
+    //private final String clientPrincipal =
+            //clientPrincipalName + "@" + kdcRealm;
     private AdminClient adminClient;
 
     @Test
@@ -37,7 +37,7 @@ public class AdminTest {
         adminClient.setAllowTcp(true);
         adminClient.setAllowUdp(false);
         adminClient.setAdminTcpPort(65417);
-        adminClient.init();
-        adminClient.requestAddPrincial(clientPrincipal);
+        /*adminClient.init();
+        adminClient.requestAddPrincial(clientPrincipal);*/
     }
 }


Mime
View raw message