Search in sources :

Example 1 with DestroyFailedException

use of javax.security.auth.DestroyFailedException in project robovm by robovm.

the class DestroyFailedExceptionTest method testDestroyFailedException01.

/**
     * javax.security.auth.DestroyFailedException#DestroyFailedException()
     * Assertion: constructs DestroyFailedException with no detail message
     */
public void testDestroyFailedException01() {
    DestroyFailedException dfE = new DestroyFailedException();
    assertNull("getMessage() must return null.", dfE.getMessage());
    assertNull("getCause() must return null", dfE.getCause());
}
Also used : DestroyFailedException(javax.security.auth.DestroyFailedException)

Example 2 with DestroyFailedException

use of javax.security.auth.DestroyFailedException in project robovm by robovm.

the class DestroyFailedExceptionTest method testDestroyFailedException02.

/**
     * javax.security.auth.DestroyFailedException#DestroyFailedException(String msg)
     * Assertion: constructs with not null parameter.
     */
public void testDestroyFailedException02() {
    DestroyFailedException dfE;
    for (int i = 0; i < msgs.length; i++) {
        dfE = new DestroyFailedException(msgs[i]);
        assertEquals("getMessage() must return: ".concat(msgs[i]), dfE.getMessage(), msgs[i]);
        assertNull("getCause() must return null", dfE.getCause());
    }
}
Also used : DestroyFailedException(javax.security.auth.DestroyFailedException)

Example 3 with DestroyFailedException

use of javax.security.auth.DestroyFailedException in project jdk8u_jdk by JetBrains.

the class KerberosTicket method refresh.

/**
     * Extends the validity period of this ticket. The ticket will contain
     * a new session key if the refresh operation succeeds. The refresh
     * operation will fail if the ticket is not renewable or the latest
     * allowable renew time has passed. Any other error returned by the
     * KDC will also cause this method to fail.
     *
     * Note: This method is not synchronized with the the accessor
     * methods of this object. Hence callers need to be aware of multiple
     * threads that might access this and try to renew it at the same
     * time.
     *
     * @throws RefreshFailedException if the ticket is not renewable, or
     * the latest allowable renew time has passed, or the KDC returns some
     * error.
     *
     * @see #isRenewable()
     * @see #getRenewTill()
     */
public void refresh() throws RefreshFailedException {
    if (destroyed)
        throw new RefreshFailedException("A destroyed ticket " + "cannot be renewd.");
    if (!isRenewable())
        throw new RefreshFailedException("This ticket is not renewable");
    if (System.currentTimeMillis() > getRenewTill().getTime())
        throw new RefreshFailedException("This ticket is past " + "its last renewal time.");
    Throwable e = null;
    sun.security.krb5.Credentials krb5Creds = null;
    try {
        krb5Creds = new sun.security.krb5.Credentials(asn1Encoding, client.toString(), server.toString(), sessionKey.getEncoded(), sessionKey.getKeyType(), flags, authTime, startTime, endTime, renewTill, clientAddresses);
        krb5Creds = krb5Creds.renew();
    } catch (sun.security.krb5.KrbException krbException) {
        e = krbException;
    } catch (java.io.IOException ioException) {
        e = ioException;
    }
    if (e != null) {
        RefreshFailedException rfException = new RefreshFailedException("Failed to renew Kerberos Ticket " + "for client " + client + " and server " + server + " - " + e.getMessage());
        rfException.initCause(e);
        throw rfException;
    }
    /*
         * In case multiple threads try to refresh it at the same time.
         */
    synchronized (this) {
        try {
            this.destroy();
        } catch (DestroyFailedException dfException) {
        // Squelch it since we don't care about the old ticket.
        }
        init(krb5Creds.getEncoded(), new KerberosPrincipal(krb5Creds.getClient().getName()), new KerberosPrincipal(krb5Creds.getServer().getName(), KerberosPrincipal.KRB_NT_SRV_INST), krb5Creds.getSessionKey().getBytes(), krb5Creds.getSessionKey().getEType(), krb5Creds.getFlags(), krb5Creds.getAuthTime(), krb5Creds.getStartTime(), krb5Creds.getEndTime(), krb5Creds.getRenewTill(), krb5Creds.getClientAddresses());
        destroyed = false;
    }
}
Also used : DestroyFailedException(javax.security.auth.DestroyFailedException) java.io(java.io) RefreshFailedException(javax.security.auth.RefreshFailedException)

Example 4 with DestroyFailedException

use of javax.security.auth.DestroyFailedException in project jdk8u_jdk by JetBrains.

the class KeyStoreLoginModule method logoutInternal.

