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-578 Set up network connection between Kpasswd Server and Client. Contributed by Yan.
Date Mon, 06 Jun 2016 02:10:56 GMT
Repository: directory-kerby
Updated Branches:
  refs/heads/kadmin-remote 946948080 -> 2cb5c16f5


DIRKRB-578 Set up network connection between Kpasswd Server and Client. 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/2cb5c16f
Tree: http://git-wip-us.apache.org/repos/asf/directory-kerby/tree/2cb5c16f
Diff: http://git-wip-us.apache.org/repos/asf/directory-kerby/diff/2cb5c16f

Branch: refs/heads/kadmin-remote
Commit: 2cb5c16f55b8668d686e1a00dff43aa5f24812e1
Parents: 9469480
Author: plusplusjiajia <jiajia.li@intel.com>
Authored: Mon Jun 6 10:16:31 2016 +0800
Committer: plusplusjiajia <jiajia.li@intel.com>
Committed: Mon Jun 6 10:16:31 2016 +0800

----------------------------------------------------------------------
 kerby-dist/kdc-dist/bin/kpasswdClient.cmd       | 32 +++++++
 kerby-dist/kdc-dist/bin/kpasswdClient.sh        | 32 +++++++
 kerby-dist/kdc-dist/bin/kpasswdServer.cmd       | 32 +++++++
 kerby-dist/kdc-dist/bin/kpasswdServer.sh        | 32 +++++++
 kerby-dist/kdc-dist/conf/kpasswdClient.conf     | 20 +++++
 kerby-dist/kdc-dist/conf/kpasswdServer.conf     | 20 +++++
 .../kerb/admin/server/PasswdServerInit.java     | 71 ++++++++++++++++
 .../server/kpasswd/PasswdServerHandler.java     | 77 ++---------------
 .../admin/server/kpasswd/PasswdServerUtil.java  |  2 +-
 .../kerberos/kerb/admin/PasswdClientTool.java   | 88 ++++++++++++++++++++
 .../kerb/admin/kpasswd/PasswdConfigKey.java     |  4 +-
 .../kerb/admin/kpasswd/PasswdHandler.java       | 42 ++++------
 .../kerberos/kerb/admin/kpasswd/PasswdUtil.java |  2 +-
 .../kpasswd/impl/DefaultPasswdHandler.java      | 27 +++---
 .../admin/kpasswd/request/PasswdRequest.java    | 20 ++---
 15 files changed, 376 insertions(+), 125 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/2cb5c16f/kerby-dist/kdc-dist/bin/kpasswdClient.cmd
