Project

General

Profile

« Previous | Next » 

Revision 8469

Added by Jing Tao almost 11 years ago

Fixed a bug that the method addUser didn't set password.

View differences:

src/edu/ucsb/nceas/metacat/authentication/AuthFile.java
383 383
       User user = new User();
384 384
       user.setDN(dn);
385 385
       user.setGroups(groups);
386
       user.setPlainPass(plainPass);
387
       user.setHashedPass(hashedPass);
386 388
       user.setEmail(email);
387 389
       user.setSurName(surName);
388 390
       user.setGivenName(givenName);
......
666 668
         */
667 669
        public void addToGroup(String group) throws AuthenticationException {
668 670
            if(group == null || group.trim().equals("")) {
669
                throw new IllegalArgumentException("AuthFile.User.addGroup - the group can't be null or blank");
671
                throw new IllegalArgumentException("AuthFile.User.addToGroup - the group can't be null or blank");
670 672
            }
671 673
            if(!userExists(dn)) {
672
                throw new AuthenticationException("AuthFile.addUserToGroup - the user "+dn+ " doesn't exist.");
674
                throw new AuthenticationException("AuthFile.User.addUserToGroup - the user "+dn+ " doesn't exist.");
673 675
            }
674 676
            if(!groupExists(group)) {
675
                throw new AuthenticationException("AuthFile.addUserToGroup - the group "+group+ " doesn't exist.");
677
                throw new AuthenticationException("AuthFile.User.addUserToGroup - the group "+group+ " doesn't exist.");
676 678
            }
677 679
            List<Object> existingGroups = userpassword.getList(USERS+SLASH+USER+"["+AT+DN+"='"+dn+"']"+SLASH+GROUP);
678 680
            if(existingGroups != null && existingGroups.contains(group)) {
679
                throw new AuthenticationException("AuthFile.addUserToGroup - the user "+dn+ " already is the memember of the group "+group);
681
                throw new AuthenticationException("AuthFile.User.addUserToGroup - the user "+dn+ " already is the memember of the group "+group);
680 682
            }
681 683
            userpassword.addProperty(USERS+SLASH+USER+"["+AT+DN+"='"+dn+"']"+" "+GROUP, group);
682 684
            //add information to the memory
......
710 712
         */
711 713
        public void removeFromGroup(String group) throws AuthenticationException {
712 714
            if(!userExists(dn)) {
713
                throw new AuthenticationException("AuthFile.removeUserFromGroup - the user "+dn+ " doesn't exist.");
715
                throw new AuthenticationException("AuthFile.User.removeUserFromGroup - the user "+dn+ " doesn't exist.");
714 716
            }
715 717
            if(!groupExists(group)) {
716
                throw new AuthenticationException("AuthFile.removeUserFromGroup - the group "+group+ " doesn't exist.");
718
                throw new AuthenticationException("AuthFile.User.removeUserFromGroup - the group "+group+ " doesn't exist.");
717 719
            }
718 720
            String key = USERS+SLASH+USER+"["+AT+DN+"='"+dn+"']"+SLASH+GROUP;
719 721
            List<Object> existingGroups = userpassword.getList(key);
720 722
            if(!existingGroups.contains(group)) {
721
                throw new AuthenticationException("AuthFile.removeUserFromGroup - the user "+dn+ " isn't the memember of the group "+group);
723
                throw new AuthenticationException("AuthFile.User.removeUserFromGroup - the user "+dn+ " isn't the memember of the group "+group);
722 724
            } else {
723 725
                userpassword.clearProperty(key+"[.='"+group+"']");
724 726
            }
......
753 755
                throw new AuthenticationException("AuthFile.User.modifyHashPass - can't change the password to the null or blank.");
754 756
            }
755 757
            if(!userExists(dn)) {
756
                throw new AuthenticationException("AuthFile.modifyHashPass - can't change the password for the user "+dn+" since it doesn't eixt.");
758
                throw new AuthenticationException("AuthFile.User.modifyHashPass - can't change the password for the user "+dn+" since it doesn't eixt.");
757 759
            }
758 760
            userpassword.setProperty(USERS+SLASH+USER+"["+AT+DN+"='"+dn+"']"+SLASH+PASSWORD, hashPass);
759 761
            setHashedPass(hashPass);
......
770 772
                throw new AuthenticationException("AuthFile.User.modifyPlainPass - can't change the password to the null or blank.");
771 773
            }
772 774
            if(!userExists(dn)) {
773
                throw new AuthenticationException("AuthFile.modifyPlainPass - can't change the password for the user "+dn+" since it doesn't eixt.");
775
                throw new AuthenticationException("AuthFile.User.modifyPlainPass - can't change the password for the user "+dn+" since it doesn't eixt.");
774 776
            }
775 777
            String hashPassword = null;
776 778
            try {
777 779
                hashPassword = encrypt(plainPass);
778 780
            } catch (Exception e) {
779
                throw new AuthenticationException("AuthFile.addUser - can't encript the password since "+e.getMessage());
781
                throw new AuthenticationException("AuthFile.User.modifyPlainPass - can't encript the password since "+e.getMessage());
780 782
            }
781 783
            userpassword.setProperty(USERS+SLASH+USER+"["+AT+DN+"='"+dn+"']"+SLASH+PASSWORD, hashPassword);
782 784
            setPlainPass(plainPass);
......
787 789
         */
788 790
        public void serialize() throws AuthenticationException {
789 791
            if(dn == null || dn.trim().equals("")) {
790
                throw new AuthenticationException("AuthFile.addUser - can't add a user whose name is null or blank.");
792
                throw new AuthenticationException("AuthFile.User.serialize - can't add a user whose name is null or blank.");
791 793
            }
792 794
            if(hashedPass == null || hashedPass.trim().equals("")) {
793 795
                if(plainPass == null || plainPass.trim().equals("")) {
794
                    throw new AuthenticationException("AuthFile.addUser - can't add a user whose password is null or blank.");
796
                    throw new AuthenticationException("AuthFile.User.serialize - can't add a user whose password is null or blank.");
795 797
                } else {
796 798
                    try {
797 799
                        hashedPass = encrypt(plainPass);
798 800
                    } catch (Exception e) {
799
                        throw new AuthenticationException("AuthFile.addUser - can't encript the password since "+e.getMessage());
801
                        throw new AuthenticationException("AuthFile.User.serialize - can't encript the password since "+e.getMessage());
800 802
                    }
801 803
                }
802 804
            }
......
831 833
                  //userpassword.reload();
832 834
                 }
833 835
            } else {
834
                throw new AuthenticationException("AuthFile.addUser - can't add the user "+dn+" since it already exists.");
836
                throw new AuthenticationException("AuthFile.User.serialize - can't add the user "+dn+" since it already exists.");
835 837
            }
836 838
        }
837 839
    }

Also available in: Unified diff