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-580 Implement list_principals in Remote Kadmin. Contributed by Qing.
Date Fri, 17 Jun 2016 06:22:56 GMT
Repository: directory-kerby
Updated Branches:
  refs/heads/kadmin-remote 0d5a21926 -> 5775c4913


DIRKRB-580 Implement list_principals in Remote Kadmin. Contributed by Qing.


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

Branch: refs/heads/kadmin-remote
Commit: 5775c4913c5369e29878de8df53808012415d8c0
Parents: 0d5a219
Author: plusplusjiajia <jiajia.li@intel.com>
Authored: Fri Jun 17 14:27:27 2016 +0800
Committer: plusplusjiajia <jiajia.li@intel.com>
Committed: Fri Jun 17 14:27:27 2016 +0800

----------------------------------------------------------------------
 .../admin/server/kadmin/AdminServerHandler.java | 131 ++++++++++---------
 .../kerberos/kerb/admin/RemoteAdminTool.java    |  14 +-
 .../kerb/admin/kadmin/remote/AdminClient.java   |  13 ++
 .../kerb/admin/kadmin/remote/AdminHandler.java  |  35 +++++
 .../admin/kadmin/remote/RemoteKadminImpl.java   |  17 ++-
 .../remote/command/RemoteGetprincsCommand.java  |  65 +++++++++
 .../remote/command/RemotePrintUsageCommand.java |  42 ++++++
 .../kadmin/remote/impl/DefaultAdminHandler.java |  19 +++
 .../kadmin/remote/request/GetprincsRequest.java |  72 ++++++++++
 .../kerb/admin/tool/AdminMessageType.java       |   4 +-
 .../kerberos/kerb/admin/tool/GetprincsRep.java  |  26 ++++
 .../kerberos/kerb/admin/tool/GetprincsReq.java  |  26 ++++
 12 files changed, 394 insertions(+), 70 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/5775c491/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 1032644..de915f6 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
@@ -32,6 +32,7 @@ import org.slf4j.LoggerFactory;
 import java.io.IOException;
 import java.net.InetAddress;
 import java.nio.ByteBuffer;
+import java.util.List;
 
 /**
  * KDC handler to process client requests. Currently only one realm is supported.
@@ -82,6 +83,10 @@ public class AdminServerHandler {
                 System.out.println("message type: rename principal req");
                 responseMessage = handleRenamePrincipalReq(localKadmin, fieldInfos);
                 break;
+            case GET_PRINCS_REQ:
+                System.out.println("message type getPrincs req");
+                responseMessage = handleGetprincsReq(localKadmin, fieldInfos);
+                break;
             default:
                 throw new KrbException("AdminMessageType error, can not handle it.");
         }
@@ -103,14 +108,7 @@ public class AdminServerHandler {
                 String error = "principal already exist!";
                 LOG.error(error);
                 System.err.println(error);
-                XdrFieldInfo[] xdrFieldInfos = new XdrFieldInfo[3];
-                xdrFieldInfos[0] = new XdrFieldInfo(0, XdrDataType.ENUM, AdminMessageType.ADD_PRINCIPAL_REP);
-                xdrFieldInfos[1] = new XdrFieldInfo(1, XdrDataType.INTEGER, 1);
-                xdrFieldInfos[2] = new XdrFieldInfo(2, XdrDataType.STRING, error);
-                AdminMessageCode value = new AdminMessageCode(xdrFieldInfos);
-                AdminMessage errorMessage = new AddPrincipalRep();
-                errorMessage.setMessageBuffer(ByteBuffer.wrap(value.encode()));
-                ByteBuffer response = KadminCode.encodeMessage(errorMessage);
+                ByteBuffer response = infoPackageTool(error, "addPrincipal");
                 return response;
             }
         } else if (paramNum == 2 && fieldInfos[3].getDataType() == XdrDataType.STRING)
{
@@ -122,35 +120,15 @@ public class AdminServerHandler {
                 localKadmin.addPrincipal(temp[0], password);
             } catch (KrbException e) {
                 String error = "principal already exist.\n"
-                    + "Choose update password instead of add principal";
+                        + "Choose update password instead of add principal";
                 LOG.error(error);
-                XdrFieldInfo[] xdrFieldInfos = new XdrFieldInfo[3];
-                xdrFieldInfos[0] = new XdrFieldInfo(0, XdrDataType.ENUM, AdminMessageType.ADD_PRINCIPAL_REP);
-                xdrFieldInfos[1] = new XdrFieldInfo(1, XdrDataType.INTEGER, 1);
-                xdrFieldInfos[2] = new XdrFieldInfo(2, XdrDataType.STRING, error);
-                AdminMessageCode value = new AdminMessageCode(xdrFieldInfos);
-                AdminMessage errorMessage = new AddPrincipalRep();
-                errorMessage.setMessageBuffer(ByteBuffer.wrap(value.encode()));
-                ByteBuffer response = KadminCode.encodeMessage(errorMessage);
+                ByteBuffer response = infoPackageTool(error, "addPrincipal");
                 return response;
             }
         }
-
         String message = "add principal of " + principal;
         LOG.info(message);
-        //content to reply remain to construct
-        AdminMessage addPrincipalRep = new AddPrincipalRep();
-        /** encode admin message:
-         *  encode type
-         *  encode message
-         */
-        XdrFieldInfo[] xdrFieldInfos = new XdrFieldInfo[3];
-        xdrFieldInfos[0] = new XdrFieldInfo(0, XdrDataType.ENUM, AdminMessageType.ADD_PRINCIPAL_REP);
-        xdrFieldInfos[1] = new XdrFieldInfo(1, XdrDataType.INTEGER, 1);
-        xdrFieldInfos[2] = new XdrFieldInfo(2, XdrDataType.STRING, message);
-        AdminMessageCode value = new AdminMessageCode(xdrFieldInfos);
-        addPrincipalRep.setMessageBuffer(ByteBuffer.wrap(value.encode()));
-        ByteBuffer responseMessage = KadminCode.encodeMessage(addPrincipalRep);
+        ByteBuffer responseMessage = infoPackageTool(message, "addPrincipal");
         return responseMessage;
     }
 
