Example usage for javax.smartcardio TerminalFactory terminals

List of usage examples for javax.smartcardio TerminalFactory terminals

Introduction

In this page you can find the example usage for javax.smartcardio TerminalFactory terminals.

Prototype

public CardTerminals terminals() 

Source Link

Document

Returns a new CardTerminals object encapsulating the terminals supported by this factory.

Usage

From source file:de.willuhn.jameica.hbci.passports.pintan.Controller.java

/**
 * Liefert eine Auswahl verfuegbarer Kartenleser-Bezeichnungen.
 * @return eine Auswahl verfuegbaren Kartenleser-Bezeichnungen.
 * @throws RemoteException/*from   w  ww . ja va2s.  c  om*/
 */
public SelectInput getCardReaders() throws RemoteException {
    if (this.cardReaders != null)
        return this.cardReaders;

    List<String> available = new ArrayList<String>();

    // Erste Zeile Leerer Eintrag.
    // Damit das Feld auch dann leer bleiben kann, wenn der User nur einen
    // Kartenleser hat. Der sollte dann nicht automatisch vorselektiert
    // werden, da dessen Bezeichnung sonst unnoetigerweise hart gespeichert wird
    available.add("");
    try {
        TerminalFactory terminalFactory = TerminalFactory.getDefault();
        CardTerminals terminals = terminalFactory.terminals();
        if (terminals != null) {
            List<CardTerminal> list = terminals.list();
            if (list != null && list.size() > 0) {
                for (CardTerminal t : list) {
                    String name = StringUtils.trimToNull(t.getName());
                    if (name != null)
                        available.add(name);
                }
            }
        }
    } catch (Throwable t) {
        Logger.info("unable to determine card reader list: " + t.getMessage());
        Logger.write(Level.DEBUG, "stacktrace for debugging purpose", t);
    }

    this.cardReaders = new SelectInput(available, this.getConfig().getCardReader());
    this.cardReaders.setEditable(true);
    this.cardReaders.setComment(i18n.tr("nur ntig, wenn mehrere Leser vorhanden"));
    this.cardReaders.setName(i18n.tr("Identifier des PC/SC-Kartenlesers"));
    return this.cardReaders;
}

From source file:src.eidreader.EstEIDUtil.java

public String readCard(final Boolean full) {
    System.err.println("EIDReader.readCard()");
    return AccessController.doPrivileged(new PrivilegedAction<String>() {
        public String run() {
            try {
                TerminalFactory factory = TerminalFactory.getDefault();
                List<CardTerminal> terminals = factory.terminals().list();

                if (terminals.size() == 0) {
                    return "Error: No card reader found";
                }//  w  ww.  j  a  v a  2  s . c o  m
                //~ throws java.lang.IndexOutOfBoundsException when there is no reader
                CardTerminal terminal = terminals.get(0);

                if (!terminal.isCardPresent()) {
                    return "Error: No card found on terminal";
                    //~ return new EidReaderResponse(new String[] { "No card found on terminal" });
                }
                // "The best way to go is, as explained by Shane, to use the wildcard protocol."
                // https://forums.oracle.com/message/10531935
                Card card = terminal.connect("T=0");
                // Card card = terminal.connect("T=1");
                // Card card = terminal.connect("*");
                System.err.println("Protocol: " + card.getProtocol());
                ATR atr = card.getATR();

                CardChannel channel = card.getBasicChannel();

                if (BelgianReader.matchesEidAtr(atr)) {
                    System.err.println("It's a Belgian card");
                    BelgianReader pf = new BelgianReader(channel);
                    return pf.resultAsString(full);
                }

                System.err.println("It's an Estonian card");
                PersonalFile pf = new PersonalFile(channel);
                return pf.resultAsString(full);
                //~ return new String[] { pf.toString() };
                //~ return new EidReaderResponse(pf.getData());
                //~ return pf.getSurName();
            } catch (Throwable e) {
                //~ return new EidReaderResponse(new String[] { e.toString() });
                e.printStackTrace();
                return "Error: " + e.toString();
            }
        }
    });
}

From source file:test.be.fedict.eid.applet.PcscTest.java

@Test
public void testReadPhoto() throws Exception {
    TerminalFactory terminalFactory = TerminalFactory.getDefault();
    CardTerminals cardTerminals = terminalFactory.terminals();
    CardTerminal cardTerminal = cardTerminals.list().get(0);
    Card card = cardTerminal.connect("T=0");
    CardChannel cardChannel = card.getBasicChannel();
    // select file
    cardChannel.transmit(/*from ww  w  . java 2s.  c om*/
            new CommandAPDU(0x00, 0xA4, 0x08, 0x0C, new byte[] { 0x3F, 0x00, (byte) 0xDF, 0x01, 0x40, 0x35 }));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    int offset = 0;
    ResponseAPDU responseApdu;
    do {
        // read binary
        responseApdu = cardChannel.transmit(new CommandAPDU(0x00, 0xB0, offset >> 8, offset & 0xFF, 0xff));
        baos.write(responseApdu.getData());
        offset += responseApdu.getData().length;
    } while (responseApdu.getData().length == 0xff);
    BufferedImage photo = ImageIO.read(new ByteArrayInputStream(baos.toByteArray()));
    JOptionPane.showMessageDialog(null, new ImageIcon(photo));
}