001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package com.sun.satsa.acl;
028:
029: import com.sun.satsa.acl.ACEntry;
030: import com.sun.satsa.util.Utils;
031:
032: import java.util.Vector;
033: import java.io.IOException;
034:
035: /**
036: * This class represents access control list (ACL).
037: */
038: public class ACList {
039:
040: /**
041: * AID for this ACL.
042: */
043: private byte[] AID;
044: /**
045: * The list of ACEs.
046: */
047: private Vector ACEntries = new Vector();
048:
049: /** PIN information for APDU connection. */
050: private PINData[] PINInfo;
051:
052: /**
053: * Constructs ACL object.
054: * @param r reader for permissions file.
055: * @throws IOException if I/O error occurs.
056: */
057: ACList(ACLFileReader r) throws IOException {
058:
059: byte[] aid = new byte[16];
060:
061: int count = 0;
062: String s = r.readWord();
063: while (!s.equals("{")) {
064: aid[count++] = (byte) Short.parseShort(s, 16);
065: s = r.readWord();
066: }
067:
068: if (count > 0) {
069: AID = new byte[count];
070: System.arraycopy(aid, 0, AID, 0, count);
071: }
072:
073: Vector pin_info = new Vector();
074:
075: while (true) {
076:
077: s = r.readWord();
078:
079: if (s.equals("}")) {
080: break;
081: }
082:
083: if (!s.equals("ace")) {
084: throw new IOException();
085: }
086:
087: ACEntries.addElement(new ACEntry(r, pin_info));
088: }
089:
090: PINInfo = new PINData[pin_info.size()];
091: pin_info.copyInto(PINInfo);
092: }
093:
094: /**
095: * Verifies if this ACL describes permissions for AID in SELECT APDU.
096: * @param selectAPDU SELECT APDU command data.
097: * @return true if this ACL describes permissions for AID in SELECT APDU.
098: */
099: public boolean match(byte[] selectAPDU) {
100: return (AID == null)
101: || (AID.length == selectAPDU[4] && Utils.byteMatch(AID,
102: 0, AID.length, selectAPDU, 5, AID.length));
103: }
104:
105: /**
106: * Returns the list of ACEs.
107: * @return the list of ACEs.
108: */
109: public Vector getACEntries() {
110: return ACEntries;
111: }
112:
113: /**
114: * Places information about PINs into the vector.
115: * @param isAPDU if true, place APDU PIN data, otherwise - JCRMI
116: * PIN data.
117: * @param result the vector for results
118: */
119: void getPINs(boolean isAPDU, Vector result) {
120: for (int i = 0; i < PINInfo.length; i++) {
121: if (isAPDU == (PINInfo[i].commands instanceof Integer[])) {
122: result.addElement(PINInfo[i]);
123: }
124: }
125: }
126: }
|