@@ -163,27 +141,12 @@ public class AdminServerHandler {
         } catch (KrbException e) {
             String error = "no such principal exist!";
             LOG.error(error);
-            XdrFieldInfo[] xdrFieldInfos = new XdrFieldInfo[3];
-            xdrFieldInfos[0] = new XdrFieldInfo(0, XdrDataType.ENUM, AdminMessageType.DELETE_PRINCIPAL_REP);
-            xdrFieldInfos[1] = new XdrFieldInfo(1, XdrDataType.INTEGER, 1);
-            xdrFieldInfos[2] = new XdrFieldInfo(2, XdrDataType.STRING, error);
-            AdminMessageCode value = new AdminMessageCode(xdrFieldInfos);
-            AdminMessage errorMessage = new DeletePrincipalRep();
-            errorMessage.setMessageBuffer(ByteBuffer.wrap(value.encode()));
-            ByteBuffer response = KadminCode.encodeMessage(errorMessage);
+            ByteBuffer response = infoPackageTool(error, "deletePrincipal");
             return response;
         }
-
         String message = "delete principal of " + principal;
         LOG.info(message);
-        AdminMessage deletePrincipalRep = new DeletePrincipalRep();
-        XdrFieldInfo[] xdrFieldInfos = new XdrFieldInfo[3];
-        xdrFieldInfos[0] = new XdrFieldInfo(0, XdrDataType.ENUM, AdminMessageType.DELETE_PRINCIPAL_REP);
-        xdrFieldInfos[1] = new XdrFieldInfo(1, XdrDataType.INTEGER, 1);
-        xdrFieldInfos[2] = new XdrFieldInfo(2, XdrDataType.STRING, message);
-        AdminMessageCode value = new AdminMessageCode(xdrFieldInfos);
-        deletePrincipalRep.setMessageBuffer(ByteBuffer.wrap(value.encode()));
-        ByteBuffer responseMessage = KadminCode.encodeMessage(deletePrincipalRep);
+        ByteBuffer responseMessage = infoPackageTool(message, "deletePrincipal");
         return responseMessage;
     }
 
