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-604 Add some logs when processing the exceptions.
Date Fri, 29 Jul 2016 08:51:46 GMT
Repository: directory-kerby
Updated Branches:
  refs/heads/trunk 67d67c916 -> 4083f7e7b


DIRKRB-604 Add some logs when processing the exceptions.


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

Branch: refs/heads/trunk
Commit: 4083f7e7b1b4558adc19e8fb063fbe8d67f4e80e
Parents: 67d67c9
Author: plusplusjiajia <jiajia.li@intel.com>
Authored: Fri Jul 29 16:57:44 2016 +0800
Committer: plusplusjiajia <jiajia.li@intel.com>
Committed: Fri Jul 29 16:57:44 2016 +0800

----------------------------------------------------------------------
 .../kerby/benchmark/KrbCodecBenchmark.java      |  6 ++-
 .../typeAdapter/EncryptionKeyAdapter.java       |  5 +-
 .../identitybackend/LdapIdentityBackend.java    |  6 +--
 .../kdc/identitybackend/IdentityZNode.java      |  2 +-
 .../ZookeeperIdentityBackend.java               |  4 +-
 .../kerberos/kdc/impl/NettyKdcHandler.java      |  1 -
 .../kerberos/kdc/impl/NettyKdcNetwork.java      |  2 +-
 .../kadmin/impl/DefaultAdminServerHandler.java  |  4 +-
 .../kerb/admin/RemoteAdminClientTool.java       | 11 +++--
 .../admin/kadmin/remote/RemoteKadminImpl.java   |  6 ++-
 .../client/preauth/pkinit/PkinitPreauth.java    | 10 ++--
 .../kerb/preauth/pkinit/CertificateHelper.java  |  6 ++-
 .../kerb/preauth/pkinit/PkinitCrypto.java       | 51 ++++++++++----------
 .../kerberos/kerb/transport/KdcNetwork.java     |  6 ++-
 .../kerb/type/ad/AuthorizationDataEntry.java    |  1 -
 .../kerb/type/ad/AuthorizationDataWrapper.java  |  5 +-
 .../server/preauth/pkinit/PkinitPreauth.java    | 31 ++++++------
 .../kerb/server/preauth/token/TokenPreauth.java | 11 +++--
 .../kerberos/kerb/server/SimpleKdcServer.java   |  5 +-
 .../tool/kinit/KinitToolWithConcurrence.java    | 22 +++------
 .../kerby/kerberos/tool/klist/KlistTool.java    |  9 ++--
 .../kerby/kerberos/tool/token/TokenCache.java   | 34 ++++++++-----
 .../kadmin/command/AddPrincipalsCommand.java    |  8 ++-
 23 files changed, 139 insertions(+), 107 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/4083f7e7/benchmark/src/main/java/org/apache/kerby/benchmark/KrbCodecBenchmark.java
----------------------------------------------------------------------
diff --git a/benchmark/src/main/java/org/apache/kerby/benchmark/KrbCodecBenchmark.java b/benchmark/src/main/java/org/apache/kerby/benchmark/KrbCodecBenchmark.java
index 216b6b9..35eb0a3 100644
--- a/benchmark/src/main/java/org/apache/kerby/benchmark/KrbCodecBenchmark.java
+++ b/benchmark/src/main/java/org/apache/kerby/benchmark/KrbCodecBenchmark.java
@@ -26,7 +26,8 @@ import org.openjdk.jmh.annotations.Fork;
 import org.openjdk.jmh.annotations.Mode;
 import org.openjdk.jmh.annotations.OutputTimeUnit;
 import org.openjdk.jmh.annotations.Warmup;
