incubator-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ran...@apache.org
Subject cvs commit: incubator-ftpserver/src/java/org/apache/ftpserver/usermanager PropertiesUserManager.java LdapUserManager.java
Date Mon, 23 Jun 2003 16:33:59 GMT
rana_b      2003/06/23 09:33:59

  Modified:    src/java/org/apache/ftpserver/usermanager
                        PropertiesUserManager.java LdapUserManager.java
  Log:
  user attributes used
  
  Revision  Changes    Path
  1.2       +22 -19    incubator-ftpserver/src/java/org/apache/ftpserver/usermanager/PropertiesUserManager.java
  
  Index: PropertiesUserManager.java
  ===================================================================
  RCS file: /home/cvs/incubator-ftpserver/src/java/org/apache/ftpserver/usermanager/PropertiesUserManager.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PropertiesUserManager.java	31 Mar 2003 06:50:26 -0000	1.1
  +++ PropertiesUserManager.java	23 Jun 2003 16:33:59 -0000	1.2
  @@ -145,13 +145,13 @@
          String thisPrefix = PREFIX + usr.getName() + '.';
   
          // set other properties
  -       mUserData.setProperty(thisPrefix+"password", getPassword(usr));
  -       mUserData.setProperty(thisPrefix+"home",     usr.getVirtualDirectory().getRootDirectory());
  -       mUserData.setProperty(thisPrefix+"enabled",  usr.getEnabled());
  -       mUserData.setProperty(thisPrefix+"write",    usr.getVirtualDirectory().getWritePermission());
  -       mUserData.setProperty(thisPrefix+"idle",     usr.getMaxIdleTime());
  -       mUserData.setProperty(thisPrefix+"upload",   usr.getMaxUploadRate());
  -       mUserData.setProperty(thisPrefix+"download", usr.getMaxDownloadRate());
  +       mUserData.setProperty(thisPrefix + User.ATTR_PASSWORD,          getPassword(usr));
  +       mUserData.setProperty(thisPrefix + User.ATTR_HOME,              usr.getVirtualDirectory().getRootDirectory());
  +       mUserData.setProperty(thisPrefix + User.ATTR_ENABLE,            usr.getEnabled());
  +       mUserData.setProperty(thisPrefix + User.ATTR_WRITE_PERM,        usr.getVirtualDirectory().getWritePermission());
  +       mUserData.setProperty(thisPrefix + User.ATTR_MAX_IDLE_TIME,     usr.getMaxIdleTime());
  +       mUserData.setProperty(thisPrefix + User.ATTR_MAX_UPLOAD_RATE,   usr.getMaxUploadRate());
  +       mUserData.setProperty(thisPrefix + User.ATTR_MAX_DOWNLOAD_RATE, usr.getMaxDownloadRate());
   
          // save user data
          FileOutputStream fos = null;
  @@ -202,6 +202,7 @@
   
       /**
        * Get user password. Returns the encrypted value.
  +     * <pre>
        * If the password value is not null
        *    password = new password
        * else
  @@ -209,6 +210,7 @@
        *     password = old password
        *   else
        *     password = ""
  +     * </pre>
        */
       private String getPassword(User usr) {
           String password = usr.getPassword();
  @@ -218,7 +220,7 @@
               }
           }
           else if ( doesExist(usr.getName()) ) {
  -            String key = PREFIX + usr.getName() + ".password";
  +            String key = PREFIX + usr.getName() + '.' + User.ATTR_PASSWORD;
               password = mUserData.getProperty(key, "");
           }
   
  @@ -236,13 +238,14 @@
       public synchronized List getAllUserNames() {
   
           // get all user names
  +        String suffix = '.' + User.ATTR_HOME;
           ArrayList ulst = new ArrayList();
           Enumeration allKeys = mUserData.propertyNames();
           while(allKeys.hasMoreElements()) {
               String key = (String)allKeys.nextElement();
  -            if(key.endsWith(".home")) {
  +            if(key.endsWith(suffix)) {
                   String name = key.substring(PREFIX.length());
  -                int endIndex = name.length() - ".home".length();
  +                int endIndex = name.length() - suffix.length();
                   name = name.substring(0, endIndex);
                   ulst.add(name);
               }
  @@ -265,12 +268,12 @@
           String baseKey = PREFIX + userName + '.';
           User user = new User();
           user.setName(userName);
  -        user.setEnabled(mUserData.getBoolean(baseKey + "enabled", true));
  -        user.getVirtualDirectory().setRootDirectory( mUserData.getFile(baseKey + "home",
new File("/")) );
  -        user.getVirtualDirectory().setWritePermission(mUserData.getBoolean(baseKey + "write",
false));
  -        user.setMaxIdleTime(mUserData.getInteger(baseKey + "idle", 0));
  -        user.setMaxUploadRate(mUserData.getInteger(baseKey + "upload", 0));
  -        user.setMaxDownloadRate(mUserData.getInteger(baseKey + "download", 0));
  +        user.setEnabled(mUserData.getBoolean(baseKey + User.ATTR_ENABLE, true));
  +        user.getVirtualDirectory().setRootDirectory( mUserData.getFile(baseKey + User.ATTR_HOME,
new File("/")) );
  +        user.getVirtualDirectory().setWritePermission(mUserData.getBoolean(baseKey + User.ATTR_WRITE_PERM,
false));
  +        user.setMaxIdleTime(mUserData.getInteger(baseKey + User.ATTR_MAX_IDLE_TIME, 0));
  +        user.setMaxUploadRate(mUserData.getInteger(baseKey + User.ATTR_MAX_UPLOAD_RATE,
0));
  +        user.setMaxDownloadRate(mUserData.getInteger(baseKey + User.ATTR_MAX_DOWNLOAD_RATE,
0));
           return user;
       }
   
  @@ -279,7 +282,7 @@
        * User existance check
        */
       public synchronized boolean doesExist(String name) {
  -        String key = PREFIX + name + ".home";
  +        String key = PREFIX + name + '.' + User.ATTR_HOME;
           return mUserData.containsKey(key);
       }
   
  @@ -288,7 +291,7 @@
        * User authenticate method
        */
       public synchronized boolean authenticate(String user, String password) {
  -        String passVal = mUserData.getProperty(PREFIX + user + ".password");
  +        String passVal = mUserData.getProperty(PREFIX + user + '.' + User.ATTR_PASSWORD);
           if (mbEncrypt) {
               password = EncryptUtils.encryptMD5(password);
           }
  
  
  
  1.2       +41 -52    incubator-ftpserver/src/java/org/apache/ftpserver/usermanager/LdapUserManager.java
  
  Index: LdapUserManager.java
  ===================================================================
  RCS file: /home/cvs/incubator-ftpserver/src/java/org/apache/ftpserver/usermanager/LdapUserManager.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LdapUserManager.java	31 Mar 2003 06:50:26 -0000	1.1
  +++ LdapUserManager.java	23 Jun 2003 16:33:59 -0000	1.2
  @@ -125,31 +125,23 @@
   
   
       // LDAP attributes
  -    private static final String LOGIN      = "memberuid";
  -    private static final String UID        = "uid";
  -    private static final String CN         = "cn";
  -    private static final String SN         = "sn";
  -    private static final String PASSWORD   = "userpassword";
  -    private static final String OBJ_CLASS  = "objectclass";
  -    private static final String ENABLE     = "enableflag";
  -    private static final String ROOT_DIR   = "homedirectory";
  -    private static final String WRITE_PERM = "writepermission";
  -    private static final String IDLE_TIME  = "idletime";
  -    private static final String UP_RATE    = "uploadrate";
  -    private static final String DOWN_RATE  = "downloadrate";
  -
  -    private static final String[] ALL_ATTRS = {
  -        UID,
  -        ENABLE,
  -        ROOT_DIR,
  -        WRITE_PERM,
  -        IDLE_TIME,
  -        UP_RATE,
  -        DOWN_RATE
  +    private final static String LOGIN      = "memberuid";
  +    private final static String CN         = "cn";
  +    private final static String SN         = "sn";
  +    private final static String OBJ_CLASS  = "objectclass";
  +    
  +    private final static String[] ALL_ATTRS = {
  +        User.ATTR_LOGIN,
  +        User.ATTR_ENABLE,
  +        User.ATTR_HOME,
  +        User.ATTR_WRITE_PERM,
  +        User.ATTR_MAX_IDLE_TIME,
  +        User.ATTR_MAX_UPLOAD_RATE,
  +        User.ATTR_MAX_DOWNLOAD_RATE
       };
   
       private final static String[] UID_ATTRS = {
  -        UID
  +        User.ATTR_LOGIN
       };
   
   
  @@ -183,9 +175,9 @@
           String password = conf.getChild("password").getValue();
           String auth     = conf.getChild("authentication").getValue();
   
  -        String ldapRoot = conf.getChild("root").getValue();
  -        String prefix   = conf.getChild("prefix").getValue();
  -        String suffix   = conf.getChild("suffix").getValue();
  +        mstRoot     = conf.getChild("root").getValue();
  +        mstDnPrefix = conf.getChild("prefix").getValue();
  +        mstDnSuffix = conf.getChild("suffix").getValue();
   
           try {
               mAdminEnv = new Properties();
  @@ -196,9 +188,6 @@
               mAdminEnv.setProperty(Context.SECURITY_CREDENTIALS, password);
               mAdminContext = new InitialDirContext(mAdminEnv);
   
  -            mstRoot = ldapRoot;
  -            mstDnPrefix = prefix;
  -            mstDnSuffix = suffix;
   
               // create objectClass attribute
               mObjClassAttr = new BasicAttribute(OBJ_CLASS, false);
  @@ -228,7 +217,7 @@
               NamingEnumeration answers = mAdminContext.search(mstRoot, matchAttrs, UID_ATTRS);
               while (answers.hasMore()) {
                   SearchResult sr = (SearchResult)answers.next();
  -                String uid = sr.getAttributes().get(UID).get().toString();
  +                String uid = sr.getAttributes().get(User.ATTR_LOGIN).get().toString();
                   allUsers.add(uid);
               }
           }
  @@ -252,13 +241,13 @@
               Attributes attrs = mAdminContext.getAttributes(dn, ALL_ATTRS);
   
               user = new User();
  -            user.setName(attrs.get(UID).get().toString());
  -            user.getVirtualDirectory().setRootDirectory(new File(attrs.get(ROOT_DIR).get().toString()));
  -            user.setEnabled(Boolean.TRUE.toString().equals(attrs.get(ENABLE).get().toString()));
  -            user.getVirtualDirectory().setWritePermission(Boolean.TRUE.toString().equals(attrs.get(WRITE_PERM).get().toString()));
  -            user.setMaxIdleTime( Integer.parseInt(attrs.get(IDLE_TIME).get().toString())
);
  -            user.setMaxUploadRate( Integer.parseInt(attrs.get(UP_RATE).get().toString())
);
  -            user.setMaxDownloadRate( Integer.parseInt(attrs.get(DOWN_RATE).get().toString())
);
  +            user.setName(attrs.get(User.ATTR_LOGIN).get().toString());
  +            user.getVirtualDirectory().setRootDirectory(new File(attrs.get(User.ATTR_HOME).get().toString()));
  +            user.setEnabled(Boolean.TRUE.toString().equals(attrs.get(User.ATTR_ENABLE).get().toString()));
  +            user.getVirtualDirectory().setWritePermission(Boolean.TRUE.toString().equals(attrs.get(User.ATTR_WRITE_PERM).get().toString()));
 
  +            user.setMaxIdleTime( Integer.parseInt(attrs.get(User.ATTR_MAX_IDLE_TIME).get().toString())
);
  +            user.setMaxUploadRate( Integer.parseInt(attrs.get(User.ATTR_MAX_UPLOAD_RATE).get().toString())
);
  +            user.setMaxDownloadRate( Integer.parseInt(attrs.get(User.ATTR_MAX_DOWNLOAD_RATE).get().toString())
);
           }
           catch(Exception ex) {
               getLogger().error("LdapUserManager.getUserByName()", ex);
  @@ -330,19 +319,19 @@
   
           Attributes attrs = new BasicAttributes(true);
           attrs.put(new BasicAttribute(LOGIN, user.getName()));
  -        attrs.put(new BasicAttribute(UID, user.getName()));
  +        attrs.put(new BasicAttribute(User.ATTR_LOGIN, user.getName()));
           attrs.put(new BasicAttribute(CN, user.getName()));
           attrs.put(new BasicAttribute(SN, user.getName()));
  -        attrs.put(new BasicAttribute(PASSWORD, user.getPassword()));
  +        attrs.put(new BasicAttribute(User.ATTR_PASSWORD, user.getPassword()));
   
           attrs.put(mObjClassAttr);
   
  -        attrs.put(new BasicAttribute(ENABLE, String.valueOf(user.getEnabled())));
  -        attrs.put(new BasicAttribute(ROOT_DIR, user.getVirtualDirectory().getRootDirectory()));
  -        attrs.put(new BasicAttribute(WRITE_PERM, String.valueOf(user.getVirtualDirectory().getWritePermission())));
  -        attrs.put(new BasicAttribute(IDLE_TIME, String.valueOf(user.getMaxIdleTime())));
  -        attrs.put(new BasicAttribute(UP_RATE, String.valueOf(user.getMaxUploadRate())));
  -        attrs.put(new BasicAttribute(DOWN_RATE, String.valueOf(user.getMaxDownloadRate())));
  +        attrs.put(new BasicAttribute(User.ATTR_ENABLE,            String.valueOf(user.getEnabled())));
  +        attrs.put(new BasicAttribute(User.ATTR_HOME,              user.getVirtualDirectory().getRootDirectory()));
  +        attrs.put(new BasicAttribute(User.ATTR_WRITE_PERM,        String.valueOf(user.getVirtualDirectory().getWritePermission())));
  +        attrs.put(new BasicAttribute(User.ATTR_MAX_IDLE_TIME,     String.valueOf(user.getMaxIdleTime())));
  +        attrs.put(new BasicAttribute(User.ATTR_MAX_UPLOAD_RATE,   String.valueOf(user.getMaxUploadRate())));
  +        attrs.put(new BasicAttribute(User.ATTR_MAX_DOWNLOAD_RATE, String.valueOf(user.getMaxDownloadRate())));
   
           mAdminContext.bind(dn, null, attrs);
       }
  @@ -359,14 +348,14 @@
               if (user.getPassword().equals("")) {
                   user.setPassword(" ");
               }
  -            mods.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(PASSWORD,
user.getPassword())));
  +            mods.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(User.ATTR_PASSWORD,
user.getPassword())));
           }
  -        mods.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(ENABLE,
String.valueOf(user.getEnabled()))));
  -        mods.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(ROOT_DIR,
user.getVirtualDirectory().getRootDirectory())));
  -        mods.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(WRITE_PERM,
String.valueOf(user.getVirtualDirectory().getWritePermission()))));
  -        mods.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(IDLE_TIME,
String.valueOf(user.getMaxIdleTime()))));
  -        mods.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(UP_RATE,
String.valueOf(user.getMaxUploadRate()))));
  -        mods.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(DOWN_RATE,
String.valueOf(user.getMaxDownloadRate()))));
  +        mods.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(User.ATTR_ENABLE,
           String.valueOf(user.getEnabled()))));
  +        mods.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(User.ATTR_HOME,
             user.getVirtualDirectory().getRootDirectory())));
  +        mods.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(User.ATTR_WRITE_PERM,
       String.valueOf(user.getVirtualDirectory().getWritePermission()))));
  +        mods.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(User.ATTR_MAX_IDLE_TIME,
    String.valueOf(user.getMaxIdleTime()))));
  +        mods.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(User.ATTR_MAX_UPLOAD_RATE,
  String.valueOf(user.getMaxUploadRate()))));
  +        mods.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(User.ATTR_MAX_DOWNLOAD_RATE,
String.valueOf(user.getMaxDownloadRate()))));
   
   
           ModificationItem modArr[] = new ModificationItem[mods.size()];
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@incubator.apache.org
For additional commands, e-mail: cvs-help@incubator.apache.org


Mime
View raw message