@@ -192,33 +155,77 @@ public class AdminServerHandler {
 
         String[] oldPrincipalName = ((String) fieldInfos[2].getValue()).split("@");
         String[] newPrincipalName = ((String) fieldInfos[3].getValue()).split("@");
-
         try {
             localKadmin.renamePrincipal(oldPrincipalName[0], newPrincipalName[0]);
         } catch (KrbException e) {
             String error = "the old principal name does not exist, or the new principal name"
-                + " already exists, rename failed.";
+                    + " already exists, rename failed.";
             System.err.println(error);
-            XdrFieldInfo[] xdrFieldInfos = new XdrFieldInfo[3];
-            xdrFieldInfos[0] = new XdrFieldInfo(0, XdrDataType.ENUM, AdminMessageType.RENAME_PRINCIPAL_REP);
-            xdrFieldInfos[1] = new XdrFieldInfo(1, XdrDataType.INTEGER, 1);
-            xdrFieldInfos[2] = new XdrFieldInfo(2, XdrDataType.STRING, error);
-            AdminMessageCode value = new AdminMessageCode(xdrFieldInfos);
-            AdminMessage errorMessage = new RenamePrincipalRep();
-            errorMessage.setMessageBuffer(ByteBuffer.wrap(value.encode()));
-            ByteBuffer response = KadminCode.encodeMessage(errorMessage);
+            ByteBuffer response = infoPackageTool(error, "renamePrincipal");
             return response;
         }
 
         String message = "rename " + oldPrincipalName[0] + " to " + newPrincipalName[0];
-        AdminMessage renamePrincipalRep = new RenamePrincipalRep();
+        ByteBuffer responseMessage = infoPackageTool(message, "renamePrincipal");
+        return responseMessage;
+    }
+
+    private ByteBuffer handleGetprincsReq(LocalKadmin localKadmin, XdrFieldInfo[] fieldInfos)
throws IOException {
+        String globString = ((String) fieldInfos[2].getValue());
+        List<String> princsList = null;
+
+        try {
+            if (globString == null || globString.isEmpty()) {
+                princsList = localKadmin.getPrincipals();
+            } else {
+                princsList = localKadmin.getPrincipals(globString);
+            }
+            ByteBuffer responseMessage = infoPackageTool(listToString(princsList), "getPrincs");
+            return responseMessage;
+        } catch (KrbException e) {
+            String error = "principal do not exist.";
+            ByteBuffer responseError = infoPackageTool(error, "getPrincs");
+            return responseError;
+        }
+    }
+
+    private ByteBuffer infoPackageTool(String message, String dealType) throws IOException
{
+        AdminMessage adminMessage = null;
         XdrFieldInfo[] xdrFieldInfos = new XdrFieldInfo[3];
-        xdrFieldInfos[0] = new XdrFieldInfo(0, XdrDataType.ENUM, AdminMessageType.RENAME_PRINCIPAL_REP);
+
+        if ("getPrincs".equals(dealType)) {
+            adminMessage = new GetprincsRep();
+            xdrFieldInfos[0] = new XdrFieldInfo(0, XdrDataType.ENUM, AdminMessageType.GET_PRINCS_REP);
+        } else if ("renamePrincipal".equals(dealType)) {
+            adminMessage = new RenamePrincipalRep();
+            xdrFieldInfos[0] = new XdrFieldInfo(0, XdrDataType.ENUM, AdminMessageType.RENAME_PRINCIPAL_REP);
+        } else if ("deletePrincipal".equals(dealType)) {
+            adminMessage = new DeletePrincipalRep();
+            xdrFieldInfos[0] = new XdrFieldInfo(0, XdrDataType.ENUM, AdminMessageType.DELETE_PRINCIPAL_REP);
+        } else if ("addPrincipal".equals(dealType)) {
+            adminMessage = new AddPrincipalRep();
+            xdrFieldInfos[0] = new XdrFieldInfo(0, XdrDataType.ENUM, AdminMessageType.ADD_PRINCIPAL_REP);
+        }
+
         xdrFieldInfos[1] = new XdrFieldInfo(1, XdrDataType.INTEGER, 1);
         xdrFieldInfos[2] = new XdrFieldInfo(2, XdrDataType.STRING, message);
+
         AdminMessageCode value = new AdminMessageCode(xdrFieldInfos);
-        renamePrincipalRep.setMessageBuffer(ByteBuffer.wrap(value.encode()));
-        ByteBuffer responseMessage = KadminCode.encodeMessage(renamePrincipalRep);
+        adminMessage.setMessageBuffer(ByteBuffer.wrap(value.encode()));
+
+        ByteBuffer responseMessage = KadminCode.encodeMessage(adminMessage);
         return responseMessage;
     }
