harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r440671 [1/2] - in /incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java: common/javax/security/auth/ common/javax/security/auth/callback/ common/javax/security/auth/kerberos/ common/javax/security/auth/login/ common/javax/s...
Date Wed, 06 Sep 2006 09:39:29 GMT
Author: smishura
Date: Wed Sep  6 02:39:27 2006
New Revision: 440671

URL: http://svn.apache.org/viewvc?view=rev&rev=440671
Log:
Set eol-style=native

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/AuthPermission.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/DestroyFailedException.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/Destroyable.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/Policy.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/PrivateCredentialPermission.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/RefreshFailedException.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/Refreshable.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/Subject.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/SubjectDomainCombiner.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/callback/Callback.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/callback/CallbackHandler.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/callback/ChoiceCallback.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/callback/ConfirmationCallback.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/callback/LanguageCallback.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/callback/NameCallback.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/callback/PasswordCallback.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/callback/TextInputCallback.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/callback/TextOutputCallback.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/callback/UnsupportedCallbackException.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/kerberos/DelegationPermission.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/kerberos/KerberosKey.java   (contents, props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/kerberos/KerberosTicket.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/kerberos/ServicePermission.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/login/AccountException.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/login/AccountExpiredException.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/login/AccountLockedException.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/login/AccountNotFoundException.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/login/Configuration.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/login/CredentialException.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/login/CredentialExpiredException.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/login/CredentialNotFoundException.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/login/FailedLoginException.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/login/LoginContext.java   (contents, props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/login/LoginException.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/x500/X500PrivateCredential.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/sasl/AuthenticationException.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/sasl/AuthorizeCallback.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/sasl/RealmCallback.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/sasl/RealmChoiceCallback.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/sasl/Sasl.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/sasl/SaslClient.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/sasl/SaslClientFactory.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/sasl/SaslException.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/sasl/SaslServer.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/sasl/SaslServerFactory.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/linux/org/apache/harmony/auth/module/UnixLoginModule.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/windows/org/apache/harmony/auth/NTNumericCredential.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/windows/org/apache/harmony/auth/module/NTLoginModule.java   (props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/windows/org/apache/harmony/auth/module/NTSystem.java   (contents, props changed)

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/AuthPermission.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/DestroyFailedException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/Destroyable.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/Policy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/PrivateCredentialPermission.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/RefreshFailedException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/Refreshable.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/Subject.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/SubjectDomainCombiner.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/callback/Callback.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/callback/CallbackHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/callback/ChoiceCallback.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/callback/ConfirmationCallback.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/callback/LanguageCallback.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/callback/NameCallback.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/callback/PasswordCallback.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/callback/TextInputCallback.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/callback/TextOutputCallback.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/callback/UnsupportedCallbackException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/kerberos/DelegationPermission.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/kerberos/KerberosKey.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/kerberos/KerberosKey.java?view=diff&rev=440671&r1=440670&r2=440671
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/kerberos/KerberosKey.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/kerberos/KerberosKey.java Wed Sep  6 02:39:27 2006
@@ -1,444 +1,444 @@
-/*
- *  Copyright 2005 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.
- */
-
-/**
-* @author Maxim V. Makarov
-* @version $Revision$
-*/
-
-package javax.security.auth.kerberos;
-
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-import java.util.Arrays;
-
-import javax.crypto.Cipher;
-import javax.crypto.SecretKey;
-import javax.crypto.spec.IvParameterSpec;
-import javax.crypto.spec.SecretKeySpec;
-import javax.security.auth.DestroyFailedException;
-import javax.security.auth.Destroyable;
-
-import org.apache.harmony.security.utils.Array;
-
-/**
- * @com.intel.drl.spec_ref
- * 
- * @see http://www.ietf.org/rfc/rfc3961.txt
- */
-public class KerberosKey implements SecretKey, Destroyable {
-
-    private static final long serialVersionUID = -4625402278148246993L;
-    
-    //principal    
-    private KerberosPrincipal principal;
-
-    //key version number
-    private int versionNum;
-    
-    //raw bytes for the sicret key
-    private KeyImpl key;
-    
-    // indicates the ticket state
-    private transient boolean destroyed;
-    
-    
-    
-    /**
-     * @com.intel.drl.spec_ref
-     */
-    public KerberosKey(KerberosPrincipal principal, byte[] keyBytes,
-                       int keyType, int versionNumber) {
-
-        if (keyBytes == null) {
-            throw new NullPointerException("key is null");
-        }
-
-        this.principal = principal;
-        this.versionNum = versionNumber;
-        
-        this.key = new KeyImpl(keyBytes, keyType);
-        
-    }
-    
-    /**
-     * @com.intel.drl.spec_ref
-     */
-    public KerberosKey(KerberosPrincipal principal, char[] password,
-                       String algorithm) {
-        
-        this.principal = principal;
-
-        this.key = new KeyImpl(principal, password, algorithm);
-    }
-    
-    /**
-     * @com.intel.drl.spec_ref
-     */
-    public final KerberosPrincipal getPrincipal() {
-        checkState();
-        return principal;
-    }
-    
-    /**
-     * @com.intel.drl.spec_ref
-     */
-    public final String getAlgorithm() {
-        return key.getAlgorithm();
-    }
-
-    /**
-     * @com.intel.drl.spec_ref
-     */
-    public final String getFormat() {
-        return key.getFormat();
-    }
-
-    /**
-     * @com.intel.drl.spec_ref
-     */
-    public final int getKeyType() {
-        return key.getKeyType();
-    }  
-    /**
-     * @com.intel.drl.spec_ref
-     */
-    public final byte[] getEncoded() {
-        return key.getEncoded();
-    }
-    
-    /**
-     * @com.intel.drl.spec_ref
-     */
-    public final int getVersionNumber()  {
-        checkState();
-        return versionNum;
-    } 
-
-    /**
-     * @com.intel.drl.spec_ref
-     */
-    public void destroy() throws DestroyFailedException {
-        if (!destroyed) {
-            this.principal = null;
-            key.destroy();
-            this.destroyed = true;
-        }
-    }
-
-    /**
-     * @com.intel.drl.spec_ref
-     */
-    public boolean isDestroyed() {
-        return destroyed;
-    }
-
-    /**
-     * @com.intel.drl.spec_ref
-     */
-    public String toString() {
-        checkState();
-        StringBuffer sb = new StringBuffer();
-        sb.append("KerberosPrincipal ").append(principal.getName()).append("\n");
-        sb.append("KeyVersion ").append(versionNum).append("\n");
-        sb.append(key.toString());
-        return sb.toString();
-    } 
-    
-    // if a key is destroyed then IllegalStateException must be thrown 
-    private void checkState() {
-        if (destroyed) {
-            throw new IllegalStateException ("The key is destroyed");
-        }
-    }
-}
-
-/**
- * This class encapsulates a Kerberos encryption key.
- * 
- */
-class KeyImpl implements SecretKey, Destroyable, Serializable {
-
-    private static final long serialVersionUID = -7889313790214321193L;
-    
-    private transient byte[] keyBytes;
-
-    private transient int keyType;
-    
-    //  indicates the ticket state
-    private transient boolean destroyed;
-
-    // Pre-calculated parity values 
-    // TODO the alternative for boolean table - any acceptable algorithm?
-    private final static boolean[] PARITY = new boolean[] { false, true, true,
-            false, true, false, false, true, true, false, false, true, false,
-            true, true, false, true, false, false, true, false, true, true,
-            false, false, true, true, false, true, false, false, true, true,
-            false, false, true, false, true, true, false, false, true, true,
-            false, true, false, false, true, false, true, true, false, true,
-            false, false, true, true, false, false, true, false, true, true,
-            false, true, false, false, true, false, true, true, false, false,
-            true, true, false, true, false, false, true, false, true, true,
-            false, true, false, false, true, true, false, false, true, false,
-            true, true, false, false, true, true, false, true, false, false,
-            true, true, false, false, true, false, true, true, false, true,
-            false, false, true, false, true, true, false, false, true, true,
-            false, true, false, false, true, true, false, false, true, false,
-            true, true, false, false, true, true, false, true, false, false,
-            true, false, true, true, false, true, false, false, true, true,
-            false, false, true, false, true, true, false, false, true, true,
-            false, true, false, false, true, true, false, false, true, false,
-            true, true, false, true, false, false, true, false, true, true,
-            false, false, true, true, false, true, false, false, true, false,
-            true, true, false, true, false, false, true, true, false, false,
-            true, false, true, true, false, true, false, false, true, false,
-            true, true, false, false, true, true, false, true, false, false,
-            true, true, false, false, true, false, true, true, false, false,
-            true, true, false, true, false, false, true, false, true, true,
-            false, true, false, false, true, true, false, false, true, false,
-            true, true, false };
-
-    // Pre-calculated reversed values 
-    // TODO any acceptable alternative algorithm instead of table?
-    private static final byte[] REVERSE = new byte[] { 0, 64, 32, 96, 16, 80,
-            48, 112, 8, 72, 40, 104, 24, 88, 56, 120, 4, 68, 36, 100, 20, 84,
-            52, 116, 12, 76, 44, 108, 28, 92, 60, 124, 2, 66, 34, 98, 18, 82,
-            50, 114, 10, 74, 42, 106, 26, 90, 58, 122, 6, 70, 38, 102, 22, 86,
-            54, 118, 14, 78, 46, 110, 30, 94, 62, 126, 1, 65, 33, 97, 17, 81,
-            49, 113, 9, 73, 41, 105, 25, 89, 57, 121, 5, 69, 37, 101, 21, 85,
-            53, 117, 13, 77, 45, 109, 29, 93, 61, 125, 3, 67, 35, 99, 19, 83,
-            51, 115, 11, 75, 43, 107, 27, 91, 59, 123, 7, 71, 39, 103, 23, 87,
-            55, 119, 15, 79, 47, 111, 31, 95, 63, 127 };
-
-    /**
-     * creates a secret key from a given raw bytes
-     * 
-     * @param keyBytes
-     * @param keyType
-     */
-    public KeyImpl(byte[] keyBytes, int keyType) {
-        this.keyBytes = new byte[keyBytes.length];
-        System.arraycopy(keyBytes , 0, this.keyBytes, 0, this.keyBytes.length); 
-        this.keyType = keyType;
-    }
-    /**
-     * creates a secret key from a given password
-     * 
-     * @param principal
-     * @param password
-     * @param algorithm
-     */
-    public KeyImpl(KerberosPrincipal principal, char[] password, String algorithm) {
-
-        //
-        // See http://www.ietf.org/rfc/rfc3961.txt for algorithm description
-        //
-        
-        if (principal == null || password == null) {
-            throw new NullPointerException();
-        }
-
-        if (algorithm != null && "DES".compareTo(algorithm) != 0) {
-            throw new IllegalArgumentException("Unsupported algorithm");
-        }
-
-        keyType = 3; // DES algorithm
-        keyBytes = new byte[8];
-        
-        String realm = principal.getRealm();
-        String pname = principal.getName();
-
-        StringBuffer buf = new StringBuffer();
-        buf.append(password);
-        buf.append(realm);
-        buf.append(pname.substring(0, pname.length() - realm.length() - 1));
-
-        byte[] tmp = buf.toString().getBytes();
-
-        // pad with 0x00 to 8 byte boundary
-        byte[] raw = new byte[tmp.length
-                + ((tmp.length % 8) == 0 ? 0 : (8 - tmp.length % 8))];
-        System.arraycopy(tmp, 0, raw, 0, tmp.length);
-
-        long k1, k2 = 0;
-        boolean isOdd = false;
-        // for each 8-byte block in raw byte array
-        for (int i = 0; i < raw.length; i = i + 8, isOdd = !isOdd) {
-
-            k1 = 0;
-            if (isOdd) {
-                //reverse
-                for (int j = 7; j > -1; j--) {
-                    k1 = (k1 << 7) + REVERSE[raw[i + j] & 0x7F];
-                }
-            } else {
-                for (int j = 0; j < 8; j++) {
-                    k1 = (k1 << 7) + (raw[i + j] & 0x7F);
-                }
-            }
-            k2 = k2 ^ k1;
-        }
-        
-        // 56-bit long to byte array (8 bytes)
-        for (int i = 7; i > -1; i--) {
-            keyBytes[i] = (byte) k2;
-            keyBytes[i] = (byte) (keyBytes[i] << 1);
-            k2 = k2 >> 7;
-        }
-        keyCorrection(keyBytes);
-
-        // calculate DES-CBC check sum
-        try {
-            Cipher cipher = Cipher.getInstance("DES/CBC/NoPadding");
-
-            // use tmp key as IV
-            IvParameterSpec IV = new IvParameterSpec(keyBytes);
-
-            // do DES encryption 
-            SecretKey secretKey = new SecretKeySpec(keyBytes, "DES");
-            cipher.init(Cipher.ENCRYPT_MODE, secretKey, IV);
-            byte[] enc = cipher.doFinal(raw);
-
-            // final last block is check sum
-            System.arraycopy(enc, enc.length - 8, keyBytes, 0, 8);
-            
-            keyCorrection(keyBytes);
-
-        } catch (Exception e) {
-            throw new RuntimeException(
-                    "Failed to generate DES key from password.", e);
-        }
-    }
-
-    private void keyCorrection(byte[] key) {
-        
-        // fix parity
-        for (int i = 0; i < 8; i++) {
-            if (!PARITY[key[i] & 0xFF]) {
-                if ((key[i] & 0x01) == 0) {
-                    key[i]++;
-                } else {
-                    key[i]--;
-                }
-            }
-        }
-        
-        // TODO if is week do XOR
-        //if(DESKeySpec.isWeak(keyBytes,0)){
-        //}
-    }
-
-    /**
-     * Method is described in 
-     * <code>getAlgorithm</code> in interface <code>Key</code>
-     */
-    public final String getAlgorithm() {
-        checkState();
-        if (keyType == 0) {
-            return "NULL";
-        }
-        return "DES";
-    }
-    
-    /**
-     * Method is described in
-     * <code>getFormat</code> in interface <code>Key</code>
-     */
-    public final String getFormat() {
-        checkState();
-        return "RAW";
-    }
-   
-    /**
-     * Method is described in
-     * <code>getEncoded</code> in interface <code>Key</code>
-     */
-    public final byte[] getEncoded() {
-        checkState();
-        byte[] tmp = new byte[keyBytes.length];
-        System.arraycopy(keyBytes, 0, tmp, 0, tmp.length);
-        return tmp;
-    }
-
-    /**
-     * Returns the key type for this key
-     */
-    public final int getKeyType() {
-        checkState();
-        return keyType;
-    }
-
-    /**
-     * Destroys this key
-     */
-    public void destroy() throws DestroyFailedException {
-        if (!destroyed) {
-            Arrays.fill(keyBytes, (byte) 0); 
-            destroyed = true;
-        }
-        
-    }
-    /**
-     * Determines if this key has been destroyed 
-     */
-   public boolean isDestroyed() {
-        return destroyed;
-    }
-
-   /**
-    * A string representation of this key
-    */
-   public String toString() {
-       String s_key = null;
-       StringBuffer sb = new StringBuffer();
-       
-       if (keyBytes.length == 0) {
-           s_key = "Empty Key";
-       } else {
-           s_key = Array.toString(keyBytes," ");
-       }
-       sb.append("EncryptionKey: ").append("KeyType = ").append(keyType);
-       sb.append("KeyBytes (Hex dump) = ").append(s_key);
-       return sb.toString();
-   }
-   
-   /**
-    * if a key is destroyed then IllegalStateException should be thrown
-    */  
-   private void checkState() {
-       if (destroyed) {
-           throw new IllegalStateException ("The key is destroyed");
-       }
-   }
-
-   // TODO: read a object from a stream
-   private void readObject(ObjectInputStream s) throws IOException,
-       ClassNotFoundException {
-       s.defaultReadObject();
-   }
-
-   // TODO: write a object to a stream
-   private void writeObject(ObjectOutputStream s) throws IOException {
-       
-       if(destroyed){
-           throw new IOException("Key was destroyed");
-       }
-       s.defaultWriteObject();
-   }
-
+/*
+ *  Copyright 2005 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.
+ */
+
+/**
+* @author Maxim V. Makarov
+* @version $Revision$
+*/
+
+package javax.security.auth.kerberos;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.util.Arrays;
+
+import javax.crypto.Cipher;
+import javax.crypto.SecretKey;
+import javax.crypto.spec.IvParameterSpec;
+import javax.crypto.spec.SecretKeySpec;
+import javax.security.auth.DestroyFailedException;
+import javax.security.auth.Destroyable;
+
+import org.apache.harmony.security.utils.Array;
+
+/**
+ * @com.intel.drl.spec_ref
+ * 
+ * @see http://www.ietf.org/rfc/rfc3961.txt
+ */
+public class KerberosKey implements SecretKey, Destroyable {
+
+    private static final long serialVersionUID = -4625402278148246993L;
+    
+    //principal    
+    private KerberosPrincipal principal;
+
+    //key version number
+    private int versionNum;
+    
+    //raw bytes for the sicret key
+    private KeyImpl key;
+    
+    // indicates the ticket state
+    private transient boolean destroyed;
+    
+    
+    
+    /**
+     * @com.intel.drl.spec_ref
+     */
+    public KerberosKey(KerberosPrincipal principal, byte[] keyBytes,
+                       int keyType, int versionNumber) {
+
+        if (keyBytes == null) {
+            throw new NullPointerException("key is null");
+        }
+
+        this.principal = principal;
+        this.versionNum = versionNumber;
+        
+        this.key = new KeyImpl(keyBytes, keyType);
+        
+    }
+    
+    /**
+     * @com.intel.drl.spec_ref
+     */
+    public KerberosKey(KerberosPrincipal principal, char[] password,
+                       String algorithm) {
+        
+        this.principal = principal;
+
+        this.key = new KeyImpl(principal, password, algorithm);
+    }
+    
+    /**
+     * @com.intel.drl.spec_ref
+     */
+    public final KerberosPrincipal getPrincipal() {
+        checkState();
+        return principal;
+    }
+    
+    /**
+     * @com.intel.drl.spec_ref
+     */
+    public final String getAlgorithm() {
+        return key.getAlgorithm();
+    }
+
+    /**
+     * @com.intel.drl.spec_ref
+     */
+    public final String getFormat() {
+        return key.getFormat();
+    }
+
+    /**
+     * @com.intel.drl.spec_ref
+     */
+    public final int getKeyType() {
+        return key.getKeyType();
+    }  
+    /**
+     * @com.intel.drl.spec_ref
+     */
+    public final byte[] getEncoded() {
+        return key.getEncoded();
+    }
+    
+    /**
+     * @com.intel.drl.spec_ref
+     */
+    public final int getVersionNumber()  {
+        checkState();
+        return versionNum;
+    } 
+
+    /**
+     * @com.intel.drl.spec_ref
+     */
+    public void destroy() throws DestroyFailedException {
+        if (!destroyed) {
+            this.principal = null;
+            key.destroy();
+            this.destroyed = true;
+        }
+    }
+
+    /**
+     * @com.intel.drl.spec_ref
+     */
+    public boolean isDestroyed() {
+        return destroyed;
+    }
+
+    /**
+     * @com.intel.drl.spec_ref
+     */
+    public String toString() {
+        checkState();
+        StringBuffer sb = new StringBuffer();
+        sb.append("KerberosPrincipal ").append(principal.getName()).append("\n");
+        sb.append("KeyVersion ").append(versionNum).append("\n");
+        sb.append(key.toString());
+        return sb.toString();
+    } 
+    
+    // if a key is destroyed then IllegalStateException must be thrown 
+    private void checkState() {
+        if (destroyed) {
+            throw new IllegalStateException ("The key is destroyed");
+        }
+    }
+}
+
+/**
+ * This class encapsulates a Kerberos encryption key.
+ * 
+ */
+class KeyImpl implements SecretKey, Destroyable, Serializable {
+
+    private static final long serialVersionUID = -7889313790214321193L;
+    
+    private transient byte[] keyBytes;
+
+    private transient int keyType;
+    
+    //  indicates the ticket state
+    private transient boolean destroyed;
+
+    // Pre-calculated parity values 
+    // TODO the alternative for boolean table - any acceptable algorithm?
+    private final static boolean[] PARITY = new boolean[] { false, true, true,
+            false, true, false, false, true, true, false, false, true, false,
+            true, true, false, true, false, false, true, false, true, true,
+            false, false, true, true, false, true, false, false, true, true,
+            false, false, true, false, true, true, false, false, true, true,
+            false, true, false, false, true, false, true, true, false, true,
+            false, false, true, true, false, false, true, false, true, true,
+            false, true, false, false, true, false, true, true, false, false,
+            true, true, false, true, false, false, true, false, true, true,
+            false, true, false, false, true, true, false, false, true, false,
+            true, true, false, false, true, true, false, true, false, false,
+            true, true, false, false, true, false, true, true, false, true,
+            false, false, true, false, true, true, false, false, true, true,
+            false, true, false, false, true, true, false, false, true, false,
+            true, true, false, false, true, true, false, true, false, false,
+            true, false, true, true, false, true, false, false, true, true,
+            false, false, true, false, true, true, false, false, true, true,
+            false, true, false, false, true, true, false, false, true, false,
+            true, true, false, true, false, false, true, false, true, true,
+            false, false, true, true, false, true, false, false, true, false,
+            true, true, false, true, false, false, true, true, false, false,
+            true, false, true, true, false, true, false, false, true, false,
+            true, true, false, false, true, true, false, true, false, false,
+            true, true, false, false, true, false, true, true, false, false,
+            true, true, false, true, false, false, true, false, true, true,
+            false, true, false, false, true, true, false, false, true, false,
+            true, true, false };
+
+    // Pre-calculated reversed values 
+    // TODO any acceptable alternative algorithm instead of table?
+    private static final byte[] REVERSE = new byte[] { 0, 64, 32, 96, 16, 80,
+            48, 112, 8, 72, 40, 104, 24, 88, 56, 120, 4, 68, 36, 100, 20, 84,
+            52, 116, 12, 76, 44, 108, 28, 92, 60, 124, 2, 66, 34, 98, 18, 82,
+            50, 114, 10, 74, 42, 106, 26, 90, 58, 122, 6, 70, 38, 102, 22, 86,
+            54, 118, 14, 78, 46, 110, 30, 94, 62, 126, 1, 65, 33, 97, 17, 81,
+            49, 113, 9, 73, 41, 105, 25, 89, 57, 121, 5, 69, 37, 101, 21, 85,
+            53, 117, 13, 77, 45, 109, 29, 93, 61, 125, 3, 67, 35, 99, 19, 83,
+            51, 115, 11, 75, 43, 107, 27, 91, 59, 123, 7, 71, 39, 103, 23, 87,
+            55, 119, 15, 79, 47, 111, 31, 95, 63, 127 };
+
+    /**
+     * creates a secret key from a given raw bytes
+     * 
+     * @param keyBytes
+     * @param keyType
+     */
+    public KeyImpl(byte[] keyBytes, int keyType) {
+        this.keyBytes = new byte[keyBytes.length];
+        System.arraycopy(keyBytes , 0, this.keyBytes, 0, this.keyBytes.length); 
+        this.keyType = keyType;
+    }
+    /**
+     * creates a secret key from a given password
+     * 
+     * @param principal
+     * @param password
+     * @param algorithm
+     */
+    public KeyImpl(KerberosPrincipal principal, char[] password, String algorithm) {
+
+        //
+        // See http://www.ietf.org/rfc/rfc3961.txt for algorithm description
+        //
+        
+        if (principal == null || password == null) {
+            throw new NullPointerException();
+        }
+
+        if (algorithm != null && "DES".compareTo(algorithm) != 0) {
+            throw new IllegalArgumentException("Unsupported algorithm");
+        }
+
+        keyType = 3; // DES algorithm
+        keyBytes = new byte[8];
+        
+        String realm = principal.getRealm();
+        String pname = principal.getName();
+
+        StringBuffer buf = new StringBuffer();
+        buf.append(password);
+        buf.append(realm);
+        buf.append(pname.substring(0, pname.length() - realm.length() - 1));
+
+        byte[] tmp = buf.toString().getBytes();
+
+        // pad with 0x00 to 8 byte boundary
+        byte[] raw = new byte[tmp.length
+                + ((tmp.length % 8) == 0 ? 0 : (8 - tmp.length % 8))];
+        System.arraycopy(tmp, 0, raw, 0, tmp.length);
+
+        long k1, k2 = 0;
+        boolean isOdd = false;
+        // for each 8-byte block in raw byte array
+        for (int i = 0; i < raw.length; i = i + 8, isOdd = !isOdd) {
+
+            k1 = 0;
+            if (isOdd) {
+                //reverse
+                for (int j = 7; j > -1; j--) {
+                    k1 = (k1 << 7) + REVERSE[raw[i + j] & 0x7F];
+                }
+            } else {
+                for (int j = 0; j < 8; j++) {
+                    k1 = (k1 << 7) + (raw[i + j] & 0x7F);
+                }
+            }
+            k2 = k2 ^ k1;
+        }
+        
+        // 56-bit long to byte array (8 bytes)
+        for (int i = 7; i > -1; i--) {
+            keyBytes[i] = (byte) k2;
+            keyBytes[i] = (byte) (keyBytes[i] << 1);
+            k2 = k2 >> 7;
+        }
+        keyCorrection(keyBytes);
+
+        // calculate DES-CBC check sum
+        try {
+            Cipher cipher = Cipher.getInstance("DES/CBC/NoPadding");
+
+            // use tmp key as IV
+            IvParameterSpec IV = new IvParameterSpec(keyBytes);
+
+            // do DES encryption 
+            SecretKey secretKey = new SecretKeySpec(keyBytes, "DES");
+            cipher.init(Cipher.ENCRYPT_MODE, secretKey, IV);
+            byte[] enc = cipher.doFinal(raw);
+
+            // final last block is check sum
+            System.arraycopy(enc, enc.length - 8, keyBytes, 0, 8);
+            
+            keyCorrection(keyBytes);
+
+        } catch (Exception e) {
+            throw new RuntimeException(
+                    "Failed to generate DES key from password.", e);
+        }
+    }
+
+    private void keyCorrection(byte[] key) {
+        
+        // fix parity
+        for (int i = 0; i < 8; i++) {
+            if (!PARITY[key[i] & 0xFF]) {
+                if ((key[i] & 0x01) == 0) {
+                    key[i]++;
+                } else {
+                    key[i]--;
+                }
+            }
+        }
+        
+        // TODO if is week do XOR
+        //if(DESKeySpec.isWeak(keyBytes,0)){
+        //}
+    }
+
+    /**
+     * Method is described in 
+     * <code>getAlgorithm</code> in interface <code>Key</code>
+     */
+    public final String getAlgorithm() {
+        checkState();
+        if (keyType == 0) {
+            return "NULL";
+        }
+        return "DES";
+    }
+    
+    /**
+     * Method is described in
+     * <code>getFormat</code> in interface <code>Key</code>
+     */
+    public final String getFormat() {
+        checkState();
+        return "RAW";
+    }
+   
+    /**
+     * Method is described in
+     * <code>getEncoded</code> in interface <code>Key</code>
+     */
+    public final byte[] getEncoded() {
+        checkState();
+        byte[] tmp = new byte[keyBytes.length];
+        System.arraycopy(keyBytes, 0, tmp, 0, tmp.length);
+        return tmp;
+    }
+
+    /**
+     * Returns the key type for this key
+     */
+    public final int getKeyType() {
+        checkState();
+        return keyType;
+    }
+
+    /**
+     * Destroys this key
+     */
+    public void destroy() throws DestroyFailedException {
+        if (!destroyed) {
+            Arrays.fill(keyBytes, (byte) 0); 
+            destroyed = true;
+        }
+        
+    }
+    /**
+     * Determines if this key has been destroyed 
+     */
+   public boolean isDestroyed() {
+        return destroyed;
+    }
+
+   /**
+    * A string representation of this key
+    */
+   public String toString() {
+       String s_key = null;
+       StringBuffer sb = new StringBuffer();
+       
+       if (keyBytes.length == 0) {
+           s_key = "Empty Key";
+       } else {
+           s_key = Array.toString(keyBytes," ");
+       }
+       sb.append("EncryptionKey: ").append("KeyType = ").append(keyType);
+       sb.append("KeyBytes (Hex dump) = ").append(s_key);
+       return sb.toString();
+   }
+   
+   /**
+    * if a key is destroyed then IllegalStateException should be thrown
+    */  
+   private void checkState() {
+       if (destroyed) {
+           throw new IllegalStateException ("The key is destroyed");
+       }
+   }
+
+   // TODO: read a object from a stream
+   private void readObject(ObjectInputStream s) throws IOException,
+       ClassNotFoundException {
+       s.defaultReadObject();
+   }
+
+   // TODO: write a object to a stream
+   private void writeObject(ObjectOutputStream s) throws IOException {
+       
+       if(destroyed){
+           throw new IOException("Key was destroyed");
+       }
+       s.defaultWriteObject();
+   }
+
 }

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/kerberos/KerberosKey.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/kerberos/KerberosTicket.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/kerberos/ServicePermission.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/login/AccountException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/login/AccountExpiredException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/login/AccountLockedException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/login/AccountNotFoundException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/login/Configuration.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/login/CredentialException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/login/CredentialExpiredException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/login/CredentialNotFoundException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/login/FailedLoginException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/login/LoginContext.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/login/LoginContext.java?view=diff&rev=440671&r1=440670&r2=440671
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/login/LoginContext.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/login/LoginContext.java Wed Sep  6 02:39:27 2006
@@ -1,571 +1,571 @@
-/*
- *  Copyright 2005 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.
- */
-
-/**
-* @author Alexander V. Astapchuk, Stepan M. Mishura
-* @version $Revision$
-*/
-
-package javax.security.auth.login;
-
-import java.io.IOException;
-import java.security.AccessController;
-import java.security.AccessControlContext;
-import java.security.PrivilegedExceptionAction;
-import java.security.PrivilegedActionException;
-
-import java.security.Security;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.security.auth.Subject;
-import javax.security.auth.callback.CallbackHandler;
-import javax.security.auth.callback.Callback;
-import javax.security.auth.callback.UnsupportedCallbackException;
-import javax.security.auth.spi.LoginModule;
-import javax.security.auth.AuthPermission;
-
-import javax.security.auth.login.AppConfigurationEntry.LoginModuleControlFlag;
-
-/**
- * @com.intel.drl.spec_ref
- */
-
-public class LoginContext {
-
-    private static final String DEFAULT_CALLBACK_HANDLER_PROPERTY = "auth.login.defaultCallbackHandler";
-
-    // Integer constants which serve as a replacement for 
-    // the corresponding LoginModuleControlFlag.* constants.
-    // These integers are used later as index in the arrays - see 
-    // loginImpl() and logoutImpl() methods
-    private static final int OPTIONAL = 0;
-
-    private static final int REQUIRED = 1;
-
-    private static final int REQUISITE = 2;
-
-    private static final int SUFFICIENT = 3;
-
-    // Subject to be used for this LoginContext's operations
-    private Subject subject;
-
-    // Shows whether the subject 
-    // was specified by user (true) or 
-    // was created by this LoginContext itself (false).
-    private boolean userProvidedSubject;
-
-    // Shows whether we use installed or user-provided Configuration
-    private boolean userProvidedConfig;
-
-    // An user's AccessControlContext, used when user specifies 
-    private AccessControlContext userContext;
-
-    // Either a callback handler passed by the user or a wrapper for the 
-    // user's specified handler - see init() below.
-    private CallbackHandler callbackHandler;
-
-    // An array which keeps the instantiated and init()-ialized login 
-    // modules and their states
-    private Module[] modules;
-
-    // Stores a shared state
-    private HashMap sharedState;
-
-    // A context class loader used to load [mainly] LoginModules
-    private ClassLoader contextClassLoader;
-
-    // Shows overall status - whether this LoginContext was successfully logged 
-    private boolean loggedIn;
-
-    /**
-     * @com.intel.drl.spec_ref
-     */
-    public LoginContext(String name) throws LoginException {
-        init(name, null, null, null);
-    }
-
-    /**
-     * @com.intel.drl.spec_ref
-     */
-    public LoginContext(String name, CallbackHandler cbHandler)
-            throws LoginException {
-        if (cbHandler == null) {
-            throw new LoginException("CallbackHandler can not be null");
-        }
-        init(name, null, cbHandler, null);
-    }
-
-    /**
-     * @com.intel.drl.spec_ref
-     */
-    public LoginContext(String name, Subject subject) throws LoginException {
-        if (subject == null) {
-            throw new LoginException("Subject can not be null");
-        }
-        init(name, subject, null, null);
-    }
-
-    /**
-     * @com.intel.drl.spec_ref
-     */
-    public LoginContext(String name, Subject subject, CallbackHandler cbHandler)
-            throws LoginException {
-        if (subject == null) {
-            throw new LoginException("Subject can not be null");
-        }
-        if (cbHandler == null) {
-            throw new LoginException("CallbackHandler can not be null");
-        }
-        init(name, subject, cbHandler, null);
-    }
-
-    /**
-     * @com.intel.drl.spec_ref
-     */
-    public LoginContext(String name, Subject subject,
-            CallbackHandler cbHandler, Configuration config)
-            throws LoginException {
-        init(name, subject, cbHandler, config);
-    }
-
-    // Does all the machinery needed for the initialization.
-    private void init(String name, Subject subject,
-            final CallbackHandler cbHandler, Configuration config)
-            throws LoginException {
-        //
-        //
-        //
-        userProvidedSubject = (this.subject = subject) != null;
-
-        //
-        // Set config
-        //
-        if (name == null) {
-            throw new LoginException("name can not be null");
-        }
-
-        if (config == null) {
-            config = Configuration.getAccessibleConfiguration();
-        } else {
-            userProvidedConfig = true;
-        }
-
-        SecurityManager sm = System.getSecurityManager();
-
-        if (sm != null && !userProvidedConfig) {
-            sm
-                    .checkPermission(new AuthPermission("createLoginContext."
-                            + name));
-        }
-
-        AppConfigurationEntry[] entries = config.getAppConfigurationEntry(name);
-        if (entries == null) {
-            if (sm != null && !userProvidedConfig) {
-                sm.checkPermission(new AuthPermission(
-                        "createLoginContext.other"));
-            }
-            entries = config.getAppConfigurationEntry("other");
-            if (entries == null) {
-                throw new LoginException("There is no \"" + name
-                        + "\" in Configuration or it's empty.");
-            }
-        }
-
-        modules = new Module[entries.length];
-        for (int i = 0; i < modules.length; i++) {
-            modules[i] = new Module(entries[i]);
-        }
-        //
-        // Set CallbackHandler and this.contextClassLoader
-        //
-
-        // as some of the operations to be executed (i.e. get*ClassLoader, 
-        // getProperty, class loading) are security-checked, then combine all 
-        // of them into a single doPrivileged() call.
-        //
-        try {
-            AccessController.doPrivileged(new PrivilegedExceptionAction() {
-                public Object run() throws Exception {
-                    // First, set the 'contextClassLoader'
-                    contextClassLoader = Thread.currentThread()
-                            .getContextClassLoader();
-                    if (contextClassLoader == null) {
-                        contextClassLoader = ClassLoader.getSystemClassLoader();
-                    }
-                    // then, checks whether the cbHandler is set
-                    if (cbHandler == null) {
-                        // well, let's try to find it
-                        String klassName = Security
-                                .getProperty(DEFAULT_CALLBACK_HANDLER_PROPERTY);
-                        if (klassName == null || klassName.length() == 0) {
-                            return null;
-                        }
-                        Class klass = Class.forName(klassName, true,
-                                contextClassLoader);
-                        callbackHandler = (CallbackHandler) klass.newInstance();
-                    } else {
-                        callbackHandler = cbHandler;
-                    }
-                    return null;
-                }
-            });
-        } catch (PrivilegedActionException ex) {
-            throw (LoginException) new LoginException(
-                    "Could not get default callback handler.").initCause(ex
-                    .getCause());
-        }
-
-        if (userProvidedConfig) {
-            userContext = AccessController.getContext();
-        } else if (callbackHandler != null) {
-            userContext = AccessController.getContext();
-            callbackHandler = new ContextedCallbackHandler(callbackHandler);
-        }
-    }
-
-    /**
-     * @com.intel.drl.spec_ref
-     */
-    public Subject getSubject() {
-        if (userProvidedSubject || loggedIn) {
-            return subject;
-        }
-        return null;
-    }
-
-    /**
-     * @com.intel.drl.spec_ref
-     */
-    public void login() throws LoginException {
-        PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
-            public Object run() throws LoginException {
-                loginImpl();
-                return null;
-            }
-        };
-        try {
-            if (userProvidedConfig) {
-                AccessController.doPrivileged(action, userContext);
-            } else {
-                AccessController.doPrivileged(action);
-            }
-        } catch (PrivilegedActionException ex) {
-            throw (LoginException) ex.getException();
-        }
-    }
-
-    // The real implementation of login() method whose calls are wrapped into 
-    // appropriate doPrivileged calls in login().
-    private void loginImpl() throws LoginException {
-        if (loggedIn) {
-            return;
-        }
-
-        if (subject == null) {
-            subject = new Subject();
-        }
-
-        if (sharedState == null) {
-            sharedState = new HashMap();
-        }
-
-        // PHASE 1: Calling login()-s
-        Throwable firstProblem = null;
-
-        int[] logged = new int[4];
-        int[] total = new int[4];
-
-        for (int i = 0; i < modules.length; i++) {
-            try {
-                // if a module fails during Class.forName(), then it breaks overall 
-                // attempt - see catch() below
-                modules[i].create(subject, callbackHandler, sharedState);
-
-                if (modules[i].module.login()) {
-                    ++total[modules[i].getFlag()];
-                    ++logged[modules[i].getFlag()];
-                    if (modules[i].getFlag() == SUFFICIENT) {
-                        break;
-                    }
-                }
-            } catch (Throwable ex) {
-                if (firstProblem == null) {
-                    firstProblem = ex;
-                }
-                if (modules[i].klass == null) {
-                    // an exception occured during class lookup - overall 
-                    // attempt must fail
-                    // a little trick: increase the REQUIRED's number - this 
-                    // will look like a failed REQUIRED module later, so overall 
-                    // attempt will fail
-                    ++total[REQUIRED];
-                    break;
-                } else {
-                    ++total[modules[i].getFlag()];
-                    // something happened after the class was loaded
-                    if (modules[i].getFlag() == REQUISITE) {
-                        // ... and no need to walk down anymore
-                        break;
-                    }
-                }
-            }
-        }
-        // end of PHASE1, 
-
-        // Let's decide whether we have either overall success or a total failure
-        boolean fail = true;
-
-        // Note: 'failed[xxx]!=0' is not enough to check.
-        // Use 'logged[xx] != total[xx]' instead.
-        // This is because some modules might not be counted as 'failed' if
-        // an exception occured during preload()/Class.forName()-ing.
-        // But, such modules still get counted in the total[]. 
-
-        //
-        // if any REQ* module failed - then it's failure
-        if (logged[REQUIRED] != total[REQUIRED]
-                || logged[REQUISITE] != total[REQUISITE]) {
-            // fail = true;
-        } else {
-            if (total[REQUIRED] == 0 && total[REQUISITE] == 0) {
-                // neither REQUIRED nor REQUISITE was configured.
-                // must have at least one SUFFICIENT or OPTIONAL
-                if (logged[OPTIONAL] != 0 || logged[SUFFICIENT] != 0) {
-                    fail = false;
-                }
-                //else { fail = true; }
-            } else {
-                fail = false;
-            }
-        }
-
-        int commited[] = new int[4];
-        // clear it
-        total[0] = total[1] = total[2] = total[3] = 0;
-        if (!fail) {
-            // PHASE 2: 
-            for (int i = 0; i < modules.length; i++) {
-                if (modules[i].klass != null) {
-                    ++total[modules[i].getFlag()];
-                    try {
-                        modules[i].module.commit();
-                        ++commited[modules[i].getFlag()];
-                    } catch (Throwable ex) {
-                        if (firstProblem == null) {
-                            firstProblem = ex;
-                        }
-                    }
-                }
-            }
-        }
-
-        // need to decide once again
-        fail = true;
-        if (commited[REQUIRED] != total[REQUIRED]
-                || commited[REQUISITE] != total[REQUISITE]) {
-            //fail = true;
-        } else {
-            if (total[REQUIRED] == 0 && total[REQUISITE] == 0) {
-                // neither REQUIRED nor REQUISITE was configured.
-                // must have at least one SUFFICIENT or OPTIONAL
-                if (commited[OPTIONAL] != 0 || commited[SUFFICIENT] != 0) {
-                    fail = false;
-                } else {
-                    //fail = true;
-                }
-            } else {
-                fail = false;
-            }
-        }
-
-        if (fail) {
-            // either login() or commit() failed. aborting... 
-            for (int i = 0; i < modules.length; i++) {
-                try {
-                    modules[i].module.abort();
-                } catch ( /*LoginException*/Throwable ex) {
-                    if (firstProblem == null) {
-                        firstProblem = ex;
-                    }
-                }
-            }
-            if (firstProblem instanceof PrivilegedActionException
-                    && firstProblem.getCause() != null) {
-                firstProblem = firstProblem.getCause();
-            }
-            if (firstProblem instanceof LoginException) {
-                throw (LoginException) firstProblem;
-            } else {
-                throw (LoginException) new LoginException(
-                        "Login attempt failed.").initCause(firstProblem);
-            }
-        } else {
-            loggedIn = true;
-        }
-        // return silently - we are logged in
-    }
-
-    /**
-     * @com.intel.drl.spec_ref
-     */
-    public void logout() throws LoginException {
-        PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
-            public Object run() throws LoginException {
-                logoutImpl();
-                return null;
-            }
-        };
-        try {
-            if (userProvidedConfig) {
-                AccessController.doPrivileged(action, userContext);
-            } else {
-                AccessController.doPrivileged(action);
-            }
-        } catch (PrivilegedActionException ex) {
-            throw (LoginException) ex.getException();
-        }
-    }
-
-    // The real implementation of logout() method whose calls are wrapped into 
-    // appropriate doPrivileged calls in logout().
-    private void logoutImpl() throws LoginException {
-        if (subject == null) {
-            throw new LoginException("This LoginContext is not logged.");
-        }
-        loggedIn = false;
-        Throwable firstProblem = null;
-        int total = 0;
-        for (int i = 0; i < modules.length; i++) {
-            try {
-                modules[i].module.logout();
-                ++total;
-            } catch (Throwable ex) {
-                if (firstProblem == null) {
-                    firstProblem = ex;
-                }
-            }
-        }
-        if (firstProblem != null || total == 0) {
-            if (firstProblem instanceof PrivilegedActionException
-                    && firstProblem.getCause() != null) {
-                firstProblem = firstProblem.getCause();
-            }
-            if (firstProblem instanceof LoginException) {
-                throw (LoginException) firstProblem;
-            } else {
-                throw (LoginException) new LoginException(
-                        "Login attempt failed.").initCause(firstProblem);
-            }
-        }
-    }
-
-    // A class that servers as a wrapper for the CallbackHandler when we use 
-    // installed Configuration, but not a passed one. See API docs on the 
-    // LoginContext.<br>
-    // Simply invokes the given handler with the given AccessControlContext. 
-    private class ContextedCallbackHandler implements CallbackHandler {
-        CallbackHandler hiddenHandlerRef;
-
-        ContextedCallbackHandler(CallbackHandler handler) {
-            this.hiddenHandlerRef = handler;
-        }
-
-        public void handle(final Callback[] callbacks) throws IOException,
-                UnsupportedCallbackException {
-            try {
-                AccessController.doPrivileged(new PrivilegedExceptionAction() {
-                    public Object run() throws IOException,
-                            UnsupportedCallbackException {
-                        hiddenHandlerRef.handle(callbacks);
-                        return null;
-                    }
-                }, userContext);
-            } catch (PrivilegedActionException ex) {
-                if (ex.getCause() instanceof UnsupportedCallbackException) {
-                    throw (UnsupportedCallbackException) ex.getCause();
-                }
-                throw (IOException) ex.getCause();
-            }
-        }
-    }
-
-    // A private class that stores an instantiated LoginModule.
-    private final class Module {
-
-        // An initial info about the module to be used
-        AppConfigurationEntry entry;
-
-        // A mapping of LoginModuleControlFlag onto a simple int constant
-        int flag;
-
-        // The LoginModule intself 
-        LoginModule module;
-
-        // A class of the module
-        Class klass;
-
-        Module(AppConfigurationEntry entry) {
-            this.entry = entry;
-            LoginModuleControlFlag flg = entry.getControlFlag();
-            if (flg == LoginModuleControlFlag.OPTIONAL) {
-                flag = OPTIONAL;
-            } else if (flg == LoginModuleControlFlag.REQUISITE) {
-                flag = REQUISITE;
-            } else if (flg == LoginModuleControlFlag.SUFFICIENT) {
-                flag = SUFFICIENT;
-            } else {
-                flag = REQUIRED;
-                //if(flg!=LoginModuleControlFlag.REQUIRED) throw new Error()
-            }
-        }
-
-        int getFlag() {
-            return flag;
-        }
-
-        // Loads class of the LoginModule, instantiates it and then 
-        // calls initialize().
-        void create(Subject subject, CallbackHandler callbackHandler,
-                Map sharedState) throws LoginException {
-            String klassName = entry.getLoginModuleName();
-            if (klass == null) {
-                try {
-                    klass = Class.forName(klassName, false, contextClassLoader);
-                } catch (ClassNotFoundException ex) {
-                    throw (LoginException) new LoginException(
-                            "Could not load module " + klassName).initCause(ex);
-                }
-            }
-
-            if (module == null) {
-                try {
-                    module = (LoginModule) klass.newInstance();
-                } catch (IllegalAccessException ex) {
-                    throw (LoginException) new LoginException(
-                            "Could not instantiate module " + klassName)
-                            .initCause(ex);
-                } catch (InstantiationException ex) {
-                    throw (LoginException) new LoginException(
-                            "Could not instantiate module " + klassName)
-                            .initCause(ex);
-                }
-                module.initialize(subject, callbackHandler, sharedState, entry
-                        .getOptions());
-            }
-        }
-    }
+/*
+ *  Copyright 2005 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.
+ */
+
+/**
+* @author Alexander V. Astapchuk, Stepan M. Mishura
+* @version $Revision$
+*/
+
+package javax.security.auth.login;
+
+import java.io.IOException;
+import java.security.AccessController;
+import java.security.AccessControlContext;
+import java.security.PrivilegedExceptionAction;
+import java.security.PrivilegedActionException;
+
+import java.security.Security;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.security.auth.Subject;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.UnsupportedCallbackException;
+import javax.security.auth.spi.LoginModule;
+import javax.security.auth.AuthPermission;
+
+import javax.security.auth.login.AppConfigurationEntry.LoginModuleControlFlag;
+
+/**
+ * @com.intel.drl.spec_ref
+ */
+
+public class LoginContext {
+
+    private static final String DEFAULT_CALLBACK_HANDLER_PROPERTY = "auth.login.defaultCallbackHandler";
+
+    // Integer constants which serve as a replacement for 
+    // the corresponding LoginModuleControlFlag.* constants.
+    // These integers are used later as index in the arrays - see 
+    // loginImpl() and logoutImpl() methods
+    private static final int OPTIONAL = 0;
+
+    private static final int REQUIRED = 1;
+
+    private static final int REQUISITE = 2;
+
+    private static final int SUFFICIENT = 3;
+
+    // Subject to be used for this LoginContext's operations
+    private Subject subject;
+
+    // Shows whether the subject 
+    // was specified by user (true) or 
+    // was created by this LoginContext itself (false).
+    private boolean userProvidedSubject;
+
+    // Shows whether we use installed or user-provided Configuration
+    private boolean userProvidedConfig;
+
+    // An user's AccessControlContext, used when user specifies 
+    private AccessControlContext userContext;
+
+    // Either a callback handler passed by the user or a wrapper for the 
+    // user's specified handler - see init() below.
+    private CallbackHandler callbackHandler;
+
+    // An array which keeps the instantiated and init()-ialized login 
+    // modules and their states
+    private Module[] modules;
+
+    // Stores a shared state
+    private HashMap sharedState;
+
+    // A context class loader used to load [mainly] LoginModules
+    private ClassLoader contextClassLoader;
+
+    // Shows overall status - whether this LoginContext was successfully logged 
+    private boolean loggedIn;
+
+    /**
+     * @com.intel.drl.spec_ref
+     */
+    public LoginContext(String name) throws LoginException {
+        init(name, null, null, null);
+    }
+
+    /**
+     * @com.intel.drl.spec_ref
+     */
+    public LoginContext(String name, CallbackHandler cbHandler)
+            throws LoginException {
+        if (cbHandler == null) {
+            throw new LoginException("CallbackHandler can not be null");
+        }
+        init(name, null, cbHandler, null);
+    }
+
+    /**
+     * @com.intel.drl.spec_ref
+     */
+    public LoginContext(String name, Subject subject) throws LoginException {
+        if (subject == null) {
+            throw new LoginException("Subject can not be null");
+        }
+        init(name, subject, null, null);
+    }
+
+    /**
+     * @com.intel.drl.spec_ref
+     */
+    public LoginContext(String name, Subject subject, CallbackHandler cbHandler)
+            throws LoginException {
+        if (subject == null) {
+            throw new LoginException("Subject can not be null");
+        }
+        if (cbHandler == null) {
+            throw new LoginException("CallbackHandler can not be null");
+        }
+        init(name, subject, cbHandler, null);
+    }
+
+    /**
+     * @com.intel.drl.spec_ref
+     */
+    public LoginContext(String name, Subject subject,
+            CallbackHandler cbHandler, Configuration config)
+            throws LoginException {
+        init(name, subject, cbHandler, config);
+    }
+
+    // Does all the machinery needed for the initialization.
+    private void init(String name, Subject subject,
+            final CallbackHandler cbHandler, Configuration config)
+            throws LoginException {
+        //
+        //
+        //
+        userProvidedSubject = (this.subject = subject) != null;
+
+        //
+        // Set config
+        //
+        if (name == null) {
+            throw new LoginException("name can not be null");
+        }
+
+        if (config == null) {
+            config = Configuration.getAccessibleConfiguration();
+        } else {
+            userProvidedConfig = true;
+        }
+
+        SecurityManager sm = System.getSecurityManager();
+
+        if (sm != null && !userProvidedConfig) {
+            sm
+                    .checkPermission(new AuthPermission("createLoginContext."
+                            + name));
+        }
+
+        AppConfigurationEntry[] entries = config.getAppConfigurationEntry(name);
+        if (entries == null) {
+            if (sm != null && !userProvidedConfig) {
+                sm.checkPermission(new AuthPermission(
+                        "createLoginContext.other"));
+            }
+            entries = config.getAppConfigurationEntry("other");
+            if (entries == null) {
+                throw new LoginException("There is no \"" + name
+                        + "\" in Configuration or it's empty.");
+            }
+        }
+
+        modules = new Module[entries.length];
+        for (int i = 0; i < modules.length; i++) {
+            modules[i] = new Module(entries[i]);
+        }
+        //
+        // Set CallbackHandler and this.contextClassLoader
+        //
+
+        // as some of the operations to be executed (i.e. get*ClassLoader, 
+        // getProperty, class loading) are security-checked, then combine all 
+        // of them into a single doPrivileged() call.
+        //
+        try {
+            AccessController.doPrivileged(new PrivilegedExceptionAction() {
+                public Object run() throws Exception {
+                    // First, set the 'contextClassLoader'
+                    contextClassLoader = Thread.currentThread()
+                            .getContextClassLoader();
+                    if (contextClassLoader == null) {
+                        contextClassLoader = ClassLoader.getSystemClassLoader();
+                    }
+                    // then, checks whether the cbHandler is set
+                    if (cbHandler == null) {
+                        // well, let's try to find it
+                        String klassName = Security
+                                .getProperty(DEFAULT_CALLBACK_HANDLER_PROPERTY);
+                        if (klassName == null || klassName.length() == 0) {
+                            return null;
+                        }
+                        Class klass = Class.forName(klassName, true,
+                                contextClassLoader);
+                        callbackHandler = (CallbackHandler) klass.newInstance();
+                    } else {
+                        callbackHandler = cbHandler;
+                    }
+                    return null;
+                }
+            });
+        } catch (PrivilegedActionException ex) {
+            throw (LoginException) new LoginException(
+                    "Could not get default callback handler.").initCause(ex
+                    .getCause());
+        }
+
+        if (userProvidedConfig) {
+            userContext = AccessController.getContext();
+        } else if (callbackHandler != null) {
+            userContext = AccessController.getContext();
+            callbackHandler = new ContextedCallbackHandler(callbackHandler);
+        }
+    }
+
+    /**
+     * @com.intel.drl.spec_ref
+     */
+    public Subject getSubject() {
+        if (userProvidedSubject || loggedIn) {
+            return subject;
+        }
+        return null;
+    }
+
+    /**
+     * @com.intel.drl.spec_ref
+     */
+    public void login() throws LoginException {
+        PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
+            public Object run() throws LoginException {
+                loginImpl();
+                return null;
+            }
+        };
+        try {
+            if (userProvidedConfig) {
+                AccessController.doPrivileged(action, userContext);
+            } else {
+                AccessController.doPrivileged(action);
+            }
+        } catch (PrivilegedActionException ex) {
+            throw (LoginException) ex.getException();
+        }
+    }
+
+    // The real implementation of login() method whose calls are wrapped into 
+    // appropriate doPrivileged calls in login().
+    private void loginImpl() throws LoginException {
+        if (loggedIn) {
+            return;
+        }
+
+        if (subject == null) {
+            subject = new Subject();
+        }
+
+        if (sharedState == null) {
+            sharedState = new HashMap();
+        }
+
+        // PHASE 1: Calling login()-s
+        Throwable firstProblem = null;
+
+        int[] logged = new int[4];
+        int[] total = new int[4];
+
+        for (int i = 0; i < modules.length; i++) {
+            try {
+                // if a module fails during Class.forName(), then it breaks overall 
+                // attempt - see catch() below
+                modules[i].create(subject, callbackHandler, sharedState);
+
+                if (modules[i].module.login()) {
+                    ++total[modules[i].getFlag()];
+                    ++logged[modules[i].getFlag()];
+                    if (modules[i].getFlag() == SUFFICIENT) {
+                        break;
+                    }
+                }
+            } catch (Throwable ex) {
+                if (firstProblem == null) {
+                    firstProblem = ex;
+                }
+                if (modules[i].klass == null) {
+                    // an exception occured during class lookup - overall 
+                    // attempt must fail
+                    // a little trick: increase the REQUIRED's number - this 
+                    // will look like a failed REQUIRED module later, so overall 
+                    // attempt will fail
+                    ++total[REQUIRED];
+                    break;
+                } else {
+                    ++total[modules[i].getFlag()];
+                    // something happened after the class was loaded
+                    if (modules[i].getFlag() == REQUISITE) {
+                        // ... and no need to walk down anymore
+                        break;
+                    }
+                }
+            }
+        }
+        // end of PHASE1, 
+
+        // Let's decide whether we have either overall success or a total failure
+        boolean fail = true;
+
+        // Note: 'failed[xxx]!=0' is not enough to check.
+        // Use 'logged[xx] != total[xx]' instead.
+        // This is because some modules might not be counted as 'failed' if
+        // an exception occured during preload()/Class.forName()-ing.
+        // But, such modules still get counted in the total[]. 
+
+        //
+        // if any REQ* module failed - then it's failure
+        if (logged[REQUIRED] != total[REQUIRED]
+                || logged[REQUISITE] != total[REQUISITE]) {
+            // fail = true;
+        } else {
+            if (total[REQUIRED] == 0 && total[REQUISITE] == 0) {
+                // neither REQUIRED nor REQUISITE was configured.
+                // must have at least one SUFFICIENT or OPTIONAL
+                if (logged[OPTIONAL] != 0 || logged[SUFFICIENT] != 0) {
+                    fail = false;
+                }
+                //else { fail = true; }
+            } else {
+                fail = false;
+            }
+        }
+
+        int commited[] = new int[4];
+        // clear it
+        total[0] = total[1] = total[2] = total[3] = 0;
+        if (!fail) {
+            // PHASE 2: 
+            for (int i = 0; i < modules.length; i++) {
+                if (modules[i].klass != null) {
+                    ++total[modules[i].getFlag()];
+                    try {
+                        modules[i].module.commit();
+                        ++commited[modules[i].getFlag()];
+                    } catch (Throwable ex) {
+                        if (firstProblem == null) {
+                            firstProblem = ex;
+                        }
+                    }
+                }
+            }
+        }
+
+        // need to decide once again
+        fail = true;
+        if (commited[REQUIRED] != total[REQUIRED]
+                || commited[REQUISITE] != total[REQUISITE]) {
+            //fail = true;
+        } else {
+            if (total[REQUIRED] == 0 && total[REQUISITE] == 0) {
+                // neither REQUIRED nor REQUISITE was configured.
+                // must have at least one SUFFICIENT or OPTIONAL
+                if (commited[OPTIONAL] != 0 || commited[SUFFICIENT] != 0) {
+                    fail = false;
+                } else {
+                    //fail = true;
+                }
+            } else {
+                fail = false;
+            }
+        }
+
+        if (fail) {
+            // either login() or commit() failed. aborting... 
+            for (int i = 0; i < modules.length; i++) {
+                try {
+                    modules[i].module.abort();
+                } catch ( /*LoginException*/Throwable ex) {
+                    if (firstProblem == null) {
+                        firstProblem = ex;
+                    }
+                }
+            }
+            if (firstProblem instanceof PrivilegedActionException
+                    && firstProblem.getCause() != null) {
+                firstProblem = firstProblem.getCause();
+            }
+            if (firstProblem instanceof LoginException) {
+                throw (LoginException) firstProblem;
+            } else {
+                throw (LoginException) new LoginException(
+                        "Login attempt failed.").initCause(firstProblem);
+            }
+        } else {
+            loggedIn = true;
+        }
+        // return silently - we are logged in
+    }
+
+    /**
+     * @com.intel.drl.spec_ref
+     */
+    public void logout() throws LoginException {
+        PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
+            public Object run() throws LoginException {
+                logoutImpl();
+                return null;
+            }
+        };
+        try {
+            if (userProvidedConfig) {
+                AccessController.doPrivileged(action, userContext);
+            } else {
+                AccessController.doPrivileged(action);
+            }
+        } catch (PrivilegedActionException ex) {
+            throw (LoginException) ex.getException();
+        }
+    }
+
+    // The real implementation of logout() method whose calls are wrapped into 
+    // appropriate doPrivileged calls in logout().
+    private void logoutImpl() throws LoginException {
+        if (subject == null) {
+            throw new LoginException("This LoginContext is not logged.");
+        }
+        loggedIn = false;
+        Throwable firstProblem = null;
+        int total = 0;
+        for (int i = 0; i < modules.length; i++) {
+            try {
+                modules[i].module.logout();
+                ++total;
+            } catch (Throwable ex) {
+                if (firstProblem == null) {
+                    firstProblem = ex;
+                }
+            }
+        }
+        if (firstProblem != null || total == 0) {
+            if (firstProblem instanceof PrivilegedActionException
+                    && firstProblem.getCause() != null) {
+                firstProblem = firstProblem.getCause();
+            }
+            if (firstProblem instanceof LoginException) {
+                throw (LoginException) firstProblem;
+            } else {
+                throw (LoginException) new LoginException(
+                        "Login attempt failed.").initCause(firstProblem);
+            }
+        }
+    }
+
+    // A class that servers as a wrapper for the CallbackHandler when we use 
+    // installed Configuration, but not a passed one. See API docs on the 
+    // LoginContext.<br>
+    // Simply invokes the given handler with the given AccessControlContext. 
+    private class ContextedCallbackHandler implements CallbackHandler {
+        CallbackHandler hiddenHandlerRef;
+
+        ContextedCallbackHandler(CallbackHandler handler) {
+            this.hiddenHandlerRef = handler;
+        }
+
+        public void handle(final Callback[] callbacks) throws IOException,
+                UnsupportedCallbackException {
+            try {
+                AccessController.doPrivileged(new PrivilegedExceptionAction() {
+                    public Object run() throws IOException,
+                            UnsupportedCallbackException {
+                        hiddenHandlerRef.handle(callbacks);
+                        return null;
+                    }
+                }, userContext);
+            } catch (PrivilegedActionException ex) {
+                if (ex.getCause() instanceof UnsupportedCallbackException) {
+                    throw (UnsupportedCallbackException) ex.getCause();
+                }
+                throw (IOException) ex.getCause();
+            }
+        }
+    }
+
+    // A private class that stores an instantiated LoginModule.
+    private final class Module {
+
+        // An initial info about the module to be used
+        AppConfigurationEntry entry;
+
+        // A mapping of LoginModuleControlFlag onto a simple int constant
+        int flag;
+
+        // The LoginModule intself 
+        LoginModule module;
+
+        // A class of the module
+        Class klass;
+
+        Module(AppConfigurationEntry entry) {
+            this.entry = entry;
+            LoginModuleControlFlag flg = entry.getControlFlag();
+            if (flg == LoginModuleControlFlag.OPTIONAL) {
+                flag = OPTIONAL;
+            } else if (flg == LoginModuleControlFlag.REQUISITE) {
+                flag = REQUISITE;
+            } else if (flg == LoginModuleControlFlag.SUFFICIENT) {
+                flag = SUFFICIENT;
+            } else {
+                flag = REQUIRED;
+                //if(flg!=LoginModuleControlFlag.REQUIRED) throw new Error()
+            }
+        }
+
+        int getFlag() {
+            return flag;
+        }
+
+        // Loads class of the LoginModule, instantiates it and then 
+        // calls initialize().
+        void create(Subject subject, CallbackHandler callbackHandler,
+                Map sharedState) throws LoginException {
+            String klassName = entry.getLoginModuleName();
+            if (klass == null) {
+                try {
+                    klass = Class.forName(klassName, false, contextClassLoader);
+                } catch (ClassNotFoundException ex) {
+                    throw (LoginException) new LoginException(
+                            "Could not load module " + klassName).initCause(ex);
+                }
+            }
+
+            if (module == null) {
+                try {
+                    module = (LoginModule) klass.newInstance();
+                } catch (IllegalAccessException ex) {
+                    throw (LoginException) new LoginException(
+                            "Could not instantiate module " + klassName)
+                            .initCause(ex);
+                } catch (InstantiationException ex) {
+                    throw (LoginException) new LoginException(
+                            "Could not instantiate module " + klassName)
+                            .initCause(ex);
+                }
+                module.initialize(subject, callbackHandler, sharedState, entry
+                        .getOptions());
+            }
+        }
+    }
 }

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/login/LoginContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/login/LoginException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/x500/X500PrivateCredential.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/sasl/AuthenticationException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/sasl/AuthorizeCallback.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/sasl/RealmCallback.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/sasl/RealmChoiceCallback.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/sasl/Sasl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/sasl/SaslClient.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/sasl/SaslClientFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/sasl/SaslException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/sasl/SaslServer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/sasl/SaslServerFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message