-
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -36,6 +37,7 @@ import java.util.concurrent.TimeUnit;
 @BenchmarkMode(Mode.AverageTime)
 @OutputTimeUnit(TimeUnit.MILLISECONDS)
 public class KrbCodecBenchmark {
+    private static final Logger LOG = LoggerFactory.getLogger(KrbCodecBenchmark.class);
 
     private static ByteBuffer apreqToken;
 
@@ -45,7 +47,7 @@ public class KrbCodecBenchmark {
             is.read(bytes);
             apreqToken = ByteBuffer.wrap(bytes);
         } catch (IOException e) {
-            e.printStackTrace();
+            LOG.error("Fail to read bytes from input stream. " + e);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/4083f7e7/kerby-backend/json-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/typeAdapter/EncryptionKeyAdapter.java
----------------------------------------------------------------------
diff --git a/kerby-backend/json-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/typeAdapter/EncryptionKeyAdapter.java
b/kerby-backend/json-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/typeAdapter/EncryptionKeyAdapter.java
index 6694ab9..677affb 100644
--- a/kerby-backend/json-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/typeAdapter/EncryptionKeyAdapter.java
+++ b/kerby-backend/json-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/typeAdapter/EncryptionKeyAdapter.java
@@ -30,12 +30,15 @@ import org.apache.kerby.kerberos.kerb.KrbCodec;
 import org.apache.kerby.kerberos.kerb.KrbException;
 import org.apache.kerby.kerberos.kerb.type.base.EncryptionKey;
 import org.apache.kerby.util.HexUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
 import java.lang.reflect.Type;
 
 public class EncryptionKeyAdapter implements JsonSerializer<EncryptionKey>,
         JsonDeserializer<EncryptionKey> {
+    private static final Logger LOG = LoggerFactory.getLogger(EncryptionKeyAdapter.class);
 
     @Override
     public EncryptionKey deserialize(JsonElement jsonElement, Type type,
@@ -47,7 +50,7 @@ public class EncryptionKeyAdapter implements JsonSerializer<EncryptionKey>,
         try {
             encryptionKey.decode(HexUtil.hex2bytes(jsonObject.get("key").getAsString()));
         } catch (IOException e) {
-            e.printStackTrace();
+            LOG.error("Fail to decode encryption key. " + e);
         }
         encryptionKey.setKvno(jsonObject.get("kvno").getAsInt());
         return encryptionKey;

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/4083f7e7/kerby-backend/ldap-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/LdapIdentityBackend.java
----------------------------------------------------------------------
diff --git a/kerby-backend/ldap-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/LdapIdentityBackend.java
b/kerby-backend/ldap-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/LdapIdentityBackend.java
index 21fb731..1e087a9 100644
--- a/kerby-backend/ldap-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/LdapIdentityBackend.java
+++ b/kerby-backend/ldap-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/LdapIdentityBackend.java
@@ -340,11 +340,11 @@ public class LdapIdentityBackend extends AbstractIdentityBackend {
             cursor.close();
             Collections.sort(identityNames);
         } catch (LdapException e) {
-            e.printStackTrace();
+            LOG.error("With LdapException when LdapConnection searching. " + e);
         } catch (CursorException e) {
-            e.printStackTrace();
+            LOG.error("With CursorException when EntryCursor getting. " + e);
         } catch (IOException e) {
-            e.printStackTrace();
+            LOG.error("With IOException when closing EntryCursor. " + e);
         }
         return identityNames;
     }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/4083f7e7/kerby-backend/zookeeper-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/IdentityZNode.java
----------------------------------------------------------------------
diff --git a/kerby-backend/zookeeper-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/IdentityZNode.java
b/kerby-backend/zookeeper-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/IdentityZNode.java
index 92c7bf9..883d9f8 100644
--- a/kerby-backend/zookeeper-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/IdentityZNode.java
+++ b/kerby-backend/zookeeper-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/IdentityZNode.java
@@ -315,7 +315,7 @@ public class IdentityZNode {
             try {
                 encryptionKey.decode(key);
             } catch (IOException e) {
-                e.printStackTrace();
+                LOG.error("Fail to decode the encryption key. " + e);
             }
             encryptionKey.setKvno(getEncryptionKeyNo(typeName));
             keys.add(encryptionKey);

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/4083f7e7/kerby-backend/zookeeper-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/ZookeeperIdentityBackend.java
----------------------------------------------------------------------
diff --git a/kerby-backend/zookeeper-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/ZookeeperIdentityBackend.java
b/kerby-backend/zookeeper-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/ZookeeperIdentityBackend.java
index 810b271..0436e66 100644
--- a/kerby-backend/zookeeper-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/ZookeeperIdentityBackend.java
+++ b/kerby-backend/zookeeper-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/ZookeeperIdentityBackend.java
@@ -84,7 +84,7 @@ public class ZookeeperIdentityBackend extends AbstractIdentityBackend {
         try {
             zooKeeper.close();
         } catch (InterruptedException e) {
-            e.printStackTrace();
+            LOG.error("Closing zookeeper interrupted." + e);
         }
         LOG.info("Zookeeper session closed.");
     }
@@ -128,7 +128,7 @@ public class ZookeeperIdentityBackend extends AbstractIdentityBackend
{
                     try {
                         Thread.sleep(100);
                     } catch (InterruptedException e) {
-                        e.printStackTrace();
+                        LOG.error("Some thread has interrupted the current thread" + e);
                     }
                 } else {
                     LOG.info("Success connect to zookeeper server.");

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/4083f7e7/kerby-kdc/src/main/java/org/apache/kerby/kerberos/kdc/impl/NettyKdcHandler.java
----------------------------------------------------------------------
diff --git a/kerby-kdc/src/main/java/org/apache/kerby/kerberos/kdc/impl/NettyKdcHandler.java
b/kerby-kdc/src/main/java/org/apache/kerby/kerberos/kdc/impl/NettyKdcHandler.java
index edaf80d..5635c29 100644
--- a/kerby-kdc/src/main/java/org/apache/kerby/kerberos/kdc/impl/NettyKdcHandler.java
+++ b/kerby-kdc/src/main/java/org/apache/kerby/kerberos/kdc/impl/NettyKdcHandler.java
@@ -58,7 +58,6 @@ public class NettyKdcHandler extends ChannelInboundHandlerAdapter {
         } catch (Exception e) {
             LOG.error("Error occurred while processing request:"
                     + e);
-            e.printStackTrace();
         }
     }
 

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/4083f7e7/kerby-kdc/src/main/java/org/apache/kerby/kerberos/kdc/impl/NettyKdcNetwork.java
----------------------------------------------------------------------
diff --git a/kerby-kdc/src/main/java/org/apache/kerby/kerberos/kdc/impl/NettyKdcNetwork.java
b/kerby-kdc/src/main/java/org/apache/kerby/kerberos/kdc/impl/NettyKdcNetwork.java
index 1740432..50fbcf8 100644
--- a/kerby-kdc/src/main/java/org/apache/kerby/kerberos/kdc/impl/NettyKdcNetwork.java
+++ b/kerby-kdc/src/main/java/org/apache/kerby/kerberos/kdc/impl/NettyKdcNetwork.java
@@ -134,7 +134,7 @@ public class NettyKdcNetwork {
                 group.terminationFuture().sync();
             }
         } catch (InterruptedException e) {
-            e.printStackTrace();
+            LOG.error("Interrupted when sync. " + e);
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/4083f7e7/kerby-kerb/kerb-admin-server/src/main/java/org/apache/kerby/kerberos/kerb/admin/server/kadmin/impl/DefaultAdminServerHandler.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-admin-server/src/main/java/org/apache/kerby/kerberos/kerb/admin/server/kadmin/impl/DefaultAdminServerHandler.java
b/kerby-kerb/kerb-admin-server/src/main/java/org/apache/kerby/kerberos/kerb/admin/server/kadmin/impl/DefaultAdminServerHandler.java
index 764befb..62a7e47 100644
--- a/kerby-kerb/kerb-admin-server/src/main/java/org/apache/kerby/kerberos/kerb/admin/server/kadmin/impl/DefaultAdminServerHandler.java
+++ b/kerby-kerb/kerb-admin-server/src/main/java/org/apache/kerby/kerberos/kerb/admin/server/kadmin/impl/DefaultAdminServerHandler.java
@@ -63,7 +63,7 @@ public class DefaultAdminServerHandler extends AdminServerHandler implements
Run
                     try {
                         saslNegotiation();
                     } catch (Exception e) {
-                        e.printStackTrace();
+                        logger.error("With exception when sasl negotiation." + e);
                     }
                 } else {
                     ByteBuffer message = transport.receiveMessage();
@@ -142,7 +142,7 @@ public class DefaultAdminServerHandler extends AdminServerHandler implements
Run
                         }
                     }
                 } catch (Exception e) {
-                    e.printStackTrace();
+                    logger.error("With exception when sasl negotiation. " + e);
                 }
                 return null;
             }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/4083f7e7/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/RemoteAdminClientTool.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/RemoteAdminClientTool.java
