Changeset 25722 for main


Ignore:
Timestamp:
2012-05-31T13:16:11+12:00 (12 years ago)
Author:
sjm84
Message:

An attempt at fixing the registration problem for systems behind a firewall that does not let them access google services

File:
1 edited

Legend:

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

    r25635 r25722  
    11package org.greenstone.gsdl3.service;
    22
    3 import org.greenstone.gsdl3.util.GSXML;
    4 import org.greenstone.gsdl3.util.DerbyWrapper;
    5 import org.greenstone.gsdl3.util.UserQueryResult;
    6 import org.greenstone.gsdl3.util.UserTermInfo;
    7 
    8 import org.w3c.dom.Element;
    9 import org.w3c.dom.NodeList;
    10 
     3import java.io.File;
     4import java.io.Serializable;
    115import java.math.BigInteger;
     6import java.security.MessageDigest;
     7import java.sql.SQLException;
    128import java.util.ArrayList;
    139import java.util.HashMap;
    1410import java.util.UUID;
    1511import java.util.Vector;
    16 import java.security.MessageDigest;
    17 import java.sql.SQLException;
    1812import java.util.regex.Pattern;
    19 import java.io.File;
    20 import java.io.Serializable;
    2113
    2214import net.tanesha.recaptcha.ReCaptchaImpl;
    2315import net.tanesha.recaptcha.ReCaptchaResponse;
     16
     17import org.greenstone.gsdl3.util.DerbyWrapper;
     18import org.greenstone.gsdl3.util.GSXML;
     19import org.greenstone.gsdl3.util.UserQueryResult;
     20import org.greenstone.gsdl3.util.UserTermInfo;
     21import org.w3c.dom.Element;
     22import org.w3c.dom.NodeList;
    2423
    2524public class Authentication extends ServiceRack
     
    360359            String newComment = (String) paramMap.get("comment");
    361360            String newEmail = (String) paramMap.get("email");
    362            
     361
    363362            //Check the given user name
    364363            int error;
     
    395394            String newPassword = (String) paramMap.get("password");
    396395            String newEmail = (String) paramMap.get("email");
    397            
     396
    398397            //Check the given user name
    399398            int error;
     
    410409                return result;
    411410            }
    412            
     411
    413412            newPassword = hashPassword(newPassword);
    414413
    415             if(_recaptchaPrivateKey != null)
     414            if (_recaptchaPrivateKey != null)
    416415            {
    417416                ReCaptchaImpl reCaptcha = new ReCaptchaImpl();
    418417                reCaptcha.setPrivateKey(_recaptchaPrivateKey);
    419    
     418
    420419                String challenge = (String) paramMap.get("recaptcha_challenge_field");
    421420                String uResponse = (String) paramMap.get("recaptcha_response_field");
    422    
     421
    423422                if (challenge == null || uResponse == null)
    424423                {
     
    427426                    return result;
    428427                }
    429    
     428
    430429                ReCaptchaResponse reCaptchaResponse = reCaptcha.checkAnswer(request.getAttribute("remoteAddress"), challenge, uResponse);
    431    
     430
    432431                if (!reCaptchaResponse.isValid())
    433432                {
     
    475474                    return result;
    476475                }
    477                
     476
    478477                newPassword = hashPassword(newPassword);
    479478            }
    480            
     479
    481480            error = removeUser(previousUsername);
    482481            if (error != NO_ERROR)
     
    537536                    return result;
    538537                }
    539                
     538
    540539                //Check the given password
    541540                int error;
     
    545544                    return result;
    546545                }
    547                
     546
    548547                newPassword = hashPassword(newPassword);
    549548            }
     
    552551                newPassword = prevPassword;
    553552            }
    554            
     553
    555554            //Check the given user name
    556555            int error;
     
    560559                return result;
    561560            }
    562            
     561
    563562            String prevGroups = retrieveDataForUser(previousUsername, "groups");
    564563            String prevStatus = retrieveDataForUser(previousUsername, "status");
     
    638637        else if (op.equals(REGISTER))
    639638        {
    640             if(_recaptchaPublicKey != null && _recaptchaPrivateKey != null)
     639            try
     640            {
     641                ReCaptchaImpl reCaptcha = new ReCaptchaImpl();
     642                reCaptcha.setPrivateKey(_recaptchaPrivateKey);
     643                reCaptcha.checkAnswer(request.getAttribute("remoteAddress"), "", "");
     644            }
     645            catch(Exception ex)
     646            {
     647                return result;
     648            }
     649
     650            if (_recaptchaPublicKey != null && _recaptchaPrivateKey != null)
    641651            {
    642652                Element recaptchaElem = this.doc.createElement("recaptcha");
     
    660670        return result;
    661671    }
    662    
     672
    663673    public int checkUsernameAndPassword(String username, String password)
    664674    {
    665675        int uResult = checkUsername(username);
    666676        int pResult = checkPassword(password);
    667        
     677
    668678        return (uResult != NO_ERROR ? uResult : (pResult != NO_ERROR ? pResult : NO_ERROR));
    669679    }
    670    
     680
    671681    public int checkUsername(String username)
    672682    {
     
    678688        return NO_ERROR;
    679689    }
    680    
     690
    681691    public int checkPassword(String password)
    682692    {
     
    706716    }
    707717
    708 
    709    
    710     // This method can also be used for printing out the password in hex (in case
    711     // the password used the UTF-8 Charset), or the hex values in any unicode string.
    712     // From http://stackoverflow.com/questions/923863/converting-a-string-to-hexadecimal-in-java
    713     public static String toHex(String arg) {
    714     try {
    715         return String.format("%x", new BigInteger(arg.getBytes("US-ASCII"))); // set to same charset as used by hashPassword
    716     } catch (Exception e) { // UnsupportedEncodingException
    717         e.printStackTrace();
    718     }
    719     return "Unable to print";
    720     }
    721 
     718    // This method can also be used for printing out the password in hex (in case
     719    // the password used the UTF-8 Charset), or the hex values in any unicode string.
     720    // From http://stackoverflow.com/questions/923863/converting-a-string-to-hexadecimal-in-java
     721    public static String toHex(String arg)
     722    {
     723        try
     724        {
     725            return String.format("%x", new BigInteger(arg.getBytes("US-ASCII"))); // set to same charset as used by hashPassword
     726        }
     727        catch (Exception e)
     728        { // UnsupportedEncodingException
     729            e.printStackTrace();
     730        }
     731        return "Unable to print";
     732    }
    722733
    723734    private void checkAdminUserExists()
Note: See TracChangeset for help on using the changeset viewer.