Ignore:
Timestamp:
2018-08-30T14:27:06+12:00 (6 years ago)
Author:
kjdon
Message:

replaced hard coded text strings with static Strings. when doing PerformRegister and changing result to Register (on error), we might need to add in recaptcha element. have a recaptchaOplist which specifies which operations require the recaptcha to be added (list comes from siteConfig)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/Authentication.java

    r32369 r32390  
    109109        opList.add(PERFORM_ADD);
    110110        opList.add(PERFORM_EDIT);
     111        opList.add(ADD_USER);
    111112        opList.add(EDIT_USER);
    112113        opList.add(PERFORM_DELETE_USER);
     
    128129        opList.add(PERFORM_ACCOUNT_EDIT);
    129130        opList.add(PERFORM_RESET_PASSWORD);
     131        opList.add(PERFORM_CHANGE_PASSWORD);
     132        opList.add(PERFORM_RETRIEVE_PASSWORD);
    130133        opList.addAll(_adminOpList);
    131134        _userOpList = opList;
     
    145148    protected static boolean _derbyWrapperDoneForcedShutdown = false;
    146149
     150  // some XML strings
     151  protected static final String RECAPTCHA_ELEM = "recaptcha";
     152  protected static final String SITE_KEY = "site_key";
     153   protected static final String SECRET_KEY = "secret_key";
     154  protected static final String OPERATIONS = "operations";
     155protected static final String OPERATION = "operation";
     156 
     157  protected static final String USERNAME = "username";
     158  protected static final String PREV_USERNAME = "prevUsername";
     159  protected static final String NEW_USERNAME = "newUsername";
     160  protected static final String PASSWORD = "password";
     161  protected static final String OLD_PASSWORD = "oldPassword";
     162  protected static final String NEW_PASSWORD = "newPassword";
     163
     164  protected static final String GROUPS = "groups";
     165  protected static final String ENABLED = "enabled";
     166  protected static final String COMMENT = "comment";
     167  protected static final String STATUS = "status";
     168  protected static final String EMAIL = "email";
     169  protected static final String NEW_EMAIL = "newEmail";
     170  protected static final String ACCOUNT_STATUS = "accountstatus";
     171  protected static final String EDIT_ENABLED = "editEnabled";
     172 
    147173    protected String _recaptchaSiteKey = null;
    148174    protected String _recaptchaSecretKey = null;
    149 
     175  protected static ArrayList<String> _recaptchaOpList = null;
    150176    /** constructor */
    151177    public Authentication()
     
    204230        DerbyWrapper.createDatabaseIfNeeded();
    205231
    206         NodeList recaptchaElems = info.getElementsByTagName("recaptcha");
     232        NodeList recaptchaElems = info.getElementsByTagName(RECAPTCHA_ELEM);
    207233        for (int i = 0; i < recaptchaElems.getLength(); i++)
    208234        {
    209235            Element currentElem = (Element) recaptchaElems.item(i);
    210             if (currentElem.getAttribute(GSXML.NAME_ATT) != null && currentElem.getAttribute(GSXML.NAME_ATT).equals("site_key"))
    211             {
    212                 if (currentElem.getAttribute(GSXML.VALUE_ATT) != null)
     236            if (currentElem.getAttribute(GSXML.NAME_ATT).equals(SITE_KEY))
     237            {
     238              if (!currentElem.getAttribute(GSXML.VALUE_ATT).equals(""))
    213239                {
    214240                    _recaptchaSiteKey = currentElem.getAttribute(GSXML.VALUE_ATT);
    215241                }
    216242            }
    217             else if (currentElem.getAttribute(GSXML.NAME_ATT) != null && currentElem.getAttribute(GSXML.NAME_ATT).equals("secret_key"))
    218             {
    219                 if (currentElem.getAttribute(GSXML.VALUE_ATT) != null)
     243            else if (currentElem.getAttribute(GSXML.NAME_ATT).equals(SECRET_KEY))
     244            {
     245              if (!currentElem.getAttribute(GSXML.VALUE_ATT).equals(""))
    220246                {
    221247                    _recaptchaSecretKey = currentElem.getAttribute(GSXML.VALUE_ATT);
    222248                }
    223249            }
    224         }
    225 
     250            else if (currentElem.getAttribute(GSXML.NAME_ATT).equals(OPERATIONS))
     251              {
     252                _recaptchaOpList = new ArrayList<String>();
     253                String value = currentElem.getAttribute(GSXML.VALUE_ATT);
     254                String[] ops = value.split(",");
     255                for (int j=0; j<ops.length; j++) {
     256                  if (!ops[j].equals("")) {
     257                _recaptchaOpList.add(ops[j]); /// value checking?
     258                  }
     259                }
     260              }
     261           
     262        }
     263        // check recaptcha
     264        if (_recaptchaSecretKey == null || _recaptchaSecretKey.length() == 0 || _recaptchaSiteKey == null || _recaptchaSiteKey.length() == 0) {
     265          _recaptchaOpList = null;
     266        }
     267         
    226268        return true;
    227269    }
     
    301343        HashMap<String, Serializable> params = GSXML.extractParams(paramList, true);
    302344
    303         String username = (String) params.get("username");
    304         String editMode = (String) params.get("enabled");
     345        String username = (String) params.get(USERNAME);
     346        String editMode = (String) params.get(ENABLED);
    305347
    306348        if (!editMode.toLowerCase().equals("true") && !editMode.toLowerCase().equals("false"))
     
    332374       
    333375        Element system = (Element) GSXML.getChildByTagName(request, GSXML.REQUEST_TYPE_SYSTEM);     
    334         String username = system.hasAttribute("username") ? system.getAttribute("username") : "";
    335         String password = system.hasAttribute("password") ? system.getAttribute("password") : "";
     376        String username = system.hasAttribute(USERNAME) ? system.getAttribute(USERNAME) : "";
     377        String password = system.hasAttribute(PASSWORD) ? system.getAttribute(PASSWORD) : "";
    336378       
    337379       
     
    345387        }       
    346388        else {     
    347             String storedPassword = retrieveDataForUser(username, "password");
     389            String storedPassword = retrieveDataForUser(username, PASSWORD);
    348390            if(storedPassword != null && (password.equals(storedPassword) || hashPassword(password).equals(storedPassword))) {
    349391               
    350392                // gliserver.pl used to return the groups when authentication succeeded
    351                 String groups = retrieveDataForUser(username, "groups"); //comma-separated list
     393                String groups = retrieveDataForUser(username, GROUPS); //comma-separated list
    352394               
    353395                if(collection.equals("")) {
     
    407449        HashMap<String, Serializable> params = GSXML.extractParams(paramList, true);
    408450
    409         String username = (String) params.get("username");
     451        String username = (String) params.get(USERNAME);
    410452
    411453        if (username == null)
     
    432474        result.appendChild(userInfoList);
    433475
    434         Element usernameField = GSXML.createParameter(result_doc, "username", userInfo.username);
    435         Element passwordField = GSXML.createParameter(result_doc, "password", userInfo.password);
    436         Element groupsField = GSXML.createParameter(result_doc, "groups", userInfo.groups);
    437         Element accountStatusField = GSXML.createParameter(result_doc, "accountstatus", userInfo.accountstatus);
    438         Element commentField = GSXML.createParameter(result_doc, "comment", userInfo.comment);
     476        Element usernameField = GSXML.createParameter(result_doc, USERNAME, userInfo.username);
     477        Element passwordField = GSXML.createParameter(result_doc, PASSWORD, userInfo.password);
     478        Element groupsField = GSXML.createParameter(result_doc, GROUPS, userInfo.groups);
     479        Element accountStatusField = GSXML.createParameter(result_doc, ACCOUNT_STATUS, userInfo.accountstatus);
     480        Element commentField = GSXML.createParameter(result_doc, COMMENT, userInfo.comment);
    439481
    440482        if (editEnabled != null)
    441483        {
    442             Element editEnabledElem = GSXML.createParameter(result_doc, "editEnabled", editEnabled);
     484            Element editEnabledElem = GSXML.createParameter(result_doc, EDIT_ENABLED, editEnabled);
    443485            userInfoList.appendChild(editEnabledElem);
    444486        }
     
    479521        if (param_list == null)
    480522        {
    481             serviceNode.setAttribute("operation", LOGIN);
     523            serviceNode.setAttribute(OPERATION, LOGIN);
    482524            logger.error("Authentication request has no param list");
    483525            return result; // Return the empty result
     
    485527        HashMap<String, Serializable> paramMap = GSXML.extractParams(param_list, false);
    486528        String op = (String) paramMap.get("authpage");
    487         serviceNode.setAttribute("operation", op);
     529        serviceNode.setAttribute(OPERATION, op);
    488530
    489531        String username = null;
     
    496538            groups = userInformation.getAttribute(GSXML.GROUPS_ATT);
    497539        }
    498 
     540        logger.error("username="+username+", groups = "+groups);
    499541        if ((userInformation == null || username == null) && _userOpList.contains(op))
    500542        {
    501543          // its an operation that requires the user to be logged on - direct them to login page
    502             serviceNode.setAttribute("operation", LOGIN);
     544            serviceNode.setAttribute(OPERATION, LOGIN);
    503545            GSXML.addError(result, getErrorTextString(ERROR_NOT_LOGGED_IN, lang));
    504546            return result;
     
    508550        {
    509551          // actually, the user needs to be an admin user and they are not
    510             serviceNode.setAttribute("operation", LOGIN);
     552            serviceNode.setAttribute(OPERATION, LOGIN);
    511553            GSXML.addError(result, getErrorTextString(ERROR_ADMIN_NOT_LOGGED_IN, lang));
    512554            return result;
    513555        }
    514556
     557        if (_recaptchaOpList != null && _recaptchaOpList.contains(op)) {
     558          serviceNode.setAttribute("recaptcha_key", _recaptchaSiteKey);
     559        }
     560       
    515561        if (op.equals(LIST_USERS))
    516562        {
     
    518564          if (error != NO_ERROR)
    519565            {
    520               serviceNode.setAttribute("operation", BLANK);
     566              serviceNode.setAttribute(OPERATION, BLANK);
    521567              GSXML.addError(result, getErrorTextString(error, lang));
    522568            }
     
    527573        if (op.equals(PERFORM_ADD))
    528574        {
    529             String newUsername = (String) paramMap.get("username");
    530             String newPassword = (String) paramMap.get("password");
    531             String newGroups = (String) paramMap.get("groups");
    532             String newStatus = (String) paramMap.get("status");
    533             String newComment = (String) paramMap.get("comment");
    534             String newEmail = (String) paramMap.get("email");
     575            String newUsername = (String) paramMap.get(USERNAME);
     576            String newPassword = (String) paramMap.get(PASSWORD);
     577            String newGroups = (String) paramMap.get(GROUPS);
     578            String newStatus = (String) paramMap.get(STATUS);
     579            String newComment = (String) paramMap.get(COMMENT);
     580            String newEmail = (String) paramMap.get(EMAIL);
    535581
    536582            //Check the given user name
     
    538584            if ((error = checkUsername(newUsername)) != NO_ERROR)
    539585            {
     586              serviceNode.setAttribute(OPERATION, ADD_USER);
    540587                GSXML.addError(result, getErrorTextString(error, lang));
    541588                return result;
     
    545592            if ((error = checkPassword(newPassword)) != NO_ERROR)
    546593            {
     594              serviceNode.setAttribute(OPERATION, ADD_USER);
    547595                GSXML.addError(result, getErrorTextString(error, lang));
    548596                return result;
     
    554602            if (error != NO_ERROR)
    555603            {
    556                 serviceNode.setAttribute("operation", ADD_USER);
     604                serviceNode.setAttribute(OPERATION, ADD_USER);
    557605                GSXML.addError(result, getErrorTextString(error, lang));
    558606            }
     
    560608            {
    561609                addUserInformationToNode(null, serviceNode);
    562                 serviceNode.setAttribute("operation", LIST_USERS);
     610                serviceNode.setAttribute(OPERATION, LIST_USERS);
    563611            }
    564612            return result;
    565613        }
     614
     615        if (op.equals(REGISTER)) {
     616          // don't need any additional info
     617          return result;
     618        }
     619        if (op.equals(PERFORM_REGISTER))
     620        {
     621            String newUsername = (String) paramMap.get(USERNAME);
     622            String newPassword = (String) paramMap.get(PASSWORD);
     623            String newEmail = (String) paramMap.get(EMAIL);
     624
     625            //Check the given details
     626            int error;
     627            if ((error = checkUsername(newUsername)) == NO_ERROR) {
     628              if ((error = checkPassword(newPassword)) == NO_ERROR) {
     629                newPassword = hashPassword(newPassword);
     630                if (_recaptchaSiteKey != null && _recaptchaSecretKey != null) {
     631
     632                  String user_response = (String) paramMap.get("g-recaptcha-response");
     633                  if ((error= verifyRecaptcha(_recaptchaSecretKey, user_response)) == NO_ERROR) {
     634                error = addUser(newUsername, newPassword, "", "true", "", newEmail);
     635                  }
     636                }
     637              }
     638            }
     639           
     640            if (error != NO_ERROR)
     641            {
     642                serviceNode.setAttribute(OPERATION, REGISTER);
     643                if (_recaptchaOpList != null && _recaptchaOpList.contains(REGISTER)) {
     644                  serviceNode.setAttribute("recaptcha_key", _recaptchaSiteKey);
     645                }
     646                GSXML.addError(result, getErrorTextString(error, lang));
     647            }
     648            // otherwise everything hunky dory and we return result
     649            return result;
     650        }
    566651       
    567         if (op.equals(PERFORM_REGISTER))
    568         {
    569             String newUsername = (String) paramMap.get("username");
    570             String newPassword = (String) paramMap.get("password");
    571             String newEmail = (String) paramMap.get("email");
     652        if (op.equals(PERFORM_EDIT))
     653        {
     654            String previousUsername = (String) paramMap.get(PREV_USERNAME);
     655            String newUsername = (String) paramMap.get(NEW_USERNAME);
     656            String newPassword = (String) paramMap.get(PASSWORD);
     657            String newGroups = (String) paramMap.get(GROUPS);
     658            String newStatus = (String) paramMap.get(STATUS);
     659            String newComment = (String) paramMap.get(COMMENT);
     660            String newEmail = (String) paramMap.get(NEW_EMAIL);
    572661
    573662            //Check the given user name
     
    579668            }
    580669
    581             //Check the given password
    582             if ((error = checkPassword(newPassword)) != NO_ERROR)
    583             {
     670            if (newPassword == null)
     671            {
     672                newPassword = retrieveDataForUser(previousUsername, PASSWORD);
     673            }
     674            else
     675            {
     676                //Check the given password
     677                if ((error = checkPassword(newPassword)) != NO_ERROR)
     678                {
     679                    GSXML.addError(result, getErrorTextString(error, lang));
     680                    return result;
     681                }
     682
     683                newPassword = hashPassword(newPassword);
     684            }
     685
     686            error = removeUser(previousUsername);
     687            if (error != NO_ERROR)
     688            {
     689                if (error == ERROR_USERNAME_NOT_SPECIFIED)
     690                {
     691                    addUserInformationToNode(null, serviceNode);
     692                    serviceNode.setAttribute(OPERATION, LIST_USERS);
     693                }
     694                else
     695                {
     696                    serviceNode.setAttribute(OPERATION, EDIT_USER);
     697                    GSXML.addError(result, getErrorTextString(error, lang));
     698                }
     699                return result;
     700            }
     701
     702            error = addUser(newUsername, newPassword, newGroups, newStatus, newComment, newEmail);
     703            if (error != NO_ERROR)
     704            {
     705                serviceNode.setAttribute(OPERATION, EDIT_USER);
    584706                GSXML.addError(result, getErrorTextString(error, lang));
     707            }
     708            else
     709            {
     710                addUserInformationToNode(null, serviceNode);
     711                serviceNode.setAttribute(OPERATION, LIST_USERS);
     712            }
     713            return result;
     714        }
     715        // this operation is done by a user when editing their own details. Should not return userNode info.
     716        if (op.equals(PERFORM_ACCOUNT_EDIT))
     717        {
     718            String previousUsername = (String) paramMap.get(PREV_USERNAME);
     719            String newUsername = (String) paramMap.get(NEW_USERNAME);
     720            String oldPassword = (String) paramMap.get(OLD_PASSWORD);
     721            String newPassword = (String) paramMap.get(NEW_PASSWORD);
     722            String newEmail = (String) paramMap.get(NEW_EMAIL);
     723
     724            //Make sure the user name does not already exist
     725            if (!previousUsername.equals(newUsername) && checkUserExists(newUsername))
     726            {
     727                addUserInformationToNode(previousUsername, serviceNode);
     728                serviceNode.setAttribute(OPERATION, ACCOUNT_SETTINGS);
     729                GSXML.addError(result, getErrorTextString(ERROR_USER_ALREADY_EXISTS, lang));
    585730                return result;
    586731            }
    587732
    588             newPassword = hashPassword(newPassword);
    589 
    590             // check the recaptcha
    591             if (_recaptchaSiteKey != null && _recaptchaSecretKey.length() > 0) {
    592 
    593               String user_response = (String) paramMap.get("g-recaptcha-response");
    594               int recaptcha_error = verifyRecaptcha(_recaptchaSecretKey, user_response);
    595               if (recaptcha_error != NO_ERROR) {
    596                 serviceNode.setAttribute("operation", REGISTER);
    597                 GSXML.addError(result, getErrorTextString(recaptcha_error, lang));
    598                 return result;
    599               }
    600             }
    601 
    602             error = addUser(newUsername, newPassword, "", "true", "", newEmail);
    603             if (error != NO_ERROR)
    604             {
    605                 serviceNode.setAttribute("operation", REGISTER);
    606                 GSXML.addError(result, getErrorTextString(error, lang));
    607             }
    608             return result;
    609         }
    610        
    611         else if (op.equals(PERFORM_EDIT))
    612         {
    613             String previousUsername = (String) paramMap.get("prevUsername");
    614             String newUsername = (String) paramMap.get("newUsername");
    615             String newPassword = (String) paramMap.get("password");
    616             String newGroups = (String) paramMap.get("groups");
    617             String newStatus = (String) paramMap.get("status");
    618             String newComment = (String) paramMap.get("comment");
    619             String newEmail = (String) paramMap.get("newEmail");
     733            String prevPassword = retrieveDataForUser(previousUsername, PASSWORD);
     734
     735            if (newPassword != null)
     736            {
     737                oldPassword = hashPassword(oldPassword);
     738
     739                if (oldPassword == null || !oldPassword.equals(prevPassword))
     740                {
     741                    addUserInformationToNode(previousUsername, serviceNode);
     742                    serviceNode.setAttribute(OPERATION, ACCOUNT_SETTINGS);
     743                    GSXML.addError(result, getErrorTextString(ERROR_INCORRECT_PASSWORD, lang), "INCORRECT_PASSWORD");
     744                    return result;
     745                }
     746
     747                //Check the given password
     748                int error;
     749                if ((error = checkPassword(newPassword)) != NO_ERROR)
     750                {
     751                  addUserInformationToNode(previousUsername, serviceNode);
     752                  serviceNode.setAttribute(OPERATION, ACCOUNT_SETTINGS);
     753                    GSXML.addError(result, getErrorTextString(error, lang));
     754                    return result;
     755                }
     756
     757                newPassword = hashPassword(newPassword);
     758            }
     759            else
     760            {
     761                newPassword = prevPassword;
     762            }
    620763
    621764            //Check the given user name
     
    623766            if ((error = checkUsername(newUsername)) != NO_ERROR)
    624767            {
     768              addUserInformationToNode(previousUsername, serviceNode);
     769                  serviceNode.setAttribute(OPERATION, ACCOUNT_SETTINGS);
    625770                GSXML.addError(result, getErrorTextString(error, lang));
    626771                return result;
    627772            }
    628773
    629             if (newPassword == null)
    630             {
    631                 newPassword = retrieveDataForUser(previousUsername, "password");
    632             }
    633             else
    634             {
    635                 //Check the given password
    636                 if ((error = checkPassword(newPassword)) != NO_ERROR)
    637                 {
    638                     GSXML.addError(result, getErrorTextString(error, lang));
    639                     return result;
    640                 }
    641 
    642                 newPassword = hashPassword(newPassword);
    643             }
     774            String prevGroups = retrieveDataForUser(previousUsername, GROUPS);
     775            String prevStatus = retrieveDataForUser(previousUsername, STATUS);
     776            String prevComment = retrieveDataForUser(previousUsername, COMMENT);
    644777
    645778            error = removeUser(previousUsername);
    646779            if (error != NO_ERROR)
    647780            {
    648                 if (error == ERROR_USERNAME_NOT_SPECIFIED)
    649                 {
    650                     addUserInformationToNode(null, serviceNode);
    651                     serviceNode.setAttribute("operation", LIST_USERS);
    652                 }
    653                 else
    654                 {
    655                     serviceNode.setAttribute("operation", EDIT_USER);
    656                     GSXML.addError(result, getErrorTextString(error, lang));
    657                 }
    658                 return result;
    659             }
    660 
    661             error = addUser(newUsername, newPassword, newGroups, newStatus, newComment, newEmail);
    662             if (error != NO_ERROR)
    663             {
    664                 serviceNode.setAttribute("operation", EDIT_USER);
    665                 GSXML.addError(result, getErrorTextString(error, lang));
    666             }
    667             else
    668             {
    669                 addUserInformationToNode(null, serviceNode);
    670                 serviceNode.setAttribute("operation", LIST_USERS);
    671             }
    672         }
    673         // this operation is done by a user when editing their own details. Should not return userNode info.
    674         else if (op.equals(PERFORM_ACCOUNT_EDIT))
    675         {
    676             String previousUsername = (String) paramMap.get("prevUsername");
    677             String newUsername = (String) paramMap.get("newUsername");
    678             String oldPassword = (String) paramMap.get("oldPassword");
    679             String newPassword = (String) paramMap.get("newPassword");
    680             String newEmail = (String) paramMap.get("newEmail");
    681 
    682             //Make sure the user name does not already exist
    683             if (!previousUsername.equals(newUsername) && checkUserExists(newUsername))
    684             {
    685                 addUserInformationToNode(previousUsername, serviceNode);
    686                 serviceNode.setAttribute("operation", ACCOUNT_SETTINGS);
    687                 GSXML.addError(result, getErrorTextString(ERROR_USER_ALREADY_EXISTS, lang));
    688                 return result;
    689             }
    690 
    691             String prevPassword = retrieveDataForUser(previousUsername, "password");
    692 
    693             if (newPassword != null)
    694             {
    695                 oldPassword = hashPassword(oldPassword);
    696 
    697                 if (oldPassword == null || !oldPassword.equals(prevPassword))
    698                 {
    699                     addUserInformationToNode(previousUsername, serviceNode);
    700                     serviceNode.setAttribute("operation", ACCOUNT_SETTINGS);
    701                     GSXML.addError(result, getErrorTextString(ERROR_INCORRECT_PASSWORD, lang), "INCORRECT_PASSWORD");
    702                     return result;
    703                 }
    704 
    705                 //Check the given password
    706                 int error;
    707                 if ((error = checkPassword(newPassword)) != NO_ERROR)
    708                 {
    709                   addUserInformationToNode(previousUsername, serviceNode);
    710                   serviceNode.setAttribute("operation", ACCOUNT_SETTINGS);
    711                     GSXML.addError(result, getErrorTextString(error, lang));
    712                     return result;
    713                 }
    714 
    715                 newPassword = hashPassword(newPassword);
    716             }
    717             else
    718             {
    719                 newPassword = prevPassword;
    720             }
    721 
    722             //Check the given user name
    723             int error;
    724             if ((error = checkUsername(newUsername)) != NO_ERROR)
    725             {
    726781              addUserInformationToNode(previousUsername, serviceNode);
    727                   serviceNode.setAttribute("operation", ACCOUNT_SETTINGS);
    728                 GSXML.addError(result, getErrorTextString(error, lang));
    729                 return result;
    730             }
    731 
    732             String prevGroups = retrieveDataForUser(previousUsername, "groups");
    733             String prevStatus = retrieveDataForUser(previousUsername, "status");
    734             String prevComment = retrieveDataForUser(previousUsername, "comment");
    735 
    736             error = removeUser(previousUsername);
    737             if (error != NO_ERROR)
    738             {
    739               addUserInformationToNode(previousUsername, serviceNode);
    740               serviceNode.setAttribute("operation", ACCOUNT_SETTINGS);
     782              serviceNode.setAttribute(OPERATION, ACCOUNT_SETTINGS);
    741783              GSXML.addError(result, getErrorTextString(error, lang));
    742784              return result;
     
    746788            if (error != NO_ERROR)
    747789            {
    748               serviceNode.setAttribute("operation", ACCOUNT_SETTINGS);
     790              serviceNode.setAttribute(OPERATION, ACCOUNT_SETTINGS);
    749791                GSXML.addError(result, getErrorTextString(error, lang));
    750792            }
    751793
    752794            addUserInformationToNode(newUsername, serviceNode);
    753             serviceNode.setAttribute("operation", ACCOUNT_SETTINGS);
     795            serviceNode.setAttribute(OPERATION, ACCOUNT_SETTINGS);
    754796            GSXML.addError(result, getTextString("auth.success.account_settings", lang));
    755            
    756         }
    757         else if (op.equals(PERFORM_RETRIEVE_PASSWORD))
    758         {
    759 
    760         }
    761         else if (op.equals(PERFORM_CHANGE_PASSWORD))
    762         {
    763             serviceNode.setAttribute("operation", PERFORM_CHANGE_PASSWORD);
    764             String user_name = (String) paramMap.get("username");
    765             String oldPassword = (String) paramMap.get("oldPassword");
    766             String newPassword = (String) paramMap.get("newPassword");
     797            return result;
     798        }
     799        if (op.equals(PERFORM_RETRIEVE_PASSWORD))
     800        {
     801          return result;
     802        }
     803        if (op.equals(PERFORM_CHANGE_PASSWORD))
     804        {
     805            serviceNode.setAttribute(OPERATION, PERFORM_CHANGE_PASSWORD);
     806            String user_name = (String) paramMap.get(USERNAME);
     807            String oldPassword = (String) paramMap.get(OLD_PASSWORD);
     808            String newPassword = (String) paramMap.get(NEW_PASSWORD);
    767809            if (user_name == null || oldPassword == null || newPassword == null)
    768810            {
     
    771813            }
    772814
    773             String prevPassword = retrieveDataForUser(user_name, "password");
     815            String prevPassword = retrieveDataForUser(user_name, PASSWORD);
    774816            if (!hashPassword(oldPassword).equals(prevPassword))
    775817            {
     
    788830
    789831            DerbyWrapper derbyWrapper = openDatabase();
    790             String chpa_groups = retrieveDataForUser(user_name, "groups");
     832            String chpa_groups = retrieveDataForUser(user_name, GROUPS);
    791833            String chpa_comment = "password_changed_by_user";
    792834            String info = derbyWrapper.modifyUserInfo(user_name, hashPassword(newPassword), chpa_groups, null, chpa_comment, null);
     
    797839                return result;
    798840            }
    799         }
    800         else if (op.equals(EDIT_USER))
    801         {
    802             String editUsername = (String) paramMap.get("username");
     841            return result;
     842        }
     843        if (op.equals(EDIT_USER))
     844        {
     845            String editUsername = (String) paramMap.get(USERNAME);
    803846            int error = addUserInformationToNode(editUsername, serviceNode);
    804847            if (error != NO_ERROR)
     
    806849              GSXML.addError(result, getErrorTextString(error, lang));
    807850            }
    808         }
    809         else if (op.equals(ACCOUNT_SETTINGS))
    810         {
    811             String editUsername = (String) paramMap.get("username");
     851            return result;
     852        }
     853        if (op.equals(ACCOUNT_SETTINGS))
     854        {
     855            String editUsername = (String) paramMap.get(USERNAME);
    812856
    813857            if (editUsername == null)
    814858            {
    815                 serviceNode.setAttribute("operation", "");
     859                serviceNode.setAttribute(OPERATION, "");
    816860                GSXML.addError(result, getErrorTextString(ERROR_USERNAME_NOT_SPECIFIED, lang));
    817861                return result;
     
    820864            if (!editUsername.equals(username))
    821865            {
    822                 serviceNode.setAttribute("operation", LOGIN);
     866                serviceNode.setAttribute(OPERATION, LOGIN);
    823867                GSXML.addError(result, getErrorTextString(ERROR_NOT_AUTHORISED, lang));
    824868                return result;
     
    829873              GSXML.addError(result, getErrorTextString(error, lang));
    830874            }
    831         }
    832         else if (op.equals(PERFORM_RESET_PASSWORD))
    833         {
    834             String passwordResetUser = (String) paramMap.get("username");
     875            return result;
     876        }
     877        if (op.equals(PERFORM_RESET_PASSWORD))
     878        {
     879            String passwordResetUser = (String) paramMap.get(USERNAME);
    835880
    836881            String newPassword = UUID.randomUUID().toString();
    837882            newPassword = newPassword.substring(0, newPassword.indexOf("-"));
    838883
    839             String email = retrieveDataForUser(passwordResetUser, "email");
     884            String email = retrieveDataForUser(passwordResetUser, EMAIL);
    840885            String from = "[email protected]";
    841886            String host = request.getAttribute("remoteAddress");
    842887
    843888            //TODO: FINISH THIS
    844         }
    845         else if (op.equals(REGISTER))
    846         {
    847         }
    848         else if (op.equals(PERFORM_DELETE_USER))
    849         {
    850             String usernameToDelete = (String) paramMap.get("username");
     889            return result;
     890        }
     891        if (op.equals(PERFORM_DELETE_USER))
     892        {
     893            String usernameToDelete = (String) paramMap.get(USERNAME);
    851894            int error = removeUser(usernameToDelete);
    852895            if (error != NO_ERROR)
     
    855898            }
    856899            addUserInformationToNode(null, serviceNode);
    857             serviceNode.setAttribute("operation", LIST_USERS);
    858         }
    859 
    860         return result;
     900            serviceNode.setAttribute(OPERATION, LIST_USERS);
     901            return result;
     902        }
     903
     904        return result; // or should we return null, as we haven't recognised the operation??
    861905    }
    862906
     
    11141158            for (int i = 0; i < result.getSize(); i++)
    11151159            {
    1116                 if (dataType.equals("password"))
     1160                if (dataType.equals(PASSWORD))
    11171161                {
    11181162                    data = ((UserTermInfo) userInfo.get(i)).password;
    11191163                    break;
    11201164                }
    1121                 else if (dataType.equals("groups"))
     1165                else if (dataType.equals(GROUPS))
    11221166                {
    11231167                    data = ((UserTermInfo) userInfo.get(i)).groups;
    11241168                    break;
    11251169                }
    1126                 else if (dataType.equals("status"))
     1170                else if (dataType.equals(STATUS))
    11271171                {
    11281172                    data = ((UserTermInfo) userInfo.get(i)).accountstatus;
    11291173                    break;
    11301174                }
    1131                 else if (dataType.equals("comment"))
     1175                else if (dataType.equals(COMMENT))
    11321176                {
    11331177                    data = ((UserTermInfo) userInfo.get(i)).comment;
    11341178                    break;
    11351179                }
    1136                 else if (dataType.equals("email"))
     1180                else if (dataType.equals(EMAIL))
    11371181                {
    11381182                    data = ((UserTermInfo) userInfo.get(i)).email;
     
    11631207            String comment = ((UserTermInfo) userInfo.get(i)).comment;
    11641208            String email = ((UserTermInfo) userInfo.get(i)).email;
    1165             user_node.setAttribute("username", username);
    1166             user_node.setAttribute("groups", groups);
    1167             user_node.setAttribute("status", accountstatus);
    1168             user_node.setAttribute("comment", comment);
    1169             user_node.setAttribute("email", email);
     1209            user_node.setAttribute(USERNAME, username);
     1210            user_node.setAttribute(GROUPS, groups);
     1211            user_node.setAttribute(STATUS, accountstatus);
     1212            user_node.setAttribute(COMMENT, comment);
     1213            user_node.setAttribute(EMAIL, email);
    11701214
    11711215            user_list_node.appendChild(user_node);
Note: See TracChangeset for help on using the changeset viewer.