Changeset 25722 for main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/Authentication.java
- Timestamp:
- 2012-05-31T13:16:11+12:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/Authentication.java
r25635 r25722 1 1 package org.greenstone.gsdl3.service; 2 2 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 3 import java.io.File; 4 import java.io.Serializable; 11 5 import java.math.BigInteger; 6 import java.security.MessageDigest; 7 import java.sql.SQLException; 12 8 import java.util.ArrayList; 13 9 import java.util.HashMap; 14 10 import java.util.UUID; 15 11 import java.util.Vector; 16 import java.security.MessageDigest;17 import java.sql.SQLException;18 12 import java.util.regex.Pattern; 19 import java.io.File;20 import java.io.Serializable;21 13 22 14 import net.tanesha.recaptcha.ReCaptchaImpl; 23 15 import net.tanesha.recaptcha.ReCaptchaResponse; 16 17 import org.greenstone.gsdl3.util.DerbyWrapper; 18 import org.greenstone.gsdl3.util.GSXML; 19 import org.greenstone.gsdl3.util.UserQueryResult; 20 import org.greenstone.gsdl3.util.UserTermInfo; 21 import org.w3c.dom.Element; 22 import org.w3c.dom.NodeList; 24 23 25 24 public class Authentication extends ServiceRack … … 360 359 String newComment = (String) paramMap.get("comment"); 361 360 String newEmail = (String) paramMap.get("email"); 362 361 363 362 //Check the given user name 364 363 int error; … … 395 394 String newPassword = (String) paramMap.get("password"); 396 395 String newEmail = (String) paramMap.get("email"); 397 396 398 397 //Check the given user name 399 398 int error; … … 410 409 return result; 411 410 } 412 411 413 412 newPassword = hashPassword(newPassword); 414 413 415 if (_recaptchaPrivateKey != null)414 if (_recaptchaPrivateKey != null) 416 415 { 417 416 ReCaptchaImpl reCaptcha = new ReCaptchaImpl(); 418 417 reCaptcha.setPrivateKey(_recaptchaPrivateKey); 419 418 420 419 String challenge = (String) paramMap.get("recaptcha_challenge_field"); 421 420 String uResponse = (String) paramMap.get("recaptcha_response_field"); 422 421 423 422 if (challenge == null || uResponse == null) 424 423 { … … 427 426 return result; 428 427 } 429 428 430 429 ReCaptchaResponse reCaptchaResponse = reCaptcha.checkAnswer(request.getAttribute("remoteAddress"), challenge, uResponse); 431 430 432 431 if (!reCaptchaResponse.isValid()) 433 432 { … … 475 474 return result; 476 475 } 477 476 478 477 newPassword = hashPassword(newPassword); 479 478 } 480 479 481 480 error = removeUser(previousUsername); 482 481 if (error != NO_ERROR) … … 537 536 return result; 538 537 } 539 538 540 539 //Check the given password 541 540 int error; … … 545 544 return result; 546 545 } 547 546 548 547 newPassword = hashPassword(newPassword); 549 548 } … … 552 551 newPassword = prevPassword; 553 552 } 554 553 555 554 //Check the given user name 556 555 int error; … … 560 559 return result; 561 560 } 562 561 563 562 String prevGroups = retrieveDataForUser(previousUsername, "groups"); 564 563 String prevStatus = retrieveDataForUser(previousUsername, "status"); … … 638 637 else if (op.equals(REGISTER)) 639 638 { 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) 641 651 { 642 652 Element recaptchaElem = this.doc.createElement("recaptcha"); … … 660 670 return result; 661 671 } 662 672 663 673 public int checkUsernameAndPassword(String username, String password) 664 674 { 665 675 int uResult = checkUsername(username); 666 676 int pResult = checkPassword(password); 667 677 668 678 return (uResult != NO_ERROR ? uResult : (pResult != NO_ERROR ? pResult : NO_ERROR)); 669 679 } 670 680 671 681 public int checkUsername(String username) 672 682 { … … 678 688 return NO_ERROR; 679 689 } 680 690 681 691 public int checkPassword(String password) 682 692 { … … 706 716 } 707 717 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 } 722 733 723 734 private void checkAdminUserExists()
Note:
See TracChangeset
for help on using the changeset viewer.