+
+    private String listToString(List<String> list) {
+        if (list.size() <= 0) {
+            return null;
+        }
+        //Both speed and safety,so use StringBuffer
+        StringBuffer result = new StringBuffer();
+        for (int i = 0; i < list.size(); i++) {
+            result.append(list.get(i)).append(" ");
+        }
+        return result.toString();
+    }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/5775c491/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/RemoteAdminTool.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/RemoteAdminTool.java
b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/RemoteAdminTool.java
index fbeda4a..7d26534 100644
--- a/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/RemoteAdminTool.java
+++ b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/RemoteAdminTool.java
@@ -22,11 +22,13 @@ package org.apache.kerby.kerberos.kerb.admin;
 import org.apache.kerby.kerberos.kerb.KrbException;
 import org.apache.kerby.kerberos.kerb.admin.kadmin.remote.AdminClient;
 import org.apache.kerby.kerberos.kerb.admin.kadmin.remote.AdminConfig;
+import org.apache.kerby.util.OSUtil;
 import org.apache.kerby.kerberos.kerb.admin.kadmin.remote.command.RemoteAddPrincipalCommand;
 import org.apache.kerby.kerberos.kerb.admin.kadmin.remote.command.RemoteCommand;
 import org.apache.kerby.kerberos.kerb.admin.kadmin.remote.command.RemoteDeletePrincipalCommand;
 import org.apache.kerby.kerberos.kerb.admin.kadmin.remote.command.RemoteRenamePrincipalCommand;
-import org.apache.kerby.util.OSUtil;
+import org.apache.kerby.kerberos.kerb.admin.kadmin.remote.command.RemoteGetprincsCommand;
+import org.apache.kerby.kerberos.kerb.admin.kadmin.remote.command.RemotePrintUsageCommand;
 
 import java.io.File;
 import java.util.Scanner;
