Search in sources :

Example 1 with CustomAuthorizeCallback

use of es.gob.jmulticard.card.dnie.CustomAuthorizeCallback in project jmulticard by ctt-gob-es.

the class DnieCallbackHandler method handle.

@Override
public void handle(final Callback[] callbacks) throws UnsupportedCallbackException {
    if (callbacks != null) {
        for (final Callback cb : callbacks) {
            if (cb != null) {
                if (cb instanceof CustomTextInputCallback) {
                    final UIPasswordCallbackCan uip = new UIPasswordCallbackCan(// $NON-NLS-1$
                    Messages.getString("CanPasswordCallback.0"), null, // $NON-NLS-1$
                    Messages.getString("CanPasswordCallback.0"), // $NON-NLS-1$
                    Messages.getString("CanPasswordCallback.2"));
                    ((CustomTextInputCallback) cb).setText(new String(uip.getPassword()));
                    return;
                } else if (cb instanceof CustomAuthorizeCallback) {
                    DialogBuilder.showSignatureConfirmDialog((CustomAuthorizeCallback) cb);
                    return;
                } else if (cb instanceof PasswordCallback) {
                    final CommonPasswordCallback uip = new CommonPasswordCallback(((PasswordCallback) cb).getPrompt(), // $NON-NLS-1$
                    Messages.getString("CommonPasswordCallback.1"), true);
                    ((PasswordCallback) cb).setPassword(uip.getPassword());
                    return;
                } else {
                    // $NON-NLS-1$
                    LOGGER.severe("Callback no soportada: " + cb.getClass().getName());
                }
            }
        }
    } else {
        // $NON-NLS-1$
        LOGGER.warning("Se ha recibido un array de Callbacks nulo");
    }
    throw new UnsupportedCallbackException(null);
}
Also used : PasswordCallback(javax.security.auth.callback.PasswordCallback) CustomTextInputCallback(es.gob.jmulticard.card.dnie.CustomTextInputCallback) Callback(javax.security.auth.callback.Callback) CustomAuthorizeCallback(es.gob.jmulticard.card.dnie.CustomAuthorizeCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) CustomAuthorizeCallback(es.gob.jmulticard.card.dnie.CustomAuthorizeCallback) CustomTextInputCallback(es.gob.jmulticard.card.dnie.CustomTextInputCallback)

Example 2 with CustomAuthorizeCallback

use of es.gob.jmulticard.card.dnie.CustomAuthorizeCallback in project jmulticard by ctt-gob-es.

the class DnieNFCCallbackHandler method handle.

@Override
public void handle(final Callback[] callbacks) throws UnsupportedCallbackException {
    if (callbacks != null) {
        for (final Callback cb : callbacks) {
            if (cb instanceof PasswordCallback) {
                final PinDialog dialog = new PinDialog(false, this.activity, cb, this.dialogDone);
                final FragmentTransaction ft = ((FragmentActivity) this.activity).getSupportFragmentManager().beginTransaction();
                final ShowPinDialogTask spdt = new ShowPinDialogTask(dialog, ft, this.activity, this.dialogDone);
                final String input = spdt.getInput();
                ((PasswordCallback) cb).setPassword(input.toCharArray());
                return;
            }
            String input;
            if (cb instanceof CustomTextInputCallback) {
                if (this.passwordCallback == null) {
                    final PinDialog dialog = new PinDialog(true, this.activity, cb, this.dialogDone);
                    final FragmentTransaction ft = ((FragmentActivity) this.activity).getSupportFragmentManager().beginTransaction();
                    final ShowPinDialogTask spdt = new ShowPinDialogTask(dialog, ft, this.activity, this.dialogDone);
                    input = spdt.getInput();
                } else {
                    input = new String(this.passwordCallback.getPassword());
                    // En caso de fallar el primer CAN lo pedira de nuevo al ususario
                    this.passwordCallback = null;
                }
                ((CustomTextInputCallback) cb).setText(input);
                return;
            }
            if (cb instanceof CustomAuthorizeCallback) {
                return;
            }
            LOGGER.severe(cb.getClass().getName());
        }
    } else {
        // $NON-NLS-1$
        LOGGER.warning("Se ha recibido un array de Callbacks nulo");
        throw new UnsupportedCallbackException(null);
    }
}
Also used : PasswordCallback(javax.security.auth.callback.PasswordCallback) CustomTextInputCallback(es.gob.jmulticard.card.dnie.CustomTextInputCallback) Callback(javax.security.auth.callback.Callback) CustomAuthorizeCallback(es.gob.jmulticard.card.dnie.CustomAuthorizeCallback) FragmentTransaction(android.support.v4.app.FragmentTransaction) PasswordCallback(javax.security.auth.callback.PasswordCallback) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) CustomAuthorizeCallback(es.gob.jmulticard.card.dnie.CustomAuthorizeCallback) CustomTextInputCallback(es.gob.jmulticard.card.dnie.CustomTextInputCallback)

Aggregations

CustomAuthorizeCallback (es.gob.jmulticard.card.dnie.CustomAuthorizeCallback)2 CustomTextInputCallback (es.gob.jmulticard.card.dnie.CustomTextInputCallback)2 Callback (javax.security.auth.callback.Callback)2 PasswordCallback (javax.security.auth.callback.PasswordCallback)2 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)2 FragmentTransaction (android.support.v4.app.FragmentTransaction)1