b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/RemoteAdminClientTool.java
index 27a8da2..819ec1d 100644
--- a/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/RemoteAdminClientTool.java
+++ b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/RemoteAdminClientTool.java
@@ -36,6 +36,8 @@ 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 org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import javax.security.auth.Subject;
 import javax.security.auth.login.LoginException;
@@ -54,6 +56,7 @@ import java.util.Scanner;
  * Command use of remote admin
  */
 public class RemoteAdminClientTool {
+    private static final Logger LOG = LoggerFactory.getLogger(RemoteAdminClientTool.class);
     private static final byte[] EMPTY = new byte[0];
     private static KrbTransport transport;
     private static final String PROMPT = RemoteAdminClientTool.class.getSimpleName() + ".local:";
@@ -126,7 +129,7 @@ public class RemoteAdminClientTool {
         try {
             tpair = AdminUtil.getTransportPair(adminClient.getSetting());
         } catch (KrbException e) {
-            e.printStackTrace();
+            LOG.error("Fail to get transport pair. " + e);
         }
         KrbNetwork network = new KrbNetwork();
         network.setSocketTimeout(adminClient.getSetting().getTimeout());
@@ -144,7 +147,7 @@ public class RemoteAdminClientTool {
             subject = AuthUtil.loginUsingKeytab(adminPrincipal,
                 new File(adminConfig.getKeyTabFile()));
         } catch (LoginException e) {
-            e.printStackTrace();
+            LOG.error("Fail to login using keytab. " + e);
         }
         Subject.doAs(subject, new PrivilegedAction<Object>() {
             @Override
@@ -161,7 +164,7 @@ public class RemoteAdminClientTool {
                         saslClient = Sasl.createSaslClient(new String[]{"GSSAPI"}, null,
                             protocol, serverName, props, null);
                     } catch (SaslException e) {
-                        e.printStackTrace();
+                        LOG.error("Fail to create sasl client. " + e);
                     }
                     if (saslClient == null) {
                         throw new KrbException("Unable to find client implementation for:
GSSAPI");
@@ -171,7 +174,7 @@ public class RemoteAdminClientTool {
                         response = saslClient.hasInitialResponse()
                             ? saslClient.evaluateChallenge(EMPTY) : EMPTY;
                     } catch (SaslException e) {
-                        e.printStackTrace();
+                        LOG.error("Sasl client evaluate challenge failed." + e);
                     }
 
                     sendMessage(response, saslClient);

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/4083f7e7/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 c4ac154..ccc3419 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
@@ -33,6 +33,8 @@ import org.apache.kerby.kerberos.kerb.common.KrbUtil;
 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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.io.File;
 import java.io.IOException;
@@ -48,7 +50,7 @@ import java.util.List;
  * TO BE IMPLEMENTED.
  */
 public class RemoteKadminImpl implements Kadmin {
-
+    private static final Logger LOG = LoggerFactory.getLogger(RemoteKadminImpl.class);
     private InternalAdminClient innerClient;
     private KrbTransport transport;
 
@@ -58,7 +60,7 @@ public class RemoteKadminImpl implements Kadmin {
         try {
             tpair = AdminUtil.getTransportPair(innerClient.getSetting());
         } catch (KrbException e) {
-            e.printStackTrace();
+            LOG.error("Fail to get transport pair. " + e);
         }
         KrbNetwork network = new KrbNetwork();
         network.setSocketTimeout(innerClient.getSetting().getTimeout());

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/4083f7e7/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb/client/preauth/pkinit/PkinitPreauth.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb/client/preauth/pkinit/PkinitPreauth.java
b/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb/client/preauth/pkinit/PkinitPreauth.java
index 1d539aa..f16d51d 100644
--- a/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb/client/preauth/pkinit/PkinitPreauth.java
+++ b/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb/client/preauth/pkinit/PkinitPreauth.java
@@ -269,7 +269,7 @@ public class PkinitPreauth extends AbstractPreauthPlugin {
             try {
                 clientPubKey = client.init(DhGroup.MODP_GROUP2);
             } catch (Exception e) {
-                e.printStackTrace();
+                LOG.error("DiffieHellmanClient init with failure. " + e);
             }
 
             reqCtx.setDhClient(client);
@@ -278,7 +278,7 @@ public class PkinitPreauth extends AbstractPreauthPlugin {
             try {
                 type = clientPubKey.getParams();
             } catch (Exception e) {
-                e.printStackTrace();
+                LOG.error("Fail to get params from client public key. " + e);
             }
             BigInteger q = type.getP().shiftRight(1);
             DhParameter dhParameter = new DhParameter();
@@ -342,7 +342,7 @@ public class PkinitPreauth extends AbstractPreauthPlugin {
             try {
                 contentInfo.decode(dhSignedData);
             } catch (IOException e) {
-                e.printStackTrace();
+                LOG.error("Fail to decode dhSignedData. " + e);
             }
 
             SignedData signedData = contentInfo.getContentAs(SignedData.class);
@@ -364,7 +364,7 @@ public class PkinitPreauth extends AbstractPreauthPlugin {
                     x509Certificate = (X509Certificate) certs.iterator().next();
                 }
             } catch (KrbException e) {
-                e.printStackTrace();
+                LOG.error("Fail to load certs from archor file. " + e);
             }
             
             if (x509Certificate == null) {
@@ -426,7 +426,7 @@ public class PkinitPreauth extends AbstractPreauthPlugin {
                 client.doPhase(dhPublicKey.getEncoded());
                 secretKey = client.generateKey(null, null, encType);
             } catch (Exception e) {
-                e.printStackTrace();
+                LOG.error("DiffieHellmanClient do parse failed. " + e);
             }
             // Set the DH shared key as the client key
             if (secretKey == null) {

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/4083f7e7/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/preauth/pkinit/CertificateHelper.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/preauth/pkinit/CertificateHelper.java
b/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/preauth/pkinit/CertificateHelper.java
index 53096d4..6ea6feb 100644
--- a/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/preauth/pkinit/CertificateHelper.java
+++ b/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/preauth/pkinit/CertificateHelper.java
@@ -20,6 +20,8 @@
 package org.apache.kerby.kerberos.kerb.preauth.pkinit;
 
 import org.apache.kerby.kerberos.kerb.KrbException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.io.File;
 import java.io.FileInputStream;
@@ -33,7 +35,7 @@ import java.util.Collection;
 import java.util.List;
 
 public class CertificateHelper {
-
+    private static final Logger LOG = LoggerFactory.getLogger(CertificateHelper.class);
 
     public static List<Certificate> loadCerts(String filename) throws KrbException
{
         
@@ -43,7 +45,7 @@ public class CertificateHelper {
             try {
                 res = new FileInputStream(file);
             } catch (FileNotFoundException e) {
-                e.printStackTrace();
+                LOG.error("Can't load cert, file not found. " + e);
             }
         } else {
             res = CertificateHelper.class.getClassLoader().getResourceAsStream(filename);

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/4083f7e7/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/preauth/pkinit/PkinitCrypto.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/preauth/pkinit/PkinitCrypto.java
b/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/preauth/pkinit/PkinitCrypto.java
index 63e3e44..c9f3cad 100644
--- a/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/preauth/pkinit/PkinitCrypto.java
+++ b/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/preauth/pkinit/PkinitCrypto.java
@@ -18,6 +18,27 @@
  */
 package org.apache.kerby.kerberos.kerb.preauth.pkinit;
 
+import org.apache.kerby.asn1.type.Asn1ObjectIdentifier;
+import org.apache.kerby.cms.type.CertificateSet;
+import org.apache.kerby.cms.type.DigestAlgorithmIdentifiers;
+import org.apache.kerby.cms.type.EncapsulatedContentInfo;
+import org.apache.kerby.cms.type.RevocationInfoChoices;
+import org.apache.kerby.cms.type.SignedContentInfo;
+import org.apache.kerby.cms.type.SignedData;
+import org.apache.kerby.cms.type.SignerInfos;
+import org.apache.kerby.kerberos.kerb.KrbCodec;
+import org.apache.kerby.kerberos.kerb.KrbErrorCode;
+import org.apache.kerby.kerberos.kerb.KrbException;
+import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
+import org.apache.kerby.util.HexUtil;
+import org.apache.kerby.x509.type.Certificate;
+import org.apache.kerby.x509.type.DhParameter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.crypto.interfaces.DHPublicKey;
+import javax.crypto.spec.DHParameterSpec;
+import javax.crypto.spec.DHPublicKeySpec;
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.math.BigInteger;
@@ -41,28 +62,6 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
-import javax.crypto.interfaces.DHPublicKey;
-import javax.crypto.spec.DHParameterSpec;
-import javax.crypto.spec.DHPublicKeySpec;
-
-import org.apache.kerby.asn1.type.Asn1ObjectIdentifier;
-import org.apache.kerby.cms.type.CertificateSet;
-import org.apache.kerby.cms.type.DigestAlgorithmIdentifiers;
-import org.apache.kerby.cms.type.EncapsulatedContentInfo;
-import org.apache.kerby.cms.type.RevocationInfoChoices;
-import org.apache.kerby.cms.type.SignedContentInfo;
-import org.apache.kerby.cms.type.SignedData;
-import org.apache.kerby.cms.type.SignerInfos;
-import org.apache.kerby.kerberos.kerb.KrbCodec;
-import org.apache.kerby.kerberos.kerb.KrbErrorCode;
-import org.apache.kerby.kerberos.kerb.KrbException;
-import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
-import org.apache.kerby.util.HexUtil;
-import org.apache.kerby.x509.type.Certificate;
-import org.apache.kerby.x509.type.DhParameter;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 /**
   * Ref. pkinit_crypto_openssl.c in MIT krb5 project.
   */
@@ -195,7 +194,7 @@ public class PkinitCrypto {
         try {
             keyFactory = KeyFactory.getInstance("DH");
         } catch (NoSuchAlgorithmException e) {
-            e.printStackTrace();
+            LOG.error("Fail to get dh instance. " + e);
         }
         DHPublicKey dhPublicKey = null;
         try {
@@ -203,7 +202,7 @@ public class PkinitCrypto {
                 dhPublicKey = (DHPublicKey) keyFactory.generatePublic(dhPublicKeySpec);
             }
         } catch (InvalidKeySpecException e) {
-            e.printStackTrace();
+            LOG.error("Fail to generate public key. " + e);
         }
         return dhPublicKey;
     }
@@ -392,9 +391,9 @@ public class PkinitCrypto {
         try {
             certificate.decode(x509Certificate.getEncoded());
         } catch (IOException e) {
-            e.printStackTrace();
+            LOG.error("Fail to decode certificate. " + e);
         } catch (CertificateEncodingException e) {
-            e.printStackTrace();
+            LOG.error("Fail to encode x509 certificate. " + e);
         }
         return certificate;
     }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/4083f7e7/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/transport/KdcNetwork.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/transport/KdcNetwork.java
b/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/transport/KdcNetwork.java
index 135eb6e..d883774 100644
--- a/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/transport/KdcNetwork.java
+++ b/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/transport/KdcNetwork.java
@@ -19,6 +19,9 @@
  */
 package org.apache.kerby.kerberos.kerb.transport;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import java.io.IOException;
 import java.net.InetSocketAddress;
 import java.net.ServerSocket;
@@ -34,6 +37,7 @@ import java.util.Map;
  */
 @SuppressWarnings("PMD")
 public abstract class KdcNetwork {
+    private static final Logger LOG = LoggerFactory.getLogger(KdcNetwork.class);
     protected static final int MAX_MESSAGE_SIZE = 65507;
     private static final int KDC_TCP_TRANSPORT_TIMEOUT = 3 * 1000;
     private static final int KDC_TCP_SERVER_TIMEOUT = 100;
@@ -110,7 +114,7 @@ public abstract class KdcNetwork {
         try {
             Thread.sleep(1000);
         } catch (InterruptedException e) {
-            e.printStackTrace();
+            LOG.warn("Interrupted when thread sleeping. " + e);
         }
         isStopped = true;
     }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/4083f7e7/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/ad/AuthorizationDataEntry.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/ad/AuthorizationDataEntry.java
b/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/ad/AuthorizationDataEntry.java
index ae16514..4d5ad22 100644
--- a/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/ad/AuthorizationDataEntry.java
+++ b/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/ad/AuthorizationDataEntry.java
@@ -148,7 +148,6 @@ public class AuthorizationDataEntry extends KrbSequenceType {
             } catch (InstantiationException | IllegalAccessException | IOException e) {
                 e.printStackTrace();
             }
-
         }
         return result;
     }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/4083f7e7/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/ad/AuthorizationDataWrapper.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/ad/AuthorizationDataWrapper.java
b/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/ad/AuthorizationDataWrapper.java
index 86fc524..2a59be0 100644
--- a/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/ad/AuthorizationDataWrapper.java
+++ b/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/type/ad/AuthorizationDataWrapper.java
@@ -21,6 +21,8 @@ package org.apache.kerby.kerberos.kerb.type.ad;
 
 import org.apache.kerby.asn1.Asn1Dumper;
 import org.apache.kerby.asn1.EnumType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
 
@@ -30,6 +32,7 @@ import java.io.IOException;
  * @author <a href="mailto:dev@directory.apache.org">Apache DirectoryProject</a>
  */
 public class AuthorizationDataWrapper extends AuthorizationDataEntry {
+    private static final Logger LOG = LoggerFactory.getLogger(AuthorizationDataWrapper.class);
 
     private AuthorizationData authorizationData;
 
@@ -111,7 +114,7 @@ public class AuthorizationDataWrapper extends AuthorizationDataEntry {
         try {
             getAuthorizationData().dumpWith(dumper, indents + 8);
         } catch (IOException e) {
-            e.printStackTrace();
+            LOG.error("Fail to get authorization data. " + e);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/4083f7e7/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/preauth/pkinit/PkinitPreauth.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/preauth/pkinit/PkinitPreauth.java
b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/preauth/pkinit/PkinitPreauth.java
index d5c53f0..5e91950 100644
--- a/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/preauth/pkinit/PkinitPreauth.java
+++ b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/preauth/pkinit/PkinitPreauth.java
@@ -19,18 +19,6 @@
  */
 package org.apache.kerby.kerberos.kerb.server.preauth.pkinit;
 
-import java.io.IOException;
-import java.math.BigInteger;
-import java.nio.ByteBuffer;
-import java.security.cert.X509Certificate;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.crypto.interfaces.DHPublicKey;
-
 import org.apache.kerby.asn1.Asn1;
 import org.apache.kerby.asn1.parse.Asn1Container;
 import org.apache.kerby.asn1.parse.Asn1ParseResult;
@@ -75,6 +63,17 @@ import org.apache.kerby.x509.type.SubjectPublicKeyInfo;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import javax.crypto.interfaces.DHPublicKey;
+import java.io.IOException;
+import java.math.BigInteger;
+import java.nio.ByteBuffer;
+import java.security.cert.X509Certificate;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 public class PkinitPreauth extends AbstractPreauthPlugin {
 
     private static final Logger LOG = LoggerFactory.getLogger(PkinitPreauth.class);
@@ -135,7 +134,7 @@ public class PkinitPreauth extends AbstractPreauthPlugin {
                 try {
                     eContentInfo.decode(signedAuthPack);
                 } catch (IOException e) {
-                    e.printStackTrace();
+                    LOG.error("Fail to decode signedAuthPack. " + e);
                 }
                 authPack = KrbCodec.decode(eContentInfo.getContent(), AuthPack.class);
 
@@ -145,7 +144,7 @@ public class PkinitPreauth extends AbstractPreauthPlugin {
                 try {
                     contentInfo.decode(signedAuthPack);
                 } catch (IOException e) {
-                    e.printStackTrace();
+                    LOG.error("Fail to decode signedAuthPack");
                 }
 
                 SignedData signedData = contentInfo.getContentAs(SignedData.class);
@@ -186,7 +185,7 @@ public class PkinitPreauth extends AbstractPreauthPlugin {
                 try {
                     parseResult = Asn1.parse(kdcRequest.getReqPackage());
                 } catch (IOException e) {
-                    e.printStackTrace();
+                    LOG.error("Fail to parse reqPackage. " + e);
                 }
                 /**Get REQ_BODY in KDC_REQ for checksum*/
                 Asn1Container container = (Asn1Container) parseResult;
@@ -290,7 +289,7 @@ public class PkinitPreauth extends AbstractPreauthPlugin {
         try {
             paDataEntry.setPaDataValue(paPkAsRep.encode());
         } catch (IOException e) {
-            e.printStackTrace();
+            LOG.error("Fail to encode PaDataEntry. " + e);
         }
 
         return paDataEntry;

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/4083f7e7/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/preauth/token/TokenPreauth.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/preauth/token/TokenPreauth.java
b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/preauth/token/TokenPreauth.java
index 8245115..f630b70 100644
--- a/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/preauth/token/TokenPreauth.java
+++ b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/preauth/token/TokenPreauth.java
@@ -41,6 +41,8 @@ import org.apache.kerby.kerberos.kerb.type.pa.PaDataEntry;
 import org.apache.kerby.kerberos.kerb.type.pa.PaDataType;
 import org.apache.kerby.kerberos.kerb.type.pa.token.PaTokenRequest;
 import org.apache.kerby.kerberos.kerb.type.pa.token.TokenInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.io.File;
 import java.io.FileInputStream;
@@ -52,6 +54,7 @@ import java.security.PublicKey;
 import java.util.List;
 
 public class TokenPreauth extends AbstractPreauthPlugin {
+    private static final Logger LOG = LoggerFactory.getLogger(TokenPreauth.class);
 
     public TokenPreauth() {
         super(new TokenPreauthMeta());
@@ -123,9 +126,9 @@ public class TokenPreauth extends AbstractPreauthPlugin {
                     tokenDecoder.setVerifyKey(verifyKey);
                 }
             } catch (FileNotFoundException e) {
-                e.printStackTrace();
+                LOG.error("The verify key path is wrong. " + e);
             } catch (Exception e) {
-                e.printStackTrace();
+                LOG.error("Fail to load public key. " + e);
             }
         }
         String decryptionKeyPath = kdcRequest.getKdcContext().getConfig().getDecryptionKeyConfig();
@@ -137,9 +140,9 @@ public class TokenPreauth extends AbstractPreauthPlugin {
                     tokenDecoder.setDecryptionKey(decryptionKey);
                 }
             } catch (FileNotFoundException e) {
-                e.printStackTrace();
+                LOG.error("The decryption key path is wrong. " + e);
             } catch (Exception e) {
-                e.printStackTrace();
+                LOG.error("Fail to load private key. " + e);
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/4083f7e7/kerby-kerb/kerb-simplekdc/src/main/java/org/apache/kerby/kerberos/kerb/server/SimpleKdcServer.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-simplekdc/src/main/java/org/apache/kerby/kerberos/kerb/server/SimpleKdcServer.java
b/kerby-kerb/kerb-simplekdc/src/main/java/org/apache/kerby/kerberos/kerb/server/SimpleKdcServer.java
index 4de8e7f..95ae420 100644
--- a/kerby-kerb/kerb-simplekdc/src/main/java/org/apache/kerby/kerberos/kerb/server/SimpleKdcServer.java
+++ b/kerby-kerb/kerb-simplekdc/src/main/java/org/apache/kerby/kerberos/kerb/server/SimpleKdcServer.java
@@ -28,6 +28,8 @@ import org.apache.kerby.kerberos.kerb.client.KrbConfig;
 import org.apache.kerby.kerberos.kerb.client.KrbPkinitClient;
 import org.apache.kerby.kerberos.kerb.client.KrbTokenClient;
 import org.apache.kerby.util.NetworkUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.io.File;
 import java.io.IOException;
@@ -37,6 +39,7 @@ import java.io.IOException;
  * kadmin sides for convenience.
  */
 public class SimpleKdcServer extends KdcServer {
+    private static final Logger LOG = LoggerFactory.getLogger(SimpleKdcServer.class);
     private final KrbClient krbClnt;
     private LocalKadmin kadmin;
     private Krb5Conf krb5Conf;
@@ -297,7 +300,7 @@ public class SimpleKdcServer extends KdcServer {
         try {
             krb5Conf.deleteKrb5conf();
         } catch (IOException e) {
-            e.printStackTrace();
+            LOG.info("Fail to delete krb5 conf. " + e);
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/4083f7e7/kerby-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/kinit/KinitToolWithConcurrence.java
----------------------------------------------------------------------
diff --git a/kerby-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/kinit/KinitToolWithConcurrence.java
b/kerby-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/kinit/KinitToolWithConcurrence.java
index 08bbb8f..7d33e1a 100644
--- a/kerby-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/kinit/KinitToolWithConcurrence.java
+++ b/kerby-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/kinit/KinitToolWithConcurrence.java
@@ -32,6 +32,7 @@ import org.apache.kerby.kerberos.kerb.client.KrbOptionGroup;
 import org.apache.kerby.kerberos.kerb.client.PkinitOption;
 import org.apache.kerby.kerberos.kerb.client.TokenOption;
 import org.apache.kerby.util.OSUtil;
+
 import java.io.File;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
@@ -96,7 +97,7 @@ public class KinitToolWithConcurrence {
     }
 
     private static void requestTicket(String principal,
-                                      KOptions ktOptions, int flag) throws KrbException {
+                                      KOptions ktOptions, int flag) {
         ktOptions.add(KinitOption.CLIENT_PRINCIPAL, principal);
 
         File confDir = null;
@@ -273,25 +274,16 @@ public class KinitToolWithConcurrence {
     public static class PreThread implements Runnable {
         @Override
         public void run() {
-            try {
-                request();
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
+            request();
         }
     }
 
-    public static void request() throws Exception {
+    public static void request() {
         int tempFlag = 0;
         lock.lock();
-        try {
-            tempFlag = thFlag;
-            thFlag++;
-        } catch (Exception e) {
-            e.printStackTrace();
-        } finally {
-            lock.unlock();
-        }
+        tempFlag = thFlag;
+        thFlag++;
+        lock.unlock();
         requestTicket(prList[tempFlag], ktOptions, tempFlag);
     }
 

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/4083f7e7/kerby-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/klist/KlistTool.java
----------------------------------------------------------------------
diff --git a/kerby-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/klist/KlistTool.java
b/kerby-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/klist/KlistTool.java
index 0d8f8d0..f8b1eca 100644
--- a/kerby-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/klist/KlistTool.java
+++ b/kerby-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/klist/KlistTool.java
@@ -28,6 +28,8 @@ import org.apache.kerby.kerberos.kerb.keytab.KeytabEntry;
 import org.apache.kerby.kerberos.kerb.type.base.PrincipalName;
 import org.apache.kerby.util.HexUtil;
 import org.apache.kerby.util.OSUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.io.File;
 import java.io.FileInputStream;
@@ -44,9 +46,10 @@ import java.util.List;
  * Ref. MIT klist command tool usage.
  */
 public class KlistTool {
+    private static final Logger LOG = LoggerFactory.getLogger(KlistTool.class);
 
-    private static  final String USAGE = (OSUtil.isWindows()
-            ? "Usage: bin\\klist.cmd" : "Usage: sh bin/klist.sh")
+    private static final String USAGE = (OSUtil.isWindows()
+        ? "Usage: bin\\klist.cmd" : "Usage: sh bin/klist.sh")
             + " [-e] [-V] [[-c] [-l] [-A] [-d] [-f] [-s] "
             + "[-a [-n]]] [-k [-t] [-K]] [name]\n"
             + "\t-c specifies credentials cache\n"
@@ -100,7 +103,7 @@ public class KlistTool {
                         cis.close();
                     }
                 } catch (IOException e) {
-                    e.printStackTrace();
+                    LOG.warn("Fail to close input stream. " + e);
                 }
             }
 

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/4083f7e7/kerby-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/token/TokenCache.java
----------------------------------------------------------------------
diff --git a/kerby-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/token/TokenCache.java
b/kerby-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/token/TokenCache.java
index e8c5a2c..1420063 100644
--- a/kerby-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/token/TokenCache.java
+++ b/kerby-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/token/TokenCache.java
@@ -22,16 +22,20 @@ package org.apache.kerby.kerberos.tool.token;
 
 import org.apache.commons.io.output.FileWriterWithEncoding;
 import org.apache.kerby.kerberos.kerb.KrbException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.Writer;
 import java.nio.charset.StandardCharsets;
 
 public class TokenCache {
+    private static final Logger LOG = LoggerFactory.getLogger(TokenCache.class);
     private static final String DEFAULT_TOKEN_CACHE_PATH = ".tokenauth";
     private static final String TOKEN_CACHE_FILE = ".tokenauth.token";
 
@@ -51,22 +55,32 @@ public class TokenCache {
         }
 
         String token = null;
+        BufferedReader reader = null;
+        try {
+            reader = new BufferedReader(
+                new InputStreamReader(new FileInputStream(cacheFile), StandardCharsets.UTF_8));
+        } catch (FileNotFoundException e) {
+            LOG.error("Can't find the cache file. " + e);
+        }
+        String line = null;
+        try {
+            line = reader.readLine();
+        } catch (IOException e) {
+            LOG.error("I/O error occurs. " + e);
+        }
         try {
-            BufferedReader reader = new BufferedReader(
-                    new InputStreamReader(new FileInputStream(cacheFile), StandardCharsets.UTF_8));
-            String line = reader.readLine();
             reader.close();
-            if (line != null) {
-                token = line;
-            }
-        } catch (IOException ex) { //NOPMD
-            ex.printStackTrace();
+        } catch (IOException e) {
+            LOG.warn("Fail to close reader. " + e);
+        }
+        if (line != null) {
+            token = line;
         }
 
         return token;
     }
 
-    public static void writeToken(String token) {
+    public static void writeToken(String token) throws KrbException {
         File cacheFile = getDefaultTokenCache();
 
         try {
@@ -87,8 +101,6 @@ public class TokenCache {
             if (cacheFile.delete()) {
                 System.err.println("Cache file is deleted.");
             }
-        } catch (KrbException e) {
-            e.printStackTrace();
         }
     }
 

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/4083f7e7/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/AddPrincipalsCommand.java
----------------------------------------------------------------------
diff --git a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/AddPrincipalsCommand.java
b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/AddPrincipalsCommand.java
index b1843e5..470f100 100644
--- a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/AddPrincipalsCommand.java
+++ b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/AddPrincipalsCommand.java
@@ -24,8 +24,11 @@ import org.apache.kerby.kerberos.kerb.KrbException;
 import org.apache.kerby.kerberos.kerb.admin.kadmin.KadminOption;
 import org.apache.kerby.kerberos.kerb.admin.kadmin.local.LocalKadmin;
 import org.apache.kerby.kerberos.tool.kadmin.ToolUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class AddPrincipalsCommand extends KadminCommand {
+    private static final Logger LOG = LoggerFactory.getLogger(AddPrincipalsCommand.class);
     private static final String USAGE = "Usage: add_principals [options]\n"
             + "\toptions are:\n"
             + "[-pwexpire pwexpdate] [-maxlife maxtixlife]\n"
@@ -86,7 +89,8 @@ public class AddPrincipalsCommand extends KadminCommand {
         try {
             existNumbers = getKadmin().size();
         } catch (KrbException e) {
-            e.printStackTrace();
+            LOG.info("Fail to get the principal size. " + e);
+            System.out.println("Fail to get the principal size.");
             return;
         }
 
@@ -102,7 +106,7 @@ public class AddPrincipalsCommand extends KadminCommand {
                 String password = "12";
                 getKadmin().addPrincipal(principalName, password, kOptions);
             } catch (KrbException e) {
-                e.printStackTrace();
+                LOG.error("Fail to add principal. " + e);
             }
             i++;
         }


Mime
View raw message