@@ -35,6 +37,7 @@ import java.util.Scanner;
  * Command use of remote admin
  */
 public class RemoteAdminTool {
+    private static final String PROMPT = RemoteAdminTool.class.getSimpleName() + ".local:";
     private static final String USAGE = (OSUtil.isWindows()
         ? "Usage: bin\\remoteAdmin.cmd" : "Usage: sh bin/remoteAdmin.sh")
         + " <conf-file>\n"
@@ -51,7 +54,9 @@ public class RemoteAdminTool {
         + "delete_principal, delprinc\n"
         + "                         Delete principal\n"
         + "rename_principal, renprinc\n"
-        + "                         Rename principal\n";
+        + "                         Rename principal\n"
+        + "listprincs\n"
+        + "          List principals\n";
 
     public static void main(String[] args) throws Exception {
         AdminClient adminClient;
@@ -87,6 +92,7 @@ public class RemoteAdminTool {
 
             while (!(input.equals("quit") || input.equals("exit") || input.equals("q")))
{
                 excute(adminClient, input);
+                System.out.print(PROMPT);
                 input = scanner.nextLine();
             }
         }
@@ -111,6 +117,10 @@ public class RemoteAdminTool {
         } else if (input.startsWith("rename_principal")
             || input.startsWith("renprinc")) {
             executor = new RemoteRenamePrincipalCommand(adminClient);
+        } else if (input.startsWith("list_principals")) {
+            executor = new RemoteGetprincsCommand(adminClient);
+        } else if (input.startsWith("listprincs")) {
+            executor = new RemotePrintUsageCommand();
         } else {
             System.out.println(LEGAL_COMMANDS);
             return;

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/5775c491/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/AdminClient.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/AdminClient.java
b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/AdminClient.java
index f482262..86faa65 100644
--- a/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/AdminClient.java
+++ b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/AdminClient.java
@@ -26,6 +26,7 @@ import org.apache.kerby.kerberos.kerb.admin.kadmin.remote.impl.DefaultInternalAd
 import org.apache.kerby.kerberos.kerb.admin.kadmin.remote.impl.InternalAdminClient;
 
 import java.io.File;
+import java.util.List;
 
 /**
  * A Krb client API for applications to interact with KDC
@@ -184,4 +185,16 @@ public class AdminClient {
         Kadmin remote = new RemoteKadminImpl(innerClient);
         remote.renamePrincipal(oldPrincipal, newPrincipal);
     }
+
+    public List<String> requestGetprincs() throws KrbException {
+        Kadmin remote = new RemoteKadminImpl(innerClient);
+        List<String> principalLists = remote.getPrincipals();
+        return principalLists;
+    }
+
+    public List<String> requestGetprincsWithExp(String exp) throws KrbException {
+        Kadmin remote = new RemoteKadminImpl(innerClient);
+        List<String> principalLists = remote.getPrincipals(exp);
+        return principalLists;
+    }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/5775c491/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 0a64914..0db757c 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
@@ -30,6 +30,8 @@ import org.apache.kerby.xdr.type.XdrStructType;
 
 import java.io.IOException;
 import java.nio.ByteBuffer;
+import java.util.Arrays;
+import java.util.List;
 
 public abstract class AdminHandler {
 
@@ -115,6 +117,37 @@ public abstract class AdminHandler {
         }
     }
 
+    public List<String> onResponseMessageForList(AdminRequest adminRequest,
+                                  ByteBuffer responseMessage) throws KrbException {
+        List<String> princalsList = null;
+
+        XdrStructType decoded = new AdminMessageCode();
+        try {
+            decoded.decode(responseMessage);
+        } catch (IOException e) {
+            throw new KrbException("On response message failed.", e);
+        }
+        XdrFieldInfo[] fieldInfos = decoded.getValue().getXdrFieldInfos();
+        AdminMessageType type = (AdminMessageType) fieldInfos[0].getValue();
+
+        switch (type) {
+            case GET_PRINCS_REP:
+                if (adminRequest.getAdminReq().getAdminMessageType()
+                        == AdminMessageType.GET_PRINCS_REQ) {
+                    String[] temp = ((String) fieldInfos[2].getValue()).trim().split(" ");
+                    princalsList = Arrays.asList(temp);
+                } else {
+                    throw new KrbException("Response message type error: need "
+                            + AdminMessageType.GET_PRINCS_REP);
+                }
+                break;
+            default:
+                throw new KrbException("Response message type error: " + type);
+        }
+
+        return princalsList;
+    }
+
     /**
      * Send message to kdc.
      *
@@ -124,4 +157,6 @@ public abstract class AdminHandler {
      */
     protected abstract void sendMessage(AdminRequest adminRequest,
                                         ByteBuffer requestMessage) throws IOException;
+
+    protected abstract List<String> handleRequestForList(AdminRequest adminRequest)
throws KrbException;
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/5775c491/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 915287e..fc9af6b 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
@@ -24,13 +24,14 @@ import org.apache.kerby.kerberos.kerb.KrbException;
 import org.apache.kerby.kerberos.kerb.admin.kadmin.Kadmin;
 import org.apache.kerby.kerberos.kerb.admin.kadmin.remote.impl.DefaultAdminHandler;
 import org.apache.kerby.kerberos.kerb.admin.kadmin.remote.impl.InternalAdminClient;
+import org.apache.kerby.kerberos.kerb.transport.KrbNetwork;
+import org.apache.kerby.kerberos.kerb.transport.KrbTransport;
+import org.apache.kerby.kerberos.kerb.transport.TransportPair;
 import org.apache.kerby.kerberos.kerb.admin.kadmin.remote.request.AddPrincipalRequest;
 import org.apache.kerby.kerberos.kerb.admin.kadmin.remote.request.AdminRequest;
 import org.apache.kerby.kerberos.kerb.admin.kadmin.remote.request.DeletePrincipalRequest;
 import org.apache.kerby.kerberos.kerb.admin.kadmin.remote.request.RenamePrincipalRequest;
-import org.apache.kerby.kerberos.kerb.transport.KrbNetwork;
-import org.apache.kerby.kerberos.kerb.transport.KrbTransport;
-import org.apache.kerby.kerberos.kerb.transport.TransportPair;
+import org.apache.kerby.kerberos.kerb.admin.kadmin.remote.request.GetprincsRequest;
 
 import java.io.File;
 import java.io.IOException;
@@ -174,12 +175,18 @@ public class RemoteKadminImpl implements Kadmin {
 
     @Override
     public List<String> getPrincipals() throws KrbException {
-        return null;
+        AdminRequest grtPrincsRequest = new GetprincsRequest();
+        grtPrincsRequest.setTransport(transport);
+        AdminHandler adminHandler = new DefaultAdminHandler();
+        return adminHandler.handleRequestForList(grtPrincsRequest);
     }
 
     @Override
     public List<String> getPrincipals(String globString) throws KrbException {
-        return null;
+        AdminRequest grtPrincsRequest = new GetprincsRequest(globString);
+        grtPrincsRequest.setTransport(transport);
+        AdminHandler adminHandler = new DefaultAdminHandler();
+        return adminHandler.handleRequestForList(grtPrincsRequest);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/5775c491/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/command/RemoteGetprincsCommand.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/command/RemoteGetprincsCommand.java
b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/command/RemoteGetprincsCommand.java
new file mode 100644
index 0000000..2e15281
--- /dev/null
+++ b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/command/RemoteGetprincsCommand.java
@@ -0,0 +1,65 @@
+/**
+ *  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.kadmin.remote.command;
+
+import org.apache.kerby.kerberos.kerb.KrbException;
+import org.apache.kerby.kerberos.kerb.admin.kadmin.remote.AdminClient;
+import java.util.List;
+
+public class RemoteGetprincsCommand extends RemoteCommand {
+    private static final String USAGE = "Usage: list_principals [expression]\n"
+            + "\t'expression' is a shell-style glob expression that can contain the wild-card
characters ?, *, and []."
+            + "\tExample:\n"
+            + "\t\tlist_principals [expression]\n";
+
+    public RemoteGetprincsCommand(AdminClient adminClient) {
+        super(adminClient);
+    }
+
+    @Override
+    public void execute(String input) throws KrbException {
+        String[] items = input.split("\\s+");
+        //String param = items[0];
+        if (items.length > 2) {
+            System.err.println(USAGE);
+            return;
+        }
+
+        List<String> principalLists = null;
+
+        if (items.length == 1) {
+            principalLists = adminClient.requestGetprincs();
+        } else {
+            //have expression
+            String exp = items[1];
+            principalLists = adminClient.requestGetprincsWithExp(exp);
+        }
+
+        if (principalLists.size() == 0 || principalLists.size() == 1 && principalLists.get(0).isEmpty())
{
+            return;
+        } else {
+            System.out.println("Principals are listed:");
+            for (int i = 0; i < principalLists.size(); i++) {
+                System.out.println(principalLists.get(i));
+            }
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/5775c491/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/command/RemotePrintUsageCommand.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/command/RemotePrintUsageCommand.java
b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/command/RemotePrintUsageCommand.java
new file mode 100644
index 0000000..a27e252
--- /dev/null
+++ b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/command/RemotePrintUsageCommand.java
@@ -0,0 +1,42 @@
+/**
+ *  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.kadmin.remote.command;
+
+import org.apache.kerby.kerberos.kerb.KrbException;
+
+public class RemotePrintUsageCommand extends RemoteCommand {
+
+    private static final String LISTPRINCSUSAGE = "Usage: list_principals [expression]\n"
+            + "\t'expression' is a shell-style glob expression that can contain "
+            + "the wild-card characters ?, *, and [].\n"
+            + "\tExample:\n"
+            + "\t\tlist_principals [expression]\n";
+
+    public RemotePrintUsageCommand() {
+        super(null);
+    }
+
+    @Override
+    public void execute(String input) throws KrbException {
+        if (input.startsWith("listprincs")) {
+            System.out.println(LISTPRINCSUSAGE);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/5775c491/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 d0e1d07..3d05b50 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
@@ -26,6 +26,7 @@ import org.apache.kerby.kerberos.kerb.transport.KrbTransport;
 
 import java.io.IOException;
 import java.nio.ByteBuffer;
+import java.util.List;
 
 public class DefaultAdminHandler extends AdminHandler {
 
@@ -57,4 +58,22 @@ public class DefaultAdminHandler extends AdminHandler {
         KrbTransport transport = adminRequest.getTransport();
         transport.sendMessage(requestMessage);
     }
+
+    @Override
+    public List<String> handleRequestForList(AdminRequest adminRequest) throws KrbException
{
+        /**send message*/
+        super.handleRequest(adminRequest);
+
+        KrbTransport transport = adminRequest.getTransport();
+        ByteBuffer receiveMessage = null;
+        List<String> prinicalList = null;
+        try {
+            receiveMessage = transport.receiveMessage();
+            prinicalList = super.onResponseMessageForList(adminRequest, receiveMessage);
+        } catch (IOException e) {
+            throw new KrbException("Admin receives response message failed", e);
+        }
+
+        return prinicalList;
+    }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/5775c491/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/request/GetprincsRequest.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/request/GetprincsRequest.java
b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/request/GetprincsRequest.java
new file mode 100644
index 0000000..e582b15
--- /dev/null
+++ b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kadmin/remote/request/GetprincsRequest.java
@@ -0,0 +1,72 @@
+/**
+ *  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.kadmin.remote.request;
+
+import org.apache.kerby.kerberos.kerb.KrbException;
+import org.apache.kerby.kerberos.kerb.admin.tool.AdminMessageCode;
+import org.apache.kerby.kerberos.kerb.admin.tool.AdminMessageType;
+import org.apache.kerby.kerberos.kerb.admin.tool.GetprincsReq;
+import org.apache.kerby.xdr.XdrDataType;
+import org.apache.kerby.xdr.XdrFieldInfo;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+/**
+ * Created by root on 6/3/16.
+ */
+public class GetprincsRequest extends AdminRequest {
+    private String globString = null;
+
+    public GetprincsRequest() {
+        super(null);
+    }
+
+    public GetprincsRequest(String globString) {
+        super(null);
+        this.globString = globString;
+    }
+
+    @Override
+    public void process() throws KrbException {
+        //encoding and set adminReq
+
+        GetprincsReq getprincsReq = new GetprincsReq();
+
+        XdrFieldInfo[] xdrFieldInfos = new XdrFieldInfo[3];
+        xdrFieldInfos[0] = new XdrFieldInfo(0, XdrDataType.ENUM, AdminMessageType.GET_PRINCS_REQ);
+        xdrFieldInfos[1] = new XdrFieldInfo(1, XdrDataType.INTEGER, 2);
+        xdrFieldInfos[2] = new XdrFieldInfo(2, XdrDataType.STRING, globString);
+
+        AdminMessageCode value = new AdminMessageCode(xdrFieldInfos);
+        byte[] encodeBytes;
+        try {
+            encodeBytes = value.encode();
+        } catch (IOException e) {
+            throw new KrbException("Xdr encode error when generate get principals request.",
e);
+        }
+        ByteBuffer messageBuffer = ByteBuffer.wrap(encodeBytes);
+        getprincsReq.setMessageBuffer(messageBuffer);
+
+        setAdminReq(getprincsReq);
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/5775c491/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/tool/AdminMessageType.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/tool/AdminMessageType.java
b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/tool/AdminMessageType.java
index 5630d13..66f4f1a 100644
--- a/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/tool/AdminMessageType.java
+++ b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/tool/AdminMessageType.java
@@ -40,7 +40,9 @@ public enum AdminMessageType implements EnumType {
     DELETE_PRINCIPAL_REQ(2),
     DELETE_PRINCIPAL_REP(3),
     RENAME_PRINCIPAL_REQ(4),
-    RENAME_PRINCIPAL_REP(5);
+    RENAME_PRINCIPAL_REP(5),
+    GET_PRINCS_REQ(6),
+    GET_PRINCS_REP(7);
 
     private int value;
 

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/5775c491/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/tool/GetprincsRep.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/tool/GetprincsRep.java
b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/tool/GetprincsRep.java
new file mode 100644
index 0000000..e9d8d39
--- /dev/null
+++ b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/tool/GetprincsRep.java
@@ -0,0 +1,26 @@
+/**
+ *  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;
+
+public class GetprincsRep extends AdminRep {
+    public GetprincsRep() {
+        super(AdminMessageType.GET_PRINCS_REP);
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/5775c491/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/tool/GetprincsReq.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/tool/GetprincsReq.java
b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/tool/GetprincsReq.java
new file mode 100644
index 0000000..b985f6a
--- /dev/null
+++ b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/tool/GetprincsReq.java
@@ -0,0 +1,26 @@
+/**
+ *  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;
+
+public class GetprincsReq extends AdminReq {
+    public GetprincsReq() {
+        super(AdminMessageType.GET_PRINCS_REQ);
+    }
+}


Mime
View raw message