private void logoutInternal() throws LoginException {
    if (debug) {
        debugPrint("Entering logoutInternal");
    }
    // assumption is that KeyStore.load did a login -
    // perform explicit logout if possible
    LoginException logoutException = null;
    Provider provider = keyStore.getProvider();
    if (provider instanceof AuthProvider) {
        AuthProvider ap = (AuthProvider) provider;
        try {
            ap.logout();
            if (debug) {
                debugPrint("logged out of KeyStore AuthProvider");
            }
        } catch (LoginException le) {
            // save but continue below
            logoutException = le;
        }
    }
    if (subject.isReadOnly()) {
        // attempt to destroy the private credential
        // even if the Subject is read-only
        principal = null;
        certP = null;
        status = INITIALIZED;
        // destroy the private credential
        Iterator<Object> it = subject.getPrivateCredentials().iterator();
        while (it.hasNext()) {
            Object obj = it.next();
            if (privateCredential.equals(obj)) {
                privateCredential = null;
                try {
                    ((Destroyable) obj).destroy();
                    if (debug)
                        debugPrint("Destroyed private credential, " + obj.getClass().getName());
                    break;
                } catch (DestroyFailedException dfe) {
                    LoginException le = new LoginException("Unable to destroy private credential, " + obj.getClass().getName());
                    le.initCause(dfe);
                    throw le;
                }
            }
        }
        // read-only Subject
        throw new LoginException("Unable to remove Principal (" + "X500Principal " + ") and public credential (certificatepath) " + "from read-only Subject");
    }
    if (principal != null) {
        subject.getPrincipals().remove(principal);
        principal = null;
    }
    if (certP != null) {
        subject.getPublicCredentials().remove(certP);
        certP = null;
    }
    if (privateCredential != null) {
        subject.getPrivateCredentials().remove(privateCredential);
        privateCredential = null;
    }
    // throw pending logout exception if there is one
    if (logoutException != null) {
        throw logoutException;
    }
    status = INITIALIZED;
}
Also used : Destroyable(javax.security.auth.Destroyable) DestroyFailedException(javax.security.auth.DestroyFailedException) LoginException(javax.security.auth.login.LoginException) FailedLoginException(javax.security.auth.login.FailedLoginException)

Example 5 with DestroyFailedException

use of javax.security.auth.DestroyFailedException in project accumulo by apache.

the class CredentialsTest method testToThrift.

@Test
public void testToThrift() throws DestroyFailedException {
    // verify thrift serialization
    Credentials creds = new Credentials("test", new PasswordToken("testing"));
    TCredentials tCreds = creds.toThrift(inst);
    assertEquals("test", tCreds.getPrincipal());
    assertEquals(PasswordToken.class.getName(), tCreds.getTokenClassName());
    assertArrayEquals(AuthenticationTokenSerializer.serialize(new PasswordToken("testing")), tCreds.getToken());
    // verify that we can't serialize if it's destroyed
    creds.getToken().destroy();
    try {
        creds.toThrift(inst);
        fail();
    } catch (Exception e) {
        assertTrue(e instanceof RuntimeException);
        assertTrue(e.getCause() instanceof AccumuloSecurityException);
        assertTrue(AccumuloSecurityException.class.cast(e.getCause()).getSecurityErrorCode().equals(SecurityErrorCode.TOKEN_EXPIRED));
    }
}
Also used : PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) TCredentials(org.apache.accumulo.core.security.thrift.TCredentials) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) TCredentials(org.apache.accumulo.core.security.thrift.TCredentials) Credentials(org.apache.accumulo.core.client.impl.Credentials) DestroyFailedException(javax.security.auth.DestroyFailedException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) Test(org.junit.Test)

Aggregations

DestroyFailedException (javax.security.auth.DestroyFailedException)30 SecretKey (javax.crypto.SecretKey)9 PrivateKey (java.security.PrivateKey)5 X509Certificate (java.security.cert.X509Certificate)4 CallbackHandler (javax.security.auth.callback.CallbackHandler)4 Crypto (org.apache.wss4j.common.crypto.Crypto)4 SecretKeySpec (javax.crypto.spec.SecretKeySpec)3 KerberosTicket (javax.security.auth.kerberos.KerberosTicket)3 CryptoType (org.apache.wss4j.common.crypto.CryptoType)3 WSPasswordCallback (org.apache.wss4j.common.ext.WSPasswordCallback)3 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)3 IOException (java.io.IOException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 XMLCipher (org.apache.xml.security.encryption.XMLCipher)2 XMLEncryptionException (org.apache.xml.security.encryption.XMLEncryptionException)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 java.io (java.io)1 Signature (java.security.Signature)1 AlgorithmParameterSpec (java.security.spec.AlgorithmParameterSpec)1 Cipher (javax.crypto.Cipher)1