Package de.netsysit.policymanager

Source Code of de.netsysit.policymanager.Enums

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package de.netsysit.policymanager;

import java.util.EnumSet;
import java.util.ResourceBundle;

/**
* This class contains all the Enums used in the program.
* @author Ducksoul
*/
public final class Enums {
    private final static ResourceBundle rb = PolicyUtilities.getResourceBundle();
   
   
    /**
     * The enum ItemTypes contains all the possible types of items that are
     * used in the program. To each itemtype the corresponding enum Card will be
     * stored.
     */
    public static enum ItemTypes {
        /**
         * Applications
         */
        APP(Cards.APP),
        /**
         * ReceiverLists
         */
        LIST(Cards.LIST),
        /**
         * Policies
         */
        POLICY(Cards.POLICY),
        /**
         * No ItemType
         */
        NONE;
       
        private Cards card;
       
        ItemTypes() {
            this.card = null;
        }
       
        ItemTypes(Cards card) {
            this.card = card;
        }
       
        /**
         *
         * @return A String with the name of the card
         */
        public String getCardString() {
            return card.toString();
        }
       
        /**
         *
         * @return A Cards enum that corresponds to the card
         */
        public Cards getCard() {
            return card;
        }
    };

    /**
     * The enum PolicyLevel contains all the possible levels of policies that
     * are allowed in the program.
     */
    public static enum PolicyLevel {

        /**
         * A - Authentizität
         */
        A,
        /**
         *
         */
        C,
        /**
         * I - Integrität
         */
        I,
        /**
         * No Level
         */
        NONE;
    };
   
    /**
     * The enum ApplicationBase contains all the possible base values of the
     * mapping.
     */
    public static enum ApplicationBase {
        /**
         * Value represents low security.
         */
        LOW(rb.getString("low")),
        /**
         * Value represents normal security.
         */
        NORMAL(rb.getString("normal")),
        /**
         * Value represents high security.
         */
        HIGH(rb.getString("high")),
        /**
         * No base value.
         */
        NONE(rb.getString("levelnone"));
       
        private String name;
       
        ApplicationBase(String name) {
            this.name = name;
        }
       
        @Override
        public String toString() {
            return name;
        }   
    }
   
    /**
     * This method returns an EnumSet with all possible base values.
     * @return An EnumSet
     */
    public static EnumSet getSecurityLevels() {
        return EnumSet.allOf(ApplicationBase.class);
    }
   
    /**
     * In this enum all of the supported security algorithms are stored. An
     * algorithm can contain a set of possible modes. The Level it is related to
     * and the name of the algorithm have to be defined.
     */
    public static enum Algorithms {
       
        /**
         * AES 128 algorithm
         * modes: Cipher-block chaining (CBC) / Cipher feedback(CFB)
         */
        AES128(EnumSet.of(Modes.CBC, Modes.CFB), PolicyLevel.C, rb.getString("aes128")),
        /**
         * AES 192 algorithm
         * modes: Cipher-block chaining (CBC) / Cipher feedback(CFB)
         */
        AES192(EnumSet.of(Modes.CBC, Modes.CFB), PolicyLevel.C, rb.getString("aes192")),
        /**
         * AES 256 algorithm
         * modes: Cipher-block chaining (CBC) / Cipher feedback(CFB)
         */
        AES256(EnumSet.of(Modes.CBC, Modes.CFB), PolicyLevel.C, rb.getString("aes256")),
        /**
         * 3DES
         * modes: none
         */
        DES(PolicyLevel.C, rb.getString("3des")),
        /**
         * SHA 1
         * modes: none
         */
        SHA1(PolicyLevel.I, rb.getString("sha1")),
        /**
         * SHA 256
         * modes: none
         */
        SHA256(PolicyLevel.I, rb.getString("sha256")),
        /**
         * SHA 384
         * modes: none
         */
        SHA384(PolicyLevel.I, rb.getString("sha384")),
        /**
         * SHA 512
         * modes: none
         */
        SHA512(PolicyLevel.I, rb.getString("sha512")),
        /**
         * Unknown algorithm - should not be possible
         */
        UNKNOWN(rb.getString("unknown")),
        /**
         * Algorithm hasn't been selected yet.
         * level: PolicyLevel.A
         */
        NOTDEFINEDA(PolicyLevel.A, rb.getString("notchosen")),
        /**
         * Algorithm hasn't been selected yet.
         * level: PolicyLevel.C
         */
        NOTDEFINEDC(PolicyLevel.C, rb.getString("notchosen")),
        /**
         * Algorithm hasn't been selected yet.
         * level: PolicyLevel.I
         */
        NOTDEFINEDI(PolicyLevel.I, rb.getString("notchosen"));
       