----------------------------------------------------------------------
diff --git a/kerby-dist/kdc-dist/bin/kpasswdClient.cmd b/kerby-dist/kdc-dist/bin/kpasswdClient.cmd
new file mode 100644
index 0000000..0ecd815
--- /dev/null
+++ b/kerby-dist/kdc-dist/bin/kpasswdClient.cmd
@@ -0,0 +1,32 @@
+@echo off
+@rem  Licensed to the Apache Software Foundation (ASF) under one
+@rem  or more contributor license agreements.  See the NOTICE file
+@rem  distributed with this work for additional information
+@rem  regarding copyright ownership.  The ASF licenses this file
+@rem  to you under the Apache License, Version 2.0 (the
+@rem  "License"); you may not use this file except in compliance
+@rem  with the License.  You may obtain a copy of the License at
+@rem
+@rem    http://www.apache.org/licenses/LICENSE-2.0
+@rem
+@rem  Unless required by applicable law or agreed to in writing,
+@rem  software distributed under the License is distributed on an
+@rem  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+@rem  KIND, either express or implied.  See the License for the
+@rem  specific language governing permissions and limitations
+@rem  under the License.
+@rem
+
+set DEBUG=
+set args=%*
+for %%a in (%*) do (
+  if -D == %%a (
+    set DEBUG=-Xdebug -Xrunjdwp:transport=dt_socket,address=8011,server=y,suspend=n
+    set args=%args:-D=%
+  )
+)
+
+java %DEBUG% ^
+-classpath target\lib\* ^
+-DKERBY_LOGFILE=kpasswdClient ^
+org.apache.kerby.kerberos.kerb.admin.PasswdClientTool %args%
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/2cb5c16f/kerby-dist/kdc-dist/bin/kpasswdClient.sh
----------------------------------------------------------------------
diff --git a/kerby-dist/kdc-dist/bin/kpasswdClient.sh b/kerby-dist/kdc-dist/bin/kpasswdClient.sh
new file mode 100644
index 0000000..a59e3d6
--- /dev/null
+++ b/kerby-dist/kdc-dist/bin/kpasswdClient.sh
@@ -0,0 +1,32 @@
+#!/usr/bin/env bash
+
+# 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.
+
+DEBUG=
+args=
+for var in $*; do
+  if [ X"$var" = X"-D" ]; then
+    DEBUG="-Xdebug -Xrunjdwp:transport=dt_socket,address=8011,server=y,suspend=n"
+  else
+    args="$args $var"
+  fi
+done
+
+java $DEBUG \
+-classpath target/lib/*:. \
+-DKERBY_LOGFILE=kpasswdClient \
+org.apache.kerby.kerberos.kerb.admin.PasswdClientTool $args
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/2cb5c16f/kerby-dist/kdc-dist/bin/kpasswdServer.cmd
----------------------------------------------------------------------
diff --git a/kerby-dist/kdc-dist/bin/kpasswdServer.cmd b/kerby-dist/kdc-dist/bin/kpasswdServer.cmd
new file mode 100644
index 0000000..27e091a
--- /dev/null
+++ b/kerby-dist/kdc-dist/bin/kpasswdServer.cmd
@@ -0,0 +1,32 @@
+@echo off
+@rem  Licensed to the Apache Software Foundation (ASF) under one
+@rem  or more contributor license agreements.  See the NOTICE file
+@rem  distributed with this work for additional information
+@rem  regarding copyright ownership.  The ASF licenses this file
+@rem  to you under the Apache License, Version 2.0 (the
+@rem  "License"); you may not use this file except in compliance
+@rem  with the License.  You may obtain a copy of the License at
+@rem
+@rem    http://www.apache.org/licenses/LICENSE-2.0
+@rem
+@rem  Unless required by applicable law or agreed to in writing,
+@rem  software distributed under the License is distributed on an
+@rem  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+@rem  KIND, either express or implied.  See the License for the
+@rem  specific language governing permissions and limitations
+@rem  under the License.
+@rem
+
+set DEBUG=
+set args=%*
+for %%a in (%*) do (
+  if -D == %%a (
+    set DEBUG=-Xdebug -Xrunjdwp:transport=dt_socket,address=8010,server=y,suspend=n
+    set args=%args:-D=%
+  )
+)
+
+java %DEBUG% ^
+-classpath target\lib\* ^
+-DKERBY_LOGFILE=kpasswdServer ^
+org.apache.kerby.kerberos.kerb.admin.server.PasswdServerInit %args%

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/2cb5c16f/kerby-dist/kdc-dist/bin/kpasswdServer.sh
----------------------------------------------------------------------
diff --git a/kerby-dist/kdc-dist/bin/kpasswdServer.sh b/kerby-dist/kdc-dist/bin/kpasswdServer.sh
new file mode 100644
index 0000000..97feb41
--- /dev/null
+++ b/kerby-dist/kdc-dist/bin/kpasswdServer.sh
@@ -0,0 +1,32 @@
+#!/usr/bin/env bash
+
+# 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.
+
+DEBUG=
+args=
+for var in $*; do
+  if [ X"$var" = X"-D" ]; then
+    DEBUG="-Xdebug -Xrunjdwp:transport=dt_socket,address=8010,server=y,suspend=n"
+  else
+    args="$args $var"
+  fi
+done
+
+java $DEBUG \
+-classpath target/lib/*:. \
+-DKERBY_LOGFILE=kpasswdServer \
+org.apache.kerby.kerberos.kerb.admin.server.PasswdServerInit $args
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/2cb5c16f/kerby-dist/kdc-dist/conf/kpasswdClient.conf
----------------------------------------------------------------------
diff --git a/kerby-dist/kdc-dist/conf/kpasswdClient.conf b/kerby-dist/kdc-dist/conf/kpasswdClient.conf
new file mode 100644
index 0000000..ea59d8b
--- /dev/null
+++ b/kerby-dist/kdc-dist/conf/kpasswdClient.conf
@@ -0,0 +1,20 @@
+#
+# 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.
+#
+[libdefaults]
+default_realm = TEST.COM
+admin_port = 65418

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/2cb5c16f/kerby-dist/kdc-dist/conf/kpasswdServer.conf
----------------------------------------------------------------------
diff --git a/kerby-dist/kdc-dist/conf/kpasswdServer.conf b/kerby-dist/kdc-dist/conf/kpasswdServer.conf
new file mode 100644
index 0000000..ea59d8b
--- /dev/null
+++ b/kerby-dist/kdc-dist/conf/kpasswdServer.conf
@@ -0,0 +1,20 @@
+#
+# 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.
+#
+[libdefaults]
+default_realm = TEST.COM
+admin_port = 65418

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/2cb5c16f/kerby-kerb/kerb-admin-server/src/main/java/org/apache/kerby/kerberos/kerb/admin/server/PasswdServerInit.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-admin-server/src/main/java/org/apache/kerby/kerberos/kerb/admin/server/PasswdServerInit.java
b/kerby-kerb/kerb-admin-server/src/main/java/org/apache/kerby/kerberos/kerb/admin/server/PasswdServerInit.java
new file mode 100644
index 0000000..a80f253
--- /dev/null
+++ b/kerby-kerb/kerb-admin-server/src/main/java/org/apache/kerby/kerberos/kerb/admin/server/PasswdServerInit.java
@@ -0,0 +1,71 @@
+/**
+ *  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.server;
+
+import org.apache.kerby.kerberos.kerb.KrbException;
+import org.apache.kerby.kerberos.kerb.admin.server.kpasswd.PasswdServer;
+import org.apache.kerby.kerberos.kerb.admin.server.kpasswd.PasswdServerConfig;
+import org.apache.kerby.util.OSUtil;
+
+import java.io.File;
+
+/**
+ * A running tool for password server.
+ * Allow both tcp and udp.
+ * tcp port: 464
+ * udp port: 464
+ */
+public class PasswdServerInit {
+    private static final String USAGE = (OSUtil.isWindows()
+        ? "Usage: bin\\kpasswdServer.cmd" : "Usage: sh bin/kpasswdServer.sh")
+        + " <conf-file>\n"
+        + "\tExample:\n"
+        + "\t\t"
+        + (OSUtil.isWindows()
+        ? "bin\\kpasswdServer.cmd" : "sh bin/kpasswdServer.sh")
+        + " conf\n";
+
+    public static void main(String[] args) throws Exception {
+
+        if (args.length != 1) {
+            System.err.println(USAGE);
+            System.exit(1);
+        }
+
+        String confDirPath = args[0];
+        PasswdServer passwdServer = new PasswdServer(new File(confDirPath));
+        PasswdServerConfig passwdServerConfig = passwdServer.getPasswdServerConfig();
+
+        passwdServer.setPasswdHost(passwdServerConfig.getPasswdHost());
+        passwdServer.setAllowTcp(true);
+        passwdServer.setAllowUdp(true); /**change password protocol allow both tcp and udp*/
+        passwdServer.setPasswdServerPort(passwdServerConfig.getPasswdPort());
+
+        try {
+            passwdServer.init();
+        } catch (KrbException e) {
+            System.err.println("Errors occurred when start admin server:  " + e.getMessage());
+            System.exit(2);
+        }
+        passwdServer.start();
+        System.out.println("Password server started!");
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/2cb5c16f/kerby-kerb/kerb-admin-server/src/main/java/org/apache/kerby/kerberos/kerb/admin/server/kpasswd/PasswdServerHandler.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-admin-server/src/main/java/org/apache/kerby/kerberos/kerb/admin/server/kpasswd/PasswdServerHandler.java
b/kerby-kerb/kerb-admin-server/src/main/java/org/apache/kerby/kerberos/kerb/admin/server/kpasswd/PasswdServerHandler.java
index aa7ba55..363ecdd 100644
--- a/kerby-kerb/kerb-admin-server/src/main/java/org/apache/kerby/kerberos/kerb/admin/server/kpasswd/PasswdServerHandler.java
+++ b/kerby-kerb/kerb-admin-server/src/main/java/org/apache/kerby/kerberos/kerb/admin/server/kpasswd/PasswdServerHandler.java
@@ -40,7 +40,7 @@ public class PasswdServerHandler {
      */
     public PasswdServerHandler(PasswdServerContext passwdServerContext) {
         this.passwdServerContext = passwdServerContext;
-        LOG.info("Passwd contex realm:" + this.passwdServerContext.getPasswdRealm());
+        LOG.info("Passwd context realm:" + this.passwdServerContext.getPasswdRealm());
     }
 
     /**
@@ -53,76 +53,13 @@ public class PasswdServerHandler {
      */
     public ByteBuffer handleMessage(ByteBuffer receivedMessage,
                                     InetAddress remoteAddress) throws KrbException {
-        return null;
-        /*
-        KrbMessage krbRequest;
-        KdcRequest passwdRequest = null;
-        KrbMessage krbResponse;
-
-        ByteBuffer message = receivedMessage.duplicate();
-
-        try {
-            krbRequest = KrbCodec.decodeMessage(receivedMessage);
-        } catch (IOException e) {
-            LOG.error("Krb decoding message failed", e);
-            throw new KrbException(KrbErrorCode.KRB_AP_ERR_MSG_TYPE, "Krb decoding message
failed");
-        }
-
-        KrbMessageType messageType = krbRequest.getMsgType();
-        if (messageType == KrbMessageType.TGS_REQ || messageType
-                == KrbMessageType.AS_REQ) {
-            KdcReq passwdReq = (KdcReq) krbRequest;
-            String realm = getRequestRealm(passwdReq);
-            if (realm == null || !passwdContext.getPasswdRealm().equals(realm)) {
-                LOG.error("Invalid realm from passwd request: " + realm);
-                throw new KrbException("Invalid realm from passwd request: " + realm);
-            }
-
-            if (messageType == KrbMessageType.TGS_REQ) {
-                passwdRequest = new TgsRequest((TgsReq) passwdReq, passwdContext);
-            } else if (messageType == KrbMessageType.AS_REQ) {
-                passwdRequest = new AsRequest((AsReq) passwdReq, passwdContext);
-            } else {
-                LOG.error("Invalid message type: " + messageType);
-                throw new KrbException(KrbErrorCode.KRB_AP_ERR_MSG_TYPE);
-            }
-        }
-
-        // For checksum
-        if (passwdRequest == null) {
-            throw new KrbException("Kdc request is null.");
-        }
-        passwdRequest.setReqPackage(message);
-        if (remoteAddress == null) {
-            throw new KrbException("Remote address is null, not available.");
-        }
-        passwdRequest.setClientAddress(remoteAddress);
-        passwdRequest.isTcp(isTcp);
-
-        try {
-            passwdRequest.process();
-            krbResponse = passwdRequest.getReply();
-        } catch (KrbException e) {
-            if (e instanceof KdcRecoverableException) {
-                krbResponse = handleRecoverableException(
-                        (KdcRecoverableException) e, passwdRequest);
-            } else {
-                throw e;
-            }
-        }
-
-        int bodyLen = krbResponse.encodingLength();
-        ByteBuffer responseMessage;
-        if (isTcp) {
-            responseMessage = ByteBuffer.allocate(bodyLen + 4);
-            responseMessage.putInt(bodyLen);
-        } else {
-            responseMessage = ByteBuffer.allocate(bodyLen);
-        }
-        KrbCodec.encode(krbResponse, responseMessage);
+        System.out.println("Password Server receive message: ");
+        System.out.println(new String(receivedMessage.array()));
+        String response = "Password server receive message.";
+        ByteBuffer responseMessage = ByteBuffer.allocate(response.length() + 4);
+        responseMessage.putInt(response.length());
+        responseMessage.put(response.getBytes());
         responseMessage.flip();
-
         return responseMessage;
-        */
     }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/2cb5c16f/kerby-kerb/kerb-admin-server/src/main/java/org/apache/kerby/kerberos/kerb/admin/server/kpasswd/PasswdServerUtil.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-admin-server/src/main/java/org/apache/kerby/kerberos/kerb/admin/server/kpasswd/PasswdServerUtil.java
b/kerby-kerb/kerb-admin-server/src/main/java/org/apache/kerby/kerberos/kerb/admin/server/kpasswd/PasswdServerUtil.java
index e490e1a..f45bafa 100644
--- a/kerby-kerb/kerb-admin-server/src/main/java/org/apache/kerby/kerberos/kerb/admin/server/kpasswd/PasswdServerUtil.java
+++ b/kerby-kerb/kerb-admin-server/src/main/java/org/apache/kerby/kerberos/kerb/admin/server/kpasswd/PasswdServerUtil.java
@@ -43,7 +43,7 @@ public final class PasswdServerUtil {
      * @throws KrbException e.
      */
     public static PasswdServerConfig getPasswdServerConfig(File confDir) throws KrbException
{
-        File passwdConfFile = new File(confDir, "passwd.conf");
+        File passwdConfFile = new File(confDir, "kpasswdServer.conf");
         if (passwdConfFile.exists()) {
             PasswdServerConfig passwdServerConfig = new PasswdServerConfig();
             try {

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/2cb5c16f/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/PasswdClientTool.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/PasswdClientTool.java
b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/PasswdClientTool.java
new file mode 100644
index 0000000..cdceb2d
--- /dev/null
+++ b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/PasswdClientTool.java
@@ -0,0 +1,88 @@
+/**
+ *  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;
+
+import org.apache.kerby.kerberos.kerb.KrbException;
+import org.apache.kerby.kerberos.kerb.admin.kpasswd.PasswdClient;
+import org.apache.kerby.kerberos.kerb.admin.kpasswd.PasswdConfig;
+import org.apache.kerby.kerberos.kerb.admin.kpasswd.PasswdHandler;
+import org.apache.kerby.kerberos.kerb.admin.kpasswd.PasswdUtil;
+import org.apache.kerby.kerberos.kerb.admin.kpasswd.impl.DefaultPasswdHandler;
+import org.apache.kerby.kerberos.kerb.admin.kpasswd.request.PasswdRequest;
+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.util.OSUtil;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * A running tool for password client.
+ */
+public class PasswdClientTool {
+    private static final String USAGE = (OSUtil.isWindows()
+        ? "Usage: bin\\kpasswdClient.cmd" : "Usage: sh bin/kpasswdClient.sh")
+        + " <conf-file>\n"
+        + "\tExample:\n"
+        + "\t\t"
+        + (OSUtil.isWindows()
+        ? "bin\\kpasswdClient.cmd" : "sh bin/kpasswdClient.sh")
+        + " conf\n";
+
+    private static final String LEGAL_COMMANDS = "Legal functions are remaining to construct...\n";
+
+    public static void main(String[] args) throws KrbException {
+
+        if (args.length != 1) {
+            System.err.println(USAGE);
+            System.exit(1);
+        }
+
+        String confDirPath = args[0];
+        PasswdClient passwdClient = new PasswdClient(new File(confDirPath));
+        PasswdConfig passwdConfig = passwdClient.getPasswdConfig();
+
+        passwdClient.setAdminRealm(passwdConfig.getAdminRealm());
+        passwdClient.setAllowTcp(true);
+        passwdClient.setAllowUdp(true);
+        passwdClient.setAdminTcpPort(passwdConfig.getAdminPort());
+        passwdClient.setAdminUdpPort(passwdConfig.getAdminPort());
+
+        passwdClient.init();
+        System.out.println("password client init successful!");
+        System.out.print(LEGAL_COMMANDS);
+
+        PasswdHandler passwdHandler = new DefaultPasswdHandler();
+        PasswdRequest passwdRequest = new PasswdRequest();
+
+        TransportPair tpair = PasswdUtil.getTransportPair(passwdClient.getSetting());
+        KrbNetwork network = new KrbNetwork();
+        network.setSocketTimeout(passwdClient.getSetting().getTimeout());
+        KrbTransport transport;
+        try {
+            transport = network.connect(tpair);
+        } catch (IOException e) {
+            throw new KrbException("Failed to create transport", e);
+        }
+        passwdRequest.setTransport(transport);
+        passwdHandler.handleRequest(passwdRequest);
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/2cb5c16f/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kpasswd/PasswdConfigKey.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kpasswd/PasswdConfigKey.java
b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kpasswd/PasswdConfigKey.java
index 8ea2a83..b963076 100644
--- a/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kpasswd/PasswdConfigKey.java
+++ b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kpasswd/PasswdConfigKey.java
@@ -25,8 +25,8 @@ public enum PasswdConfigKey implements ConfigKey {
     KRB_DEBUG(true),
     ADMIN_HOST("localhost"),
     ADMIN_PORT(null),
-    ADMIN_ALLOW_UDP(false),
-    ADMIN_ALLOW_TCP(false),
+    ADMIN_ALLOW_UDP(true),
+    ADMIN_ALLOW_TCP(true),
     ADMIN_UDP_PORT(null),
     ADMIN_TCP_PORT(null),
     ADMIN_DOMAIN("example.com"),

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/2cb5c16f/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kpasswd/PasswdHandler.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kpasswd/PasswdHandler.java
b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kpasswd/PasswdHandler.java
index 7286273..8f07bbc 100644
--- a/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kpasswd/PasswdHandler.java
+++ b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kpasswd/PasswdHandler.java
@@ -37,28 +37,29 @@ public abstract class PasswdHandler {
     }
 
     /**
-     * Handle the kdc request.
+     * Handle the password server request.
      *
-     * @param passwdRequest The kdc request
+     * @param passwdRequest The password server request
      * @throws KrbException e
      */
     public void handleRequest(PasswdRequest passwdRequest) throws KrbException {
         passwdRequest.process();
-        /*
-        ByteBuffer requestMessage;
 
-        requestMessage = ByteBuffer.allocate(bodyLen + 4);
-        requestMessage.putInt(bodyLen);
+        String request = "Client request change password.";
+        ByteBuffer requestMessage = ByteBuffer.allocate(request.length() + 4);
+        requestMessage.putInt(request.length());
+        requestMessage.put(request.getBytes());
+        requestMessage.flip();
 
         try {
             sendMessage(passwdRequest, requestMessage);
         } catch (IOException e) {
             throw new KrbException("sending message failed", e);
-        }*/
+        }
     }
 
     /**
-     * Process the response messabe from kdc.
+     * Process the response message from kdc.
      *
      * @param passwdRequest The kpasswd request
      * @param responseMessage The message from kdc
@@ -66,29 +67,16 @@ public abstract class PasswdHandler {
      */
     public void onResponseMessage(PasswdRequest passwdRequest,
                                   ByteBuffer responseMessage) throws KrbException {
-        /*
-        KrbMessage kdcRep = null;
-        try {
-            kdcRep = KrbCodec.decodeMessage(responseMessage);
-        } catch (IOException e) {
-            throw new KrbException("Krb decoding message failed", e);
-        }
-
-        KrbMessageType messageType = kdcRep.getMsgType();
-        if (messageType == KrbMessageType.AS_REP) {
-
-            kdcRequest.processResponse((KdcRep) kdcRep);
-        } else if (messageType == KrbMessageType.TGS_REP) {
-            kdcRequest.processResponse((KdcRep) kdcRep);
-        }
-        */
+        String message = new String(responseMessage.array());
+        System.out.println("client receive message: ");
+        System.out.println(message);
     }
 
     /**
-     * Send message to kdc.
+     * Send message to password server.
      *
-     * @param passwdRequest The kdc request
-     * @param requestMessage The request message to kdc
+     * @param passwdRequest The change password request
+     * @param requestMessage The request message to password server
      * @throws IOException e
      */
     protected abstract void sendMessage(PasswdRequest passwdRequest,

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/2cb5c16f/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kpasswd/PasswdUtil.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kpasswd/PasswdUtil.java
b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kpasswd/PasswdUtil.java
index 740315c..8843b74 100644
--- a/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kpasswd/PasswdUtil.java
+++ b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kpasswd/PasswdUtil.java
@@ -30,7 +30,7 @@ import java.util.Map;
 public final class PasswdUtil {
     private PasswdUtil() { }
 
-    private static final String KRB5_FILE_NAME = "krb5.conf";
+    private static final String KRB5_FILE_NAME = "kpasswdClient.conf";
     private static final String KRB5_ENV_NAME = "KRB5_CONFIG";
 
     /**

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/2cb5c16f/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kpasswd/impl/DefaultPasswdHandler.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kpasswd/impl/DefaultPasswdHandler.java
b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kpasswd/impl/DefaultPasswdHandler.java
index d2911cc..ae4f451 100644
--- a/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kpasswd/impl/DefaultPasswdHandler.java
+++ b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kpasswd/impl/DefaultPasswdHandler.java
@@ -22,6 +22,7 @@ package org.apache.kerby.kerberos.kerb.admin.kpasswd.impl;
 import org.apache.kerby.kerberos.kerb.KrbException;
 import org.apache.kerby.kerberos.kerb.admin.kpasswd.request.PasswdRequest;
 import org.apache.kerby.kerberos.kerb.admin.kpasswd.PasswdHandler;
+import org.apache.kerby.kerberos.kerb.transport.KrbTransport;
 
 import java.io.IOException;
 import java.nio.ByteBuffer;
@@ -29,34 +30,32 @@ import java.nio.ByteBuffer;
 public class DefaultPasswdHandler extends PasswdHandler {
 
     /**
-     * {@inheritDoc}
+     * Client handle request.
+     * Use super.handleRequest to send message,
+     * and use this.handleRequest to receive message.
      */
     @Override
     public void handleRequest(PasswdRequest passwdRequest) throws KrbException {
-        /*
-        KrbTransport transport = (KrbTransport) passwdRequest.getSessionData();
-        transport.setAttachment(passwdRequest);
-
+        /** super is used to send messsage*/
         super.handleRequest(passwdRequest);
-        ByteBuffer receivedMessage = null;
+
+        KrbTransport transport = passwdRequest.getTransport();
+        ByteBuffer receiveMessage = null;
         try {
-            receivedMessage = transport.receiveMessage();
+            receiveMessage = transport.receiveMessage();
         } catch (IOException e) {
-            throw new KrbException("Receiving response message failed", e);
+            throw new KrbException("Client receives response message failed.");
         }
-        super.onResponseMessage(passwdRequest, receivedMessage);
-        */
+        super.onResponseMessage(passwdRequest, receiveMessage);
     }
 
     /**
-     * {@inheritDoc}
+     * Override super's sendMessage method.
      */
     @Override
     protected void sendMessage(PasswdRequest passwdRequest,
                                ByteBuffer requestMessage) throws IOException {
-        /*
-        KrbTransport transport = (KrbTransport) passwdRequest.getSessionData();
+        KrbTransport transport = passwdRequest.getTransport();
         transport.sendMessage(requestMessage);
-        */
     }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/2cb5c16f/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kpasswd/request/PasswdRequest.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kpasswd/request/PasswdRequest.java
b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kpasswd/request/PasswdRequest.java
index 9f755aa..7f8868c 100644
--- a/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kpasswd/request/PasswdRequest.java
+++ b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/kpasswd/request/PasswdRequest.java
@@ -19,21 +19,21 @@
  */
 package org.apache.kerby.kerberos.kerb.admin.kpasswd.request;
 
-import org.apache.kerby.kerberos.kerb.admin.kpasswd.PasswdContext;
+import org.apache.kerby.kerberos.kerb.transport.KrbTransport;
 
+/**
+ * There is only one kind of password request,
+ * that is the change password request.
+ */
 public class PasswdRequest {
-    private PasswdContext context;
-
-    public PasswdRequest(PasswdContext context) {
-        this.context = context;
-    }
+    private KrbTransport transport;
 
-    public PasswdContext getContext() {
-        return context;
+    public void setTransport(KrbTransport transport) {
+        this.transport = transport;
     }
 
-    public void setContext(PasswdContext context) {
-        this.context = context;
+    public KrbTransport getTransport() {
+        return transport;
     }
 
     public void process() {


Mime
View raw message