Search in sources :

Example 56 with UnsupportedCallbackException

use of javax.security.auth.callback.UnsupportedCallbackException in project jmulticard by ctt-gob-es.

the class Ceres method getInternalPasswordCallback.

protected PasswordCallback getInternalPasswordCallback() throws PinException {
    if (this.passwordCallback != null) {
        final int retriesLeft = getPinRetriesLeft();
        if (retriesLeft == 0) {
            throw new AuthenticationModeLockedException();
        }
        return this.passwordCallback;
    }
    if (this.callbackHandler != null) {
        final int retriesLeft = getPinRetriesLeft();
        if (retriesLeft == 0) {
            throw new AuthenticationModeLockedException();
        }
        final PasswordCallback pwc = new PasswordCallback(// $NON-NLS-1$
        CardMessages.getString("Gen.0", Integer.toString(retriesLeft)), false);
        try {
            this.callbackHandler.handle(new Callback[] { pwc });
        } catch (final IOException e) {
            throw new PinException(// $NON-NLS-1$
            "Error obteniendo el PIN del CallbackHandler: " + e, // $NON-NLS-1$
            e);
        } catch (final UnsupportedCallbackException e) {
            throw new PinException(// $NON-NLS-1$
            "El CallbackHandler no soporta pedir el PIN al usuario: " + e, // $NON-NLS-1$
            e);
        }
        return pwc;
    }
    // $NON-NLS-1$
    throw new PinException("No hay ningun metodo para obtener el PIN");
}
Also used : AuthenticationModeLockedException(es.gob.jmulticard.card.AuthenticationModeLockedException) PasswordCallback(javax.security.auth.callback.PasswordCallback) IOException(java.io.IOException) BadPinException(es.gob.jmulticard.card.BadPinException) PinException(es.gob.jmulticard.card.PinException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException)

Example 57 with UnsupportedCallbackException

use of javax.security.auth.callback.UnsupportedCallbackException in project jmulticard by ctt-gob-es.

the class SmartCafePkcs15Applet method getInternalPasswordCallback.

private PasswordCallback getInternalPasswordCallback() throws PinException {
    if (this.passwordCallback != null) {
        final int retriesLeft = getPinRetriesLeft();
        if (retriesLeft == 0) {
            throw new AuthenticationModeLockedException();
        }
        return this.passwordCallback;
    }
    if (this.callbackHandler != null) {
        final int retriesLeft = getPinRetriesLeft();
        if (retriesLeft == 0) {
            throw new AuthenticationModeLockedException();
        }
        final PasswordCallback pwc = new PasswordCallback(// $NON-NLS-1$
        CardMessages.getString("Gen.0", Integer.toString(retriesLeft)), false);
        try {
            this.callbackHandler.handle(new Callback[] { pwc });
        } catch (final IOException e) {
            throw new PinException(// $NON-NLS-1$
            "Error obteniendo el PIN del CallbackHandler: " + e, // $NON-NLS-1$
            e);
        } catch (final UnsupportedCallbackException e) {
            throw new PinException(// $NON-NLS-1$
            "El CallbackHandler no soporta pedir el PIN al usuario: " + e, // $NON-NLS-1$
            e);
        }
        return pwc;
    }
    // $NON-NLS-1$
    throw new PinException("No hay ningun metodo para obtener el PIN");
}
Also used : AuthenticationModeLockedException(es.gob.jmulticard.card.AuthenticationModeLockedException) PasswordCallback(javax.security.auth.callback.PasswordCallback) IOException(java.io.IOException) BadPinException(es.gob.jmulticard.card.BadPinException) PinException(es.gob.jmulticard.card.PinException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException)

Example 58 with UnsupportedCallbackException

use of javax.security.auth.callback.UnsupportedCallbackException in project jmulticard by ctt-gob-es.

the class Dnie method getInternalPasswordCallback.

protected PasswordCallback getInternalPasswordCallback() throws PinException {
    if (this.passwordCallback != null) {
        final int retriesLeft = getPinRetriesLeft();
        if (retriesLeft == 0) {
            throw new AuthenticationModeLockedException();
        }
        return this.passwordCallback;
    }
    if (this.callbackHandler != null) {
        final int retriesLeft = getPinRetriesLeft();
        if (retriesLeft == 0) {
            throw new AuthenticationModeLockedException();
        }
        final PasswordCallback pwc = new PasswordCallback(getPinMessage(retriesLeft), false);
        try {
            this.callbackHandler.handle(new Callback[] { pwc });
        } catch (final IOException e) {
            throw new PinException(// $NON-NLS-1$
            "Error obteniendo el PIN del CallbackHandler: " + e, // $NON-NLS-1$
            e);
        } catch (final UnsupportedCallbackException e) {
            throw new PinException(// $NON-NLS-1$
            "El CallbackHandler no soporta pedir el PIN al usuario: " + e, // $NON-NLS-1$
            e);
        }
        if (pwc.getPassword() == null || pwc.getPassword().toString().isEmpty()) {
            throw new PinException(// $NON-NLS-1$
            "El PIN no puede ser nulo ni vacio");
        }
        return pwc;
    }
    // $NON-NLS-1$
    throw new PinException("No hay ningun metodo para obtener el PIN");
}
Also used : AuthenticationModeLockedException(es.gob.jmulticard.card.AuthenticationModeLockedException) PasswordCallback(javax.security.auth.callback.PasswordCallback) IOException(java.io.IOException) BadPinException(es.gob.jmulticard.card.BadPinException) PinException(es.gob.jmulticard.card.PinException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException)

