Search in sources :

Example 1 with CustomTextInputCallback

use of es.gob.jmulticard.card.dnie.CustomTextInputCallback 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 CustomTextInputCallback

use of es.gob.jmulticard.card.dnie.CustomTextInputCallback 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)

Example 3 with CustomTextInputCallback

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

the class PinDialog method onCreateDialog.

@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    final Builder alertDialogBuilder = new AlertDialog.Builder(this.activity);
    final LayoutInflater layoutInflater = LayoutInflater.from(this.activity);
    final View view;
    if (this.isCan) {
        alertDialogBuilder.setTitle(R.string.can_intro);
        view = layoutInflater.inflate(R.layout.dialog_can, null);
        final TextView textV = (TextView) view.findViewById(R.id.tvPin);
    } else {
        alertDialogBuilder.setTitle(R.string.pin_intro);
        view = layoutInflater.inflate(R.layout.dialog_pin, null);
        final TextView textV = (TextView) view.findViewById(R.id.tvPin);
        textV.setText(this.title);
    }
    final EditText editTextPin = (EditText) view.findViewById(R.id.etPin);
    alertDialogBuilder.setView(view);
    alertDialogBuilder.setNegativeButton(this.activity.getString(R.string.cancel), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(final DialogInterface dialog, final int id) {
            dialog.dismiss();
            synchronized (PinDialog.this.dialogDone) {
                PinDialog.this.dialogDone.notify();
            }
        }
    });
    alertDialogBuilder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(final DialogInterface dialog, final int which) {
            if (editTextPin.getText() != null && !"".equals(editTextPin.getText().toString())) {
                // $NON-NLS-1$
                dialog.dismiss();
                setPassword(editTextPin.getText().toString());
                if (callback instanceof PasswordCallback) {
                    final PasswordCallback pc = (PasswordCallback) callback;
                    pc.setPassword(editTextPin.getText().toString().toCharArray());
                } else if (callback instanceof CustomTextInputCallback) {
                    final CustomTextInputCallback pc = (CustomTextInputCallback) callback;
                    pc.setText(editTextPin.getText().toString());
                }
                synchronized (PinDialog.this.dialogDone) {
                    PinDialog.this.dialogDone.notify();
                }
            } else {
                // TODO: Gestionar este caso
                // $NON-NLS-1$ //$NON-NLS-2$
                Log.e("es.gob.jmulticard", "El pin no puede ser vacio o nulo");
                synchronized (PinDialog.this.dialogDone) {
                    PinDialog.this.dialogDone.notify();
                }
            }
        }
    });
    alertDialogBuilder.setOnKeyListener(new DialogInterface.OnKeyListener() {

        @Override
        public boolean onKey(final DialogInterface dialog, final int keyCode, final KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                dialog.dismiss();
                return true;
            }
            return false;
        }
    });
    return alertDialogBuilder.create();
}
Also used : EditText(android.widget.EditText) DialogInterface(android.content.DialogInterface) Builder(android.app.AlertDialog.Builder) TextView(android.widget.TextView) View(android.view.View) KeyEvent(android.view.KeyEvent) LayoutInflater(android.view.LayoutInflater) PasswordCallback(javax.security.auth.callback.PasswordCallback) TextView(android.widget.TextView) CustomTextInputCallback(es.gob.jmulticard.card.dnie.CustomTextInputCallback)

Aggregations

CustomTextInputCallback (es.gob.jmulticard.card.dnie.CustomTextInputCallback)3 PasswordCallback (javax.security.auth.callback.PasswordCallback)3 CustomAuthorizeCallback (es.gob.jmulticard.card.dnie.CustomAuthorizeCallback)2 Callback (javax.security.auth.callback.Callback)2 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)2 Builder (android.app.AlertDialog.Builder)1 DialogInterface (android.content.DialogInterface)1 FragmentTransaction (android.support.v4.app.FragmentTransaction)1 KeyEvent (android.view.KeyEvent)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 EditText (android.widget.EditText)1 TextView (android.widget.TextView)1