001    /*
002     * 
003     * $Revision: 13085 $ $Date: 2008-02-06 18:27:24 +0100 (Mi, 06 Feb 2008) $
004     *
005     * This file is part of ***  M y C o R e  ***
006     * See http://www.mycore.de/ for details.
007     *
008     * This program is free software; you can use it, redistribute it
009     * and / or modify it under the terms of the GNU General Public License
010     * (GPL) as published by the Free Software Foundation; either version 2
011     * of the License or (at your option) any later version.
012     *
013     * This program is distributed in the hope that it will be useful, but
014     * WITHOUT ANY WARRANTY; without even the implied warranty of
015     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016     * GNU General Public License for more details.
017     *
018     * You should have received a copy of the GNU General Public License
019     * along with this program, in a file called gpl.txt or license.txt.
020     * If not, write to the Free Software Foundation Inc.,
021     * 59 Temple Place - Suite 330, Boston, MA  02111-1307 USA
022     */
023    
024    package org.mycore.user;
025    
026    import java.util.ArrayList;
027    
028    /**
029     * This class defines the policies of the MyCoRe user and group objects such as
030     * required fields or password policy. It is implemented as a singleton since
031     * there must not be two instances of this class.
032     * 
033     * @author Detlev Degenhardt
034     * @version $Revision: 13085 $ $Date: 2007-02-13 13:36:37 +0100 (Di, 13 Feb
035     *          2007) $
036     */
037    public class MCRUserPolicy {
038            /** ArrayList with Strings indicating required user fields */
039            private ArrayList<String> reqUserAttributes = null;
040    
041            /** ArrayList with Strings indicating required group fields */
042            private ArrayList<String> reqGroupAttributes = null;
043    
044            /** The one and only instance of this class */
045            private static MCRUserPolicy theInstance = null;
046    
047            /** private constructor to create the singleton instance. */
048            private MCRUserPolicy() {
049                    // For the moment this is hard coded but this will change soon....
050                    reqUserAttributes = new ArrayList<String>();
051                    reqUserAttributes.add("numID");
052                    reqUserAttributes.add("userID");
053                    reqUserAttributes.add("password");
054                    reqUserAttributes.add("creator");
055                    reqUserAttributes.add("primary_group");
056    
057                    reqGroupAttributes = new ArrayList<String>();
058                    reqGroupAttributes.add("groupID");
059                    // reqGroupAttributes.add("creator");
060            }
061    
062            /**
063             * This method is the only way to get an instance of this class. It calls
064             * the private constructor to create the singleton.
065             * 
066             * @return returns the one and only instance of <CODE>MCRUserPolicy</CODE>
067             */
068            public final static synchronized MCRUserPolicy instance() {
069                    if (theInstance == null) {
070                            theInstance = new MCRUserPolicy();
071                    }
072    
073                    return theInstance;
074            }
075    
076            /**
077             * This method returns true if the given field is a required user attribute.
078             * 
079             * @param required
080             *            string value representing a user attribute to check whether it
081             *            is required
082             */
083            public boolean isRequiredForUser(String required) {
084                    return (reqUserAttributes.contains(required)) ? true : false;
085            }
086    
087            /**
088             * This method returns true if the given field is a required group
089             * attribute.
090             * 
091             * @param required
092             *            string value representing a group attribute to check whether
093             *            it is required
094             */
095            public boolean isRequiredForGroup(String required) {
096                    return (reqGroupAttributes.contains(required)) ? true : false;
097            }
098    
099            /**
100             * @return This method returns a ArrayList of strings with the names of
101             *         required user attributes.
102             */
103            public ArrayList<String> getRequiredUserAttributes() {
104                    return reqUserAttributes;
105            }
106    
107            /**
108             * @return This method returns a ArrayList of strings with the names of
109             *         required group attributes.
110             */
111            public ArrayList<String> getRequiredGroupAttributes() {
112                    return reqGroupAttributes;
113            }
114    }