Example 59 with UnsupportedCallbackException

use of javax.security.auth.callback.UnsupportedCallbackException in project drill by axbaretto.

the class PlainFactory method createSaslClient.

@Override
public SaslClient createSaslClient(final UserGroupInformation ugi, final Map<String, ?> properties) throws SaslException {
    final String userName = (String) properties.get(DrillProperties.USER);
    final String password = (String) properties.get(DrillProperties.PASSWORD);
    return FastSaslClientFactory.getInstance().createSaslClient(new String[] { SIMPLE_NAME }, null, /**
     * authorization ID
     */
    null, null, properties, new CallbackHandler() {

        @Override
        public void handle(final Callback[] callbacks) throws IOException, UnsupportedCallbackException {
            for (final Callback callback : callbacks) {
                if (callback instanceof NameCallback) {
                    NameCallback.class.cast(callback).setName(userName);
                    continue;
                }
                if (callback instanceof PasswordCallback) {
                    PasswordCallback.class.cast(callback).setPassword(password.toCharArray());
                    continue;
                }
                throw new UnsupportedCallbackException(callback);
            }
        }
    });
}
Also used : CallbackHandler(javax.security.auth.callback.CallbackHandler) PasswordCallback(javax.security.auth.callback.PasswordCallback) NameCallback(javax.security.auth.callback.NameCallback) Callback(javax.security.auth.callback.Callback) NameCallback(javax.security.auth.callback.NameCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) IOException(java.io.IOException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException)

Example 60 with UnsupportedCallbackException

use of javax.security.auth.callback.UnsupportedCallbackException in project activemq-artemis by apache.

the class GSSAPIServerSASL method processSASL.

@Override
public byte[] processSASL(byte[] bytes) {
    try {
        if (jaasId == null) {
            // populate subject with acceptor private credentials
            LoginContext loginContext = new LoginContext(loginConfigScope);
            loginContext.login();
            jaasId = loginContext.getSubject();
        }
        if (saslServer == null) {
            saslServer = Subject.doAs(jaasId, (PrivilegedExceptionAction<SaslServer>) () -> Sasl.createSaslServer(NAME, null, null, new HashMap<String, String>(), new CallbackHandler() {

                @Override
                public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
                    for (Callback callback : callbacks) {
                        if (callback instanceof AuthorizeCallback) {
                            AuthorizeCallback authorizeCallback = (AuthorizeCallback) callback;
                            // only ok to authenticate as self
                            authorizeCallback.setAuthorized(authorizeCallback.getAuthenticationID().equals(authorizeCallback.getAuthorizationID()));
                        }
                    }
                }
            }));
        }
        byte[] challenge = Subject.doAs(jaasId, (PrivilegedExceptionAction<byte[]>) () -> saslServer.evaluateResponse(bytes));
        if (saslServer.isComplete()) {
            result = new PrincipalSASLResult(true, new KerberosPrincipal(saslServer.getAuthorizationID()));
        }
        return challenge;
    } catch (Exception outOfHere) {
        log.info("Error on sasl input: " + outOfHere.toString(), outOfHere);
        result = new PrincipalSASLResult(false, null);
    }
    return null;
}
Also used : KerberosPrincipal(javax.security.auth.kerberos.KerberosPrincipal) CallbackHandler(javax.security.auth.callback.CallbackHandler) LoginContext(javax.security.auth.login.LoginContext) AuthorizeCallback(javax.security.sasl.AuthorizeCallback) Callback(javax.security.auth.callback.Callback) HashMap(java.util.HashMap) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) AuthorizeCallback(javax.security.sasl.AuthorizeCallback) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) IOException(java.io.IOException) SaslException(javax.security.sasl.SaslException)

Aggregations

UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)332 Callback (javax.security.auth.callback.Callback)213 IOException (java.io.IOException)201 NameCallback (javax.security.auth.callback.NameCallback)182 PasswordCallback (javax.security.auth.callback.PasswordCallback)177 LoginException (javax.security.auth.login.LoginException)89 CallbackHandler (javax.security.auth.callback.CallbackHandler)63 FailedLoginException (javax.security.auth.login.FailedLoginException)45 LoginContext (javax.security.auth.login.LoginContext)43 Subject (javax.security.auth.Subject)36 Principal (java.security.Principal)34 AuthorizeCallback (javax.security.sasl.AuthorizeCallback)31 RealmCallback (javax.security.sasl.RealmCallback)27 HttpServletRequest (javax.servlet.http.HttpServletRequest)27 HashMap (java.util.HashMap)23 CallerPrincipalCallback (javax.security.auth.message.callback.CallerPrincipalCallback)23 Test (org.junit.Test)21 GroupPrincipalCallback (javax.security.auth.message.callback.GroupPrincipalCallback)20 SaslException (javax.security.sasl.SaslException)19 AuthException (javax.security.auth.message.AuthException)18