FileDocCategorySizeDatePackage
ACEntry.javaAPI DocphoneME MR2 API (J2ME)9471Wed May 02 18:00:38 BST 2007com.sun.satsa.acl

ACEntry

public class ACEntry extends Object
This class represents Access Control Entry.

Fields Summary
private String[]
roots
The list of CA names that correspond to rootId element of ACE.
private int[]
APDUPermissions
APDU permissions (command - mask pairs).
private JCRMIPermission[]
JCRMIPermissions
JCRMI permissions.
Constructors Summary
ACEntry(ACLFileReader r, Vector pin_info)
Constructs ACE.

param
r reader for permissions file.
param
pin_info vector for PIN information.
throws
IOException if I/O error occurs.


        Vector t_roots = new Vector();
        Vector t_apdu = new Vector();
        Vector t_jcrmi = new Vector();

        r.checkWord("{");

        while (true) {

            String s = r.readWord();

            if (s.equals("}")) {
                break;
            }

            if (s.equals("root")) {
                t_roots.addElement(r.readLine());
                continue;
            }

            if (s.equals("apdu")) {
                readAPDUPermission(r, t_apdu);
                continue;
            }

            if (s.equals("jcrmi")) {
                readJCRMIPermission(r, t_jcrmi);
                continue;
            }

            if (s.equals("pin_apdu")) {
                readAPDUPIN(r, pin_info);
                continue;
            }

            if (s.equals("pin_jcrmi")) {
                readJCRMIPIN(r, pin_info);
                continue;
            }

            throw new IOException();
        }

        if (! t_roots.isEmpty()) {
            roots = new String[t_roots.size()];
            for (int i = 0; i < t_roots.size(); i++) {
                roots[i] = (String) t_roots.elementAt(i);
            }
        }

        if (! t_apdu.isEmpty()) {
            APDUPermissions = new int[t_apdu.size() * 2];
            for (int i = 0; i < t_apdu.size(); i++) {
                byte[] data = (byte[]) t_apdu.elementAt(i);
                APDUPermissions[i * 2] = Utils.getInt(data, 0);
                APDUPermissions[i * 2 + 1] = Utils.getInt(data, 4);
            }
        }

        if (! t_jcrmi.isEmpty()) {
            JCRMIPermissions = new JCRMIPermission[t_jcrmi.size()];
            t_jcrmi.copyInto(JCRMIPermissions);
        }
    
Methods Summary
private static intgetPINCommandIndex(java.lang.String s)
Returns PIN operation identifier for given string.

param
s operation name.
return
PIN operation identifier.
throws
IOException if I/O error occurs.


        if (s.equals("verify")) {
            return ACLPermissions.CMD_VERIFY;
        }
        if (s.equals("change")) {
            return ACLPermissions.CMD_CHANGE;
        }
        if (s.equals("disable")) {
            return ACLPermissions.CMD_DISABLE;
        }
        if (s.equals("enable")) {
            return ACLPermissions.CMD_ENABLE;
        }
        if (s.equals("unblock")) {
            return ACLPermissions.CMD_UNBLOCK;
        }
        throw new IOException("Invalid command: " + s);
    
voidgetPermissions(boolean isAPDU, java.util.Vector permissions)
Places permissions from this ACE to the vector.

param
isAPDU if true, place APDU permissions, otherwise - JCRMI permissions
param
permissions the vector for results


        if (isAPDU) {
            if (APDUPermissions != null) {
                permissions.addElement(APDUPermissions);
            }
        } else {
            if (JCRMIPermissions != null) {
                for (int k = 0; k < JCRMIPermissions.length; k++) {
                    permissions.addElement(JCRMIPermissions[k]);
                }
            }
        }
    
booleanhasPermissions()
Verifies if the ACE contains permissions.

return
true if the ACE contains permissions.

        return (APDUPermissions != null || JCRMIPermissions != null);
    
private static voidreadAPDUPIN(ACLFileReader r, java.util.Vector dest)
Reads PIN information from file and adds a new object into vector.

param
r reader for permissions file.
param
dest destination vector.
throws
IOException if I/O error occurs.


        r.checkWord("{");
        r.checkWord("id");
        int id = r.readByte();
        Integer[] commands = new Integer[ACLPermissions.CMD_COUNT];

        while (true) {

            String s = r.readWord();

            if (s.equals("}")) {
                break;
            }

            int index = getPINCommandIndex(s);

            int command = 0;
            for (int i = 0; i < 4; i++) {
                command = (command << 8) | r.readByte();
            }
            commands[index] = new Integer(command);
        }
        dest.addElement(new PINData(id, commands));
    
private static voidreadAPDUPermission(ACLFileReader r, java.util.Vector t_apdu)
Reads APDU permission from file and places it into the vector.

param
r reader for permissions file.
param
t_apdu vector for APDU permissions.
throws
IOException if I/O error occurs.


        r.checkWord("{");

        String s = r.readWord();

        while (true) {

            if (s.equals("}")) {
                break;
            }

            byte[] data = new byte[8];

            for (int i = 0; i < 8; i++) {
                data[i] = (byte) Short.parseShort(s, 16);
                s = r.readWord();
            }
            t_apdu.addElement(data);
        }
    
private static voidreadJCRMIPIN(ACLFileReader r, java.util.Vector dest)
Reads PIN information from file and adds a new object into vector.

param
r reader for permissions file.
param
dest destination vector.
throws
IOException if I/O error occurs.


        r.checkWord("{");
        r.checkWord("id");
        int id = r.readByte();
        String[] commands = new String[ACLPermissions.CMD_COUNT];

        while (true) {

            String s = r.readWord();
            if (s.equals("}")) {
                break;
            }
            commands[getPINCommandIndex(s)] = r.readWord();
        }
        dest.addElement(new PINData(id, commands));
    
private static voidreadJCRMIPermission(ACLFileReader r, java.util.Vector t_jcrmi)
Reads JCRMI permission from file and places it into the vector.

param
r reader for permissions file.
param
t_jcrmi vector for JCRMI permissions.
throws
IOException if I/O error occurs.


        Vector classes = new Vector();
        Vector methods = new Vector();
        String hashModifier = null;

        r.checkWord("{");

        while (true) {

            String s = r.readWord();

            if (s.equals("}")) {
                break;
            }

            if (s.equals("classes")) {
                r.checkWord("{");
                s = r.readWord();
                while (! s.equals("}")) {
                    classes.addElement(s);
                    s = r.readWord();
                }
            } else
            if (s.equals("hashModifier")) {
                hashModifier = r.readWord();
            } else
            if (s.equals("methods")) {
                r.checkWord("{");
                s = r.readWord();
                while (! s.equals("}")) {
                    methods.addElement(s);
                    s = r.readWord();
                }
            } else {
                throw new IOException();
            }
        }

        t_jcrmi.addElement(new JCRMIPermission(hashModifier, classes, methods));
    
booleanverifyPrincipal(java.lang.String root)
Verifies if this ACE describes permissions for this CA.

param
root name of CA that authorized the suite.
return
true if this ACE describes permissions for this CA.


        if (roots == null) {
            return true;
        }

        for (int i = 0; i < roots.length; i++) {
            if (roots[i].equals(root)) {
                return true;
            }
        }

        return false;