Author: vbriand Date: 2011-02-25 10:53:59 +0100 (Fri, 25 Feb 2011) New Revision: 217 Url: http://chorem.org/repositories/revision/bow/217 Log: The token is now generated by UUID Modified: trunk/src/main/java/org/chorem/bow/BowUtils.java trunk/src/main/resources/i18n/bow_fr_FR.properties Modified: trunk/src/main/java/org/chorem/bow/BowUtils.java =================================================================== --- trunk/src/main/java/org/chorem/bow/BowUtils.java 2011-02-25 09:15:39 UTC (rev 216) +++ trunk/src/main/java/org/chorem/bow/BowUtils.java 2011-02-25 09:53:59 UTC (rev 217) @@ -23,6 +23,7 @@ */ package org.chorem.bow; +import java.util.UUID; import org.nuiton.util.StringUtil; import org.nuiton.wikitty.search.Criteria; import org.nuiton.wikitty.WikittyProxy; @@ -33,15 +34,25 @@ private BowUtils() { } + /** + * Generates a random token + * + * @return the generated token + */ static public String generateToken() { - Double rand = Math.random() * 100000000; - int res = (int) Math.abs(rand); // generate a token between 0 and 100 000 000 - String tokenGenerated = String.valueOf(res); + UUID uuid = UUID.randomUUID(); + String tokenGenerated = uuid.toString(); tokenGenerated = StringUtil.encodeMD5(tokenGenerated); // encode the token in MD5 - return tokenGenerated; // return the generate token + return tokenGenerated; // return the generated token } - + /** + * Redirects the user either on the home page or on the search page + * + * @param searchLine + * @param fullTextLine + * @return the page where the user will be redirected + */ static public String redirectTo(String searchLine, String fullTextLine) { String result = "home.action"; @@ -51,6 +62,14 @@ return result; } + /** + * Retrieves the user by the temporary or the permanent token + * + * @param session the session + * @param token either the temporary or the permanent token + * @return null if the token doesn't exist + * @return the user if the token is valid + */ static public BowUser checkToken(BowSession session, String token) { BowUser result = null; if (checkTemporaryToken(session, token) || checkPermanentToken(session, token)) { Modified: trunk/src/main/resources/i18n/bow_fr_FR.properties =================================================================== --- trunk/src/main/resources/i18n/bow_fr_FR.properties 2011-02-25 09:15:39 UTC (rev 216) +++ trunk/src/main/resources/i18n/bow_fr_FR.properties 2011-02-25 09:53:59 UTC (rev 217) @@ -109,4 +109,4 @@ bow.search.orderby=Trier par bow.search.submit=Rechercher bow.search.title=Recherche -bow.token.generate.successful=Le token a y00E9t\u00E9 reg\u00E9n\u00E9r\u00E9 avec succ\u00E8s +bow.token.generate.successful=Le token a \u00E9t\u00E9 reg\u00E9n\u00E9r\u00E9 avec succ\u00E8s