Project

General

Profile

« Previous | Next » 

Revision 8433

Added by Jing Tao almost 11 years ago

Change the user id from the name to the uid.

View differences:

src/edu/ucsb/nceas/metacat/authentication/AuthFile.java
76 76
public class AuthFile implements AuthInterface {
77 77
    private static final String ORGANIZATION = "UNkown";
78 78
    private static final String NAME = "name";
79
    private static final String UID = "uid";
80
    private static final String DESCRIPTION = "description";
79 81
    private static final String PASSWORD = "password";
80 82
    private static final String SLASH = "/";
81 83
    private static final String AT = "@";
......
176 178
    @Override
177 179
    public boolean authenticate(String user, String password)
178 180
                    throws AuthenticationException {
179
        String passwordRecord = userpassword.getString(USERS+SLASH+USER+"["+AT+NAME+"='"+user+"']"+SLASH+PASSWORD);
181
        String passwordRecord = userpassword.getString(USERS+SLASH+USER+"["+AT+UID+"='"+user+"']"+SLASH+PASSWORD);
180 182
        if(passwordRecord != null) {
181 183
            try {
182 184
                passwordRecord = decrypt(passwordRecord);
......
197 199
     */
198 200
    public String[][] getUsers(String user, String password)
199 201
                    throws ConnectException {
200
        List<Object> users = userpassword.getList(USERS+SLASH+USER+SLASH+AT+NAME);
202
        List<Object> users = userpassword.getList(USERS+SLASH+USER+SLASH+AT+UID);
201 203
        if(users != null && users.size() > 0) {
202 204
            String[][] usersArray = new String[users.size()][1];
203 205
            for(int i=0; i<users.size(); i++) {
......
230 232
     */
231 233
    public String[] getUsers(String user, String password, String group)
232 234
                    throws ConnectException {
233
        List<Object> users = userpassword.getList(USERS+SLASH+USER+"["+GROUP+"='"+group+"']"+SLASH+AT+NAME);
235
        List<Object> users = userpassword.getList(USERS+SLASH+USER+"["+GROUP+"='"+group+"']"+SLASH+AT+UID);
234 236
        if(users != null && users.size() > 0) {
235 237
            String[] usersArray = new String[users.size()];
236 238
            for(int i=0; i<users.size(); i++) {
......
266 268
     */
267 269
    public String[][] getGroups(String user, String password, String foruser)
268 270
                    throws ConnectException {
269
        List<Object> groups = userpassword.getList(USERS+SLASH+USER+"["+AT+NAME+"='"+foruser+"']"+SLASH+GROUP);
271
        List<Object> groups = userpassword.getList(USERS+SLASH+USER+"["+AT+UID+"='"+foruser+"']"+SLASH+GROUP);
270 272
        if(groups != null && groups.size() > 0) {
271 273
            String[][] groupsArray = new String[groups.size()][1];
272 274
            for(int i=0; i<groups.size(); i++) {
......
388 390
        
389 391
        if(!userExists(userName)) {
390 392
            if(userpassword != null) {
391
              userpassword.addProperty(USERS+" "+USER+AT+NAME, userName);
392
              userpassword.addProperty(USERS+SLASH+USER+"["+AT+NAME+"='"+userName+"']"+" "+PASSWORD, password);
393
              userpassword.addProperty(USERS+" "+USER+AT+UID, userName);
394
              userpassword.addProperty(USERS+SLASH+USER+"["+AT+UID+"='"+userName+"']"+" "+PASSWORD, password);
393 395
              if(groups != null) {
394 396
                  for(int i=0; i<groups.length; i++) {
395 397
                      String group = groups[i];
396 398
                      if(group != null && !group.trim().equals("")) {
397 399
                          if(groupExists(group)) {
398
                              userpassword.addProperty(USERS+SLASH+USER+"["+AT+NAME+"='"+userName+"']"+" "+GROUP, group);
400
                              userpassword.addProperty(USERS+SLASH+USER+"["+AT+UID+"='"+userName+"']"+" "+GROUP, group);
399 401
                          }
400 402
                      }
401 403
                  }
......
462 464
        if(!groupExists(group)) {
463 465
            throw new AuthenticationException("AuthFile.addUserToGroup - the group "+group+ " doesn't exist.");
464 466
        }
465
        List<Object> existingGroups = userpassword.getList(USERS+SLASH+USER+"["+AT+NAME+"='"+userName+"']"+SLASH+GROUP);
467
        List<Object> existingGroups = userpassword.getList(USERS+SLASH+USER+"["+AT+UID+"='"+userName+"']"+SLASH+GROUP);
466 468
        if(existingGroups.contains(group)) {
467 469
            throw new AuthenticationException("AuthFile.addUserToGroup - the user "+userName+ " already is the memember of the group "+group);
468 470
        }
469
        userpassword.addProperty(USERS+SLASH+USER+"["+AT+NAME+"='"+userName+"']"+" "+GROUP, group);
471
        userpassword.addProperty(USERS+SLASH+USER+"["+AT+UID+"='"+userName+"']"+" "+GROUP, group);
470 472
    }
471 473
    
472 474
    /**
......
481 483
        if(!groupExists(group)) {
482 484
            throw new AuthenticationException("AuthFile.removeUserFromGroup - the group "+group+ " doesn't exist.");
483 485
        }
484
        String key = USERS+SLASH+USER+"["+AT+NAME+"='"+userName+"']"+SLASH+GROUP;
486
        String key = USERS+SLASH+USER+"["+AT+UID+"='"+userName+"']"+SLASH+GROUP;
485 487
        List<Object> existingGroups = userpassword.getList(key);
486 488
        if(!existingGroups.contains(group)) {
487 489
            throw new AuthenticationException("AuthFile.removeUserFromGroup - the user "+userName+ " isn't the memember of the group "+group);
......
505 507
        } catch (Exception e) {
506 508
            throw new AuthenticationException("AuthFile.changepassword - can't encrype the new password for the user "+userName+" since "+e.getMessage());
507 509
        }
508
        userpassword.setProperty(USERS+SLASH+USER+"["+AT+NAME+"='"+userName+"']"+SLASH+PASSWORD, encryped);
510
        userpassword.setProperty(USERS+SLASH+USER+"["+AT+UID+"='"+userName+"']"+SLASH+PASSWORD, encryped);
509 511
    }
510 512
    
511 513
    /**
......
517 519
        if(userName == null || userName.trim().equals("")) {
518 520
            throw new AuthenticationException("AuthFile.userExist - can't judge if a user exists when its name is null or blank.");
519 521
        }
520
        List<Object> users = userpassword.getList(USERS+SLASH+USER+SLASH+AT+NAME);
522
        List<Object> users = userpassword.getList(USERS+SLASH+USER+SLASH+AT+UID);
521 523
        if(users != null && users.contains(userName)) {
522 524
            return true;
523 525
        } else {

Also available in: Unified diff