Changeset 172


Ignore:
Timestamp:
06/28/11 14:41:38 (12 years ago)
Author:
merek
Message:

Backporting start and expiration date feature from branch

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/changelog.txt

    r142 r172  
    2929- Added: DreamboxPlugin (csp-agent) support for more/older dm500 images. Basic (unsecured) file upload support.
    3030- Added: proxy-reference.html updated with highlighting for important elements and additional examples.
     31- Added: Ability to set start and expiration date for user accounts.
    3132
    3233- Changes to proxy.xml:
  • trunk/config/proxy-reference.html

    r165 r172  
    793793
    794794<a name="user-manager/auth-config/user">
    795 <div class='indent'><strong>user-manager/auth-config/user (attributes: *name, *password, display-name, ip-mask, profiles, max-connections, admin, enabled)</strong></div><br />
     795<div class='indent'><strong>user-manager/auth-config/user (attributes: *name, *password, display-name, ip-mask, profiles, max-connections, admin, enabled, map-exclude, start-date, expiration-date, debug)</strong></div><br />
    796796One user definition for the SimpleUserManager (also used by the XmlUserManager, see <strong>README.XmlUserManager.txt</strong> for more details):<br /><br />
    797797- <strong class='bold'>name</strong>: User name, avoid long names, spaces and special characters. There are no particular limitations as far as the proxy is concerned, but the camd clients may have them.<br />
     
    804804- <strong class='bold'>enabled</strong>: true/false (default: true). Allows disabling of accounts without deleting them.<br />
    805805- <strong class='bold'>map-exclude</strong>: true/false (default: false). Set to true to prevent the user from causing changes to the service maps. If a particular user is sending bad ecms or is otherwise misbehaving, this will protect the service mappings and ensure no other users are affected. Only use this if you are sure a particular client is misbehaving, the service mapping can't work if no clients are allowed to update the map.<br />
     806- <strong class='bold'>start-date</strong>: (dd-mm-yyyy) Start date for user account.<br />
     807- <strong class='bold'>expiration-date</strong>: (dd-mm-yyyy) Expiration date for the user account.<br />
    806808- <strong class='bold'>debug</strong>: true/false (default: false). Set to true to enable ecm/emm/zap logging for this user only (has no effect if these are already enabled globally).<br />
    807809<br />
  • trunk/src/com/bowman/cardserv/SimpleUserManager.java

    r165 r172  
    7070    } catch (ConfigException e) {}
    7171
     72    String startDate = null;
     73    try {
     74      startDate = xml.getStringValue("start-date");
     75    } catch (ConfigException e) {}
     76
     77    String expirationDate = null;
     78    try {
     79      expirationDate = xml.getStringValue("expiration-date");
     80    } catch (ConfigException e) {}
     81
    7282    int maxConnections = xml.getIntValue("max-connections", -1);
    7383
     
    7888
    7989    UserEntry user = new UserEntry(xml.getStringValue("name"), xml.getStringValue("password"), ipMask, emailAddr,
    80         maxConnections, enabled, admin, exclude, debug);
     90        maxConnections, enabled, admin, exclude, startDate, expirationDate, debug);
    8191
    8292    try {
     
    164174  }
    165175
     176  public String getStartDate(String user) {
     177    UserEntry entry = getUser(user);
     178    if(entry == null) return null;
     179    else return entry.startDate;
     180  }
     181
     182  public String getExpirationDate(String user) {
     183    UserEntry entry = getUser(user);
     184    if(entry == null) return null;
     185    else return entry.expirationDate;
     186  }
     187
    166188  public Set getAllowedProfiles(String user) {
    167189    UserEntry entry = getUser(user);
     
    235257    String ipMask;
    236258    String email, displayName;
     259    String startDate, expirationDate;
    237260    int maxConnections;
    238261    boolean enabled, admin, exclude, debug;
     
    240263
    241264    public UserEntry(String name, String password, String ipMask, String email, int maxConnections, boolean enabled,
    242                      boolean admin, boolean exclude, boolean debug)
     265                     boolean admin, boolean exclude, String startDate, String expirationDate, boolean debug)
    243266    {
    244267      this.name = name;
     
    251274      this.admin = admin;
    252275      this.exclude = exclude;
     276      this.startDate = startDate;
     277      this.expirationDate = expirationDate;
    253278      this.debug = debug;
    254279    }
  • trunk/src/com/bowman/cardserv/interfaces/UserManager.java

    r165 r172  
    3434  Set getAllowedConnectors(String user); // return Set of String, null for all
    3535  int getAllowedEcmRate(String user); // return minimum interval between ecm in seconds, -1 for no limit
     36  String getStartDate(String user);
     37  String getExpirationDate(String user);
    3638
    3739}
  • trunk/src/com/bowman/cardserv/rmi/RemoteHandler.java

    r165 r172  
    175175      } else {
    176176        String displayName = session.isTempUser()?session.getLoginName():um.getDisplayName(name);
    177         user = new UserStatus(name, displayName, um.getMaxConnections(name), false);
     177        user = new UserStatus(name, displayName, um.getStartDate(name), um.getExpirationDate(name), um.getMaxConnections(name), false);
    178178        user.addSession(session);
    179179        users.put(name, user);
     
    205205        if(user == null) {
    206206          String displayName = session.isTempUser()?session.getLoginName():um.getDisplayName(userName);
    207           user = new UserStatus(userName, displayName, um.getMaxConnections(userName), um.isAdmin(userName));
     207          user = new UserStatus(userName, displayName, um.getStartDate(userName), um.getExpirationDate(userName), um.getMaxConnections(userName), um.isAdmin(userName));
    208208        }
    209209        user.addSession(session);
  • trunk/src/com/bowman/cardserv/rmi/UserStatus.java

    r165 r172  
    1717  private static final long serialVersionUID = -4091190186183181716L;
    1818
    19   private final String userName, displayName;
     19  private final String userName, displayName, startDate, expirationDate;
    2020  private final boolean admin;
    2121  private final int maxSessions;
     
    2323  private final List sessions = new ArrayList();
    2424
    25   public UserStatus(String userName, String displayName, int maxSessions, boolean admin) {
     25  public UserStatus(String userName, String displayName, String startDate, String expirationDate, int maxSessions, boolean admin) {
    2626    this.userName = userName;
    2727    this.displayName = displayName;
    2828    this.admin = admin;
     29    this.startDate = startDate;
     30    this.expirationDate = expirationDate;
    2931    this.maxSessions = maxSessions;
    3032  }
     
    4042  public boolean isAdmin() {
    4143    return admin;
     44  }
     45
     46  public String getStartDate() {
     47    return startDate;
     48  }
     49
     50  public String getExpirationDate() {
     51    return expirationDate;
    4252  }
    4353
  • trunk/src/com/bowman/cardserv/session/NewcamdSession.java

    r165 r172  
    99import java.net.*;
    1010import java.io.*;
     11import java.text.DateFormat;
     12import java.text.ParseException;
     13import java.text.SimpleDateFormat;
    1114import java.util.*;
    1215
     
    113116          } else if(checkProfile && !profiles.contains(getProfileName())) {
    114117            loginFailure(user, "no access for profile: " + getProfileName(), msg);
     118          } else if(checkAccountExpired(user, um) || checkAccountStarted(user, um)) {
     119            loginFailure(user, "account has expired or has not reached start date yet", msg);
    115120          } else { // successful login
    116121
     
    189194            checksOk = checksOk && handleMessage(msg);
    190195            fireCamdMessage(msg, false); // still need to notify the rest of the proxy about the bad message to give plugins and logging a chance to see it
     196            if(checkAccountExpired(this.user, um)) {
     197              logger.warning("'User '" + user + "' kicked, account has expired");
     198              close();
     199            }
    191200            if(!checksOk) {
    192201              setFlag(msg, 'B');
     
    211220  protected boolean checkClientId(String id) {
    212221    return true;
     222  }
     223
     224  public boolean checkAccountStarted(String user, UserManager um) {
     225    Date startedDateDt = null;
     226    try {
     227      String startedDateStr = um.getStartDate(user);
     228      DateFormat df = new SimpleDateFormat("dd-MM-yyyy");
     229      if (startedDateStr == null)
     230        startedDateDt = null;
     231      else
     232        startedDateDt = df.parse(startedDateStr);
     233    }
     234    catch(ParseException ignored) {}
     235    long currDateMs = System.currentTimeMillis();
     236    long startedDateMs = 0;
     237
     238    if (startedDateDt != null)
     239      startedDateMs = startedDateDt.getTime();
     240
     241    return (startedDateMs != 0) && (currDateMs < startedDateMs);
     242  }
     243
     244  public boolean checkAccountExpired(String user, UserManager um) {
     245    Date expirationDateDt = null;
     246    long currDate = System.currentTimeMillis();
     247    long expirationDateMs = 0L;
     248    try
     249    {
     250      String expirationDateStr = um.getExpirationDate(user);
     251      DateFormat df = new SimpleDateFormat("dd-MM-yyyy");
     252
     253      if(expirationDateStr == null)
     254        expirationDateDt = null;
     255      else
     256        expirationDateDt = df.parse(expirationDateStr);
     257    }
     258    catch(ParseException ex) { }
     259    currDate = System.currentTimeMillis();
     260    expirationDateMs = 0L;
     261
     262    if(expirationDateDt != null)
     263      expirationDateMs = expirationDateDt.getTime();
     264
     265    return expirationDateMs != 0L && currDate > expirationDateMs;
    213266  }
    214267
  • trunk/src/com/bowman/cardserv/web/XmlHelper.java

    r165 r172  
    872872      xb.appendElement("user", "name", users[i].getUserName());
    873873      xb.appendAttr("display-name", users[i].getDisplayName());
     874      xb.appendAttr("start-date", users[i].getStartDate());
     875      xb.appendAttr("expiration-date", users[i].getExpirationDate());
    874876      if(users[i].isAdmin()) xb.appendAttr("admin", users[i].isAdmin());
    875877
Note: See TracChangeset for help on using the changeset viewer.