001: /***
002: * jwma Java WebMail
003: * Copyright (c) 2000-2003 jwma team
004: *
005: * jwma is free software; you can distribute and use this source
006: * under the terms of the BSD-style license received along with
007: * the distribution.
008: ***/package dtw.webmail.util.config;
009:
010: import dtw.webmail.util.StringUtil;
011:
012: import java.util.Set;
013: import java.util.TreeSet;
014: import java.util.Collections;
015: import java.io.Serializable;
016:
017: /**
018: * This class...
019: * <p>
020: * @author Dieter Wimberger (wimpi)
021: * @version (created Feb 24, 2003)
022: */
023: public class Administration implements Serializable {
024:
025: private Set m_Admins;
026: private boolean m_Enabled = false;
027:
028: public Administration() {
029: m_Admins = Collections.synchronizedSet(new TreeSet());
030: }//constructor
031:
032: /**
033: * Tests if the administration part is enabled.
034: *
035: * @return true if enabled, false otherwise.
036: */
037: public boolean isEnabled() {
038: return m_Enabled;
039: }//isEnabled
040:
041: /**
042: * Sets the flag that controls if the adminstration part
043: * is enabled.
044: *
045: * @param b true if enabled, false otherwise.
046: */
047: public void setEnabled(boolean b) {
048: m_Enabled = b;
049: }//setEnabled
050:
051: /**
052: * Convenience method for obtaining the admin users
053: * (by username) as a simple comma seperated list.
054: * <p>
055: * Note that this is supposed to be helpful for simplifying
056: * the persistency mechanism.
057: *
058: * @return the list as <tt>String</tt>.
059: */
060: public String getAdminList() {
061: return StringUtil.join(listAdmins(), ",");
062: }//getAdminList
063:
064: /**
065: * Convenience method for setting the admin users
066: * (by username) as a simple comma seperated list.
067: * <p>
068: * Note that this is supposed to be helpful for simplifying
069: * the persistency mechanism.
070: *
071: * @return the list as <tt>String</tt>.
072: */
073: public void setAdminList(String list) {
074: String[] admins = StringUtil.split(list, ",");
075: m_Admins.clear();
076: for (int i = 0; i < admins.length; i++) {
077: addAdmin(admins[i]);
078: }
079: }//setAdminList
080:
081: /**
082: * Returns the list of users (by username) with
083: * administrative rights.
084: *
085: * @return the list as <tt>String[]</tt>.
086: */
087: public String[] listAdmins() {
088: String[] admins = new String[m_Admins.size()];
089: return (String[]) m_Admins.toArray(admins);
090: }//getAdminUsernames
091:
092: /**
093: * Adds an administrator (by username).
094: *
095: * @param username the username as <tt>String</tt>.
096: */
097: public void addAdmin(String username) {
098: //check if contains
099: m_Admins.add(username);
100: }//addAdmin
101:
102: /**
103: * Removes an administrator (by username).
104: *
105: * @param username the username as <tt>String</tt>.
106: */
107: public void removeAdmin(String username) {
108: m_Admins.remove(username);
109: }//removeAdmin
110:
111: /**
112: * Tests if a given user (by username) has
113: * administrative rights.
114: *
115: * @return true if admin rights, false otherwise.
116: */
117: public boolean isAdmin(String username) {
118: return m_Admins.contains(username);
119: }//isAdmin
120:
121: }//class Administration
|