        private EnumSet cModes;
        private PolicyLevel level;
        private String name;
       
        Algorithms(EnumSet cModes, PolicyLevel level, String name) {
            this.cModes = cModes;
            this.level = level;   
            this.name = name;
        }
       
        Algorithms(PolicyLevel level, String name) {
            this.level = level;
            this.cModes = EnumSet.of(Modes.NONE);
            this.name = name;
        }
       
        Algorithms(String name) {
            this.level = PolicyLevel.NONE;
            this.name = name;
        }
       
        /**
         * This method returns an EnumSet with the compatible Modes of the
         * algorithm.
         * @return An EnumSet
         */
        public EnumSet getCompatibleModes() {
            return  cModes;
        }
       
        /**
         * This method returns the PolicyLevel the algorithm is related to.
         * @return A PolicyLevel
         */
        public PolicyLevel getLevel() {
            return level;
        }
       
        @Override
        public String toString() {
            return name;
        }       
    }
   
    /**
     * This method returns all valid algorithms for PolicyLevel.A.
     * @return An EnumSet with all valid algorithms.
     */
    public static EnumSet getAAlgorithms() {
        EnumSet aAlgorithms = EnumSet.noneOf(Algorithms.class);
        for (Algorithms val : Algorithms.values()) {
            if (val.getLevel() == PolicyLevel.A) {
                aAlgorithms.add(val);
            }
        }
        return aAlgorithms;
    }
   
    /**
     * This method returns all valid algorithms for PolicyLevel.C.
     * @return An EnumSet with all valid algorithms.
     */
    public static EnumSet getCAlgorithms() {
        EnumSet cAlgorithms = EnumSet.noneOf(Algorithms.class);
        for (Algorithms val : Algorithms.values()) {
            if (val.getLevel() == PolicyLevel.C) {
                cAlgorithms.add(val);
            }
        }
        return cAlgorithms;
    }

    /**
     * This method returns all valid algorithms for PolicyLevel.I.
     * @return An EnumSet with all valid algorithms.
     */
    public static EnumSet getIAlgorithms() {
        EnumSet iAlgorithms = EnumSet.noneOf(Algorithms.class);
        for (Algorithms val : Algorithms.values()) {
            if (val.getLevel() == PolicyLevel.I) {
                iAlgorithms.add(val);
            }
        }
        return iAlgorithms;
    }   
   
    /**
     * In this enum all of the possible algorithm modes are stored.
     */
    public static enum Modes {
        /**
         * Cipher-block chaining (CBC)
         */
        CBC(rb.getString("cbc")),
        /**
         * Cipher feedback(CFB)
         */
        CFB(rb.getString("cfb")),
        /**
         * None
         */
        NONE(rb.getString("modenone"));
       
        private String name;
       
        Modes(String name) {
            this.name = name;
        }
       
        @Override
        public String toString() {
            return name;
        }
    }
   
    /**
     * This enum is used to store the options that can be chosen in the most
     * left JList of the mainframe. This makes it easy to implement new features
     * to the program in a later state.
     */
    public static enum Cards {
        /**
         * Applications
         */
        APP(rb.getString("apps")),
        /**
         * Receiverlists
         */
        LIST(rb.getString("receiverlists")),
        /**
         * Policies
         */
        POLICY(rb.getString("policies"));
       
        private String name;
       
        Cards(String name) {
            this.name = name;
        }
       
        @Override
        public String toString() {
            return name;
        }       
    }
   
    /**
     * This method returns all the options that can be chosen in the most
     * left JList of the mainframe.
     * @return An EnumsSet
     */
    public static EnumSet getCards() {
        return EnumSet.allOf(Cards.class);
    }
}
TOP

Related Classes of de.netsysit.policymanager.Enums

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.