harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r447370 - in /incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth: internal/kerberos/v5/KDCRequest.java internal/kerberos/v5/KrbClient.java module/Krb5LoginModule.java
Date Mon, 18 Sep 2006 11:15:23 GMT
Author: smishura
Date: Mon Sep 18 04:15:22 2006
New Revision: 447370

URL: http://svn.apache.org/viewvc?view=rev&rev=447370
Log:
Move AS protocol logic to newly created KrbClient class

Added:
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/KrbClient.java
  (with props)
Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/KDCRequest.java
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/module/Krb5LoginModule.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/KDCRequest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/KDCRequest.java?view=diff&rev=447370&r1=447369&r2=447370
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/KDCRequest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/KDCRequest.java
Mon Sep 18 04:15:22 2006
@@ -60,21 +60,13 @@
 
     private final PrincipalName sname;
 
-    private KDCRequest(int msgType, PrincipalName cname, String realm,
+    KDCRequest(int msgType, PrincipalName cname, String realm,
             PrincipalName sname) {
 
         this.msgType = msgType;
         this.cname = cname;
         this.realm = realm;
         this.sname = sname;
-    }
-
-    public static KDCRequest createASRequest(PrincipalName cname, String realm) {
-
-        PrincipalName krbtgt = new PrincipalName(PrincipalName.NT_SRV_XHST,
-                new String[] { "krbtgt", realm }); //$NON-NLS-1$
-
-        return new KDCRequest(AS_REQ, cname, realm, krbtgt);
     }
 
     public DatagramSocket send(InetAddress address, int port)

Added: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/KrbClient.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/KrbClient.java?view=auto&rev=447370
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/KrbClient.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/KrbClient.java
Mon Sep 18 04:15:22 2006
@@ -0,0 +1,95 @@
+/*
+ *  Copyright 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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.harmony.auth.internal.kerberos.v5;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.InetAddress;
+
+import org.apache.harmony.auth.internal.nls.Messages;
+import org.apache.harmony.security.asn1.DerInputStream;
+
+/**
+ * TODO comment me
+ * 
+ * @see http://www.ietf.org/rfc/rfc4120.txt
+ */
+public class KrbClient {
+
+    private static final int BUF_SIZE = 1024;
+
+    private KrbClient() {
+        // no objects
+    }
+
+    /**
+     * Get credentials from Authentication Service.
+     * 
+     * @param address -
+     *            service host
+     * @param port -
+     *            service port
+     * @param cname -
+     *            client's principal identifier
+     * @param realm -
+     *            client's realm
+     * @return - ticket
+     */
+    public static Ticket doAS(InetAddress address, int port,
+            PrincipalName cname, String realm, PrincipalName sname) {
+
+        KDCRequest request = new KDCRequest(KDCRequest.AS_REQ, cname, realm,
+                sname);
+
+        try {
+            DatagramSocket socket = request.send(address, port);
+
+            ByteArrayOutputStream out = new ByteArrayOutputStream(BUF_SIZE);
+
+            byte[] buf = new byte[BUF_SIZE];
+
+            DatagramPacket resp = new DatagramPacket(buf, buf.length);
+
+            int bytesRead = BUF_SIZE;
+            while (bytesRead == BUF_SIZE) {
+                socket.receive(resp);
+
+                bytesRead = resp.getLength();
+                out.write(buf, resp.getOffset(), bytesRead);
+            }
+            DerInputStream in = new DerInputStream(out.toByteArray());
+
+            if (in.tag == KDCReply.AS_REP_ASN1.constrId) { //TODO AS reply
+                throw new RuntimeException();//FIXME
+            } else if (in.tag == KerberosErrorMessage.ASN1.constrId) {
+                KerberosErrorMessage errMsg = KerberosErrorMessage.decode(in);
+                // auth.52=Error code: {0}
+                throw new RuntimeException(Messages.getString(
+                        "auth.52", errMsg.getErrorCode())); //$NON-NLS-1$
+            } else {
+                new RuntimeException(); //FIXME
+            }
+
+        } catch (IOException e) {
+            new RuntimeException(); //FIXME 
+        }
+
+        return null;
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/KrbClient.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/module/Krb5LoginModule.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/module/Krb5LoginModule.java?view=diff&rev=447370&r1=447369&r2=447370
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/module/Krb5LoginModule.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/module/Krb5LoginModule.java
Mon Sep 18 04:15:22 2006
@@ -16,12 +16,7 @@
 
 package org.apache.harmony.auth.module;
 
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.net.DatagramPacket;
-import java.net.DatagramSocket;
 import java.net.InetAddress;
-import java.net.UnknownHostException;
 import java.util.Map;
 
 import javax.security.auth.Subject;
@@ -29,17 +24,12 @@
 import javax.security.auth.login.LoginException;
 import javax.security.auth.spi.LoginModule;
 
-import org.apache.harmony.auth.internal.kerberos.v5.KDCReply;
-import org.apache.harmony.auth.internal.kerberos.v5.KDCRequest;
-import org.apache.harmony.auth.internal.kerberos.v5.KerberosErrorMessage;
+import org.apache.harmony.auth.internal.kerberos.v5.KrbClient;
 import org.apache.harmony.auth.internal.kerberos.v5.PrincipalName;
-import org.apache.harmony.auth.internal.nls.Messages;
-import org.apache.harmony.security.asn1.DerInputStream;
+import org.apache.harmony.auth.internal.kerberos.v5.Ticket;
 
 public class Krb5LoginModule implements LoginModule {
 
-    private static final int BUF_SIZE = 1024;
-
     private static final String PRINCIPAL = "cname"; //$NON-NLS-1$
 
     private static final String REALM = "realm"; //$NON-NLS-1$
@@ -84,48 +74,19 @@
         PrincipalName cname = new PrincipalName(PrincipalName.NT_UNKNOWN,
                 new String[] { name });
 
-        KDCRequest request = KDCRequest.createASRequest(cname, realm);
+        PrincipalName krbtgt = new PrincipalName(PrincipalName.NT_SRV_XHST,
+                new String[] { "krbtgt", realm }); //$NON-NLS-1$
 
         try {
-            DatagramSocket socket = request.send(InetAddress.getByName(kdc),
-                    port);
-
-            ByteArrayOutputStream out = new ByteArrayOutputStream(BUF_SIZE);
-
-            byte[] buf = new byte[BUF_SIZE];
-
-            DatagramPacket resp = new DatagramPacket(buf, buf.length);
-
-            int bytesRead = BUF_SIZE;
-            while (bytesRead == BUF_SIZE) {
-                socket.receive(resp);
-
-                bytesRead = resp.getLength();
-                out.write(buf, resp.getOffset(), bytesRead);
-            }
-
-            DerInputStream in = new DerInputStream(out.toByteArray());
-
-            if (in.tag == KDCReply.AS_REP_ASN1.constrId) { //TODO AS reply
-                throw new RuntimeException();//FIXME
-            } else if (in.tag == KerberosErrorMessage.ASN1.constrId) {
-                KerberosErrorMessage errMsg = KerberosErrorMessage.decode(in);
-                // auth.52=Error code: {0}
-                throw new LoginException(Messages.getString("auth.52", errMsg.getErrorCode()));
//$NON-NLS-1$
-            } else {
-                new LoginException(); //FIXME message
-            }
-
-        } catch (UnknownHostException e) {
-            LoginException ex = new LoginException();
-            ex.initCause(e);
-            throw ex;
-        } catch (IOException e) {
+            Ticket ticket = KrbClient.doAS(InetAddress.getByName(kdc), port,
+                    cname, realm, krbtgt);
+            
+            return true; //FIXME 
+        } catch (Exception e) {
             LoginException ex = new LoginException();
             ex.initCause(e);
             throw ex;
         }
-        return false;
     }
 
     public boolean logout() throws LoginException {



Mime
View raw message