Author: jalkanen
Date: Sun Jun  1 10:50:35 2008
New Revision: 662256

URL: http://svn.apache.org/viewvc?rev=662256&view=rev
Log:
Javadoc upgrades; fixed some issues with password hashes being generated in 
platform native encoding instead of UTF-8.

Modified:
    incubator/jspwiki/trunk/ChangeLog
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java
    
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/auth/user/AbstractUserDatabase.java
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/CryptoUtil.java
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/FormUtil.java
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/PriorityList.java
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/Serializer.java
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/TimedCounterList.java
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/WatchDog.java
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/WikiBackgroundThread.java
    incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/util/CryptoUtilTest.java

Modified: incubator/jspwiki/trunk/ChangeLog
URL: 
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/ChangeLog?rev=662256&r1=662255&r2=662256&view=diff
==============================================================================
--- incubator/jspwiki/trunk/ChangeLog (original)
+++ incubator/jspwiki/trunk/ChangeLog Sun Jun  1 10:50:35 2008
@@ -1,3 +1,12 @@
+2008-06-01  Janne Jalkanen <[EMAIL PROTECTED]>
+
+        * 2.7.0-svn-32
+
+        * Password hashes were generated in platform native encoding
+        instead of UTF-8.  Oops.
+        
+        * In general, there have been massive upgrades of Javadocs.
+
 2008-05-31  Janne Jalkanen <[EMAIL PROTECTED]>
 
         * 2.7.0-svn-31

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java
URL: 
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java?rev=662256&r1=662255&r2=662256&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java Sun Jun  1 
10:50:35 2008
@@ -77,7 +77,7 @@
      *  <p>
      *  If the build identifier is empty, it is not added.
      */
-    public static final String     BUILD         = "31";
+    public static final String     BUILD         = "32";
     
     /**
      *  This is the generic version string you should use

Modified: 
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/auth/user/AbstractUserDatabase.java
URL: 
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/auth/user/AbstractUserDatabase.java?rev=662256&r1=662255&r2=662256&view=diff
==============================================================================
--- 
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/auth/user/AbstractUserDatabase.java
 (original)
+++ 
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/auth/user/AbstractUserDatabase.java
 Sun Jun  1 10:50:35 2008
@@ -226,7 +226,7 @@
             if ( newPasswordFormat )
             {
                 hashedPassword = getHash( password );
-                return CryptoUtil.verifySaltedPassword( password.getBytes(), 
storedPassword );
+                return CryptoUtil.verifySaltedPassword( 
password.getBytes("UTF-8"), storedPassword );
             }
 
             // If old format, verify using the old SHA verification algorithm
@@ -253,6 +253,10 @@
         {
             log.error( "Unsupported algorithm: " + e.getMessage() );
         }
+        catch( UnsupportedEncodingException e )
+        {
+            log.fatal( "You do not have UTF-8!?!" );
+        }
         catch( WikiSecurityException e )
         {
             log.error( "Could not upgrade SHA password to SSHA because profile 
could not be saved. Reason: " + e.getMessage() );
@@ -300,13 +304,17 @@
         String hash = null;
         try
         {
-            hash = CryptoUtil.getSaltedPassword( text.getBytes() );
+            hash = CryptoUtil.getSaltedPassword( text.getBytes("UTF-8") );
         }
         catch( NoSuchAlgorithmException e )
         {
             log.error( "Error creating salted SHA password hash:" + 
e.getMessage() );
             hash = text;
         }
+        catch( UnsupportedEncodingException e )
+        {
+            log.fatal("You do not have UTF-8!?!");
+        }
         return hash;
     }
 

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/CryptoUtil.java
URL: 
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/CryptoUtil.java?rev=662256&r1=662255&r2=662256&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/CryptoUtil.java 
(original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/CryptoUtil.java Sun Jun  
1 10:50:35 2008
@@ -1,5 +1,6 @@
 package com.ecyrd.jspwiki.util;
 
+import java.io.UnsupportedEncodingException;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.security.SecureRandom;
@@ -56,6 +57,7 @@
      * <blockquote><code>java -cp JSPWiki.jar:../lib/commons-codec-1.3.jar 
com.ecyrd.jspwiki.util.CryptoUtil --hash mynewpassword</code></blockquote>
      * 
      * @param args arguments for this method as described above
+     * @throws Exception Catches nothing; throws everything up.
      */
     public static void main( String[] args ) throws Exception
     {
@@ -76,7 +78,7 @@
                 throw new IllegalArgumentException( "Error: --hash requires a 
'password' argument." );
             }
             String password = args[1].trim();
-            System.out.println( CryptoUtil.getSaltedPassword( 
password.getBytes() ) );
+            System.out.println( CryptoUtil.getSaltedPassword( 
password.getBytes("UTF-8") ) );
         }
 
         // User wants to verify an existing password
@@ -88,7 +90,7 @@
             }
             String password = args[1].trim();
             String digest = args[2].trim();
-            System.out.println( CryptoUtil.verifySaltedPassword( 
password.getBytes(), digest ) );
+            System.out.println( CryptoUtil.verifySaltedPassword( 
password.getBytes("UTF-8"), digest ) );
         }
 
         else
@@ -118,6 +120,7 @@
      * @param password the password to be digested
      * @return the Base64-encoded password hash, prepended by
      *         <code>{SSHA}</code>.
+     * @throws NoSuchAlgorithmException If your JVM is completely b0rked and 
does not have SHA.
      */
     public static String getSaltedPassword( byte[] password ) throws 
NoSuchAlgorithmException
     {
@@ -142,6 +145,7 @@
      * @param password the password to be digested
      * @param salt the random salt
      * @return the Base64-encoded password hash, prepended by 
<code>{SSHA}</code>.
+     * @throws NoSuchAlgorithmException If your JVM is totally b0rked and does 
not have SHA1.
      */
     protected static String getSaltedPassword( byte[] password, byte[] salt ) 
throws NoSuchAlgorithmException
     {
@@ -163,14 +167,24 @@
         return SSHA + new String( base64 );
     }
 
-    public static boolean verifySaltedPassword( byte[] password, String entry 
) throws NoSuchAlgorithmException
+    /**
+     *  Compares a password to a given entry and returns true, if it matches.
+     *  
+     *  @param password The password in bytes.
+     *  @param entry The password entry, typically starting with {SSHA}.
+     *  @return True, if the password matches.
+     *  @throws NoSuchAlgorithmException If there is no SHA available.
+     *  @throws UnsupportedEncodingException If no UTF-8 encoding is available 
+     */
+    public static boolean verifySaltedPassword( byte[] password, String entry 
) 
+        throws NoSuchAlgorithmException, UnsupportedEncodingException
     {
         // First, extract everything after {SSHA} and decode from Base64
         if( !entry.startsWith( SSHA ) )
         {
             throw new IllegalArgumentException( "Hash not prefixed by {SSHA}; 
is it really a salted hash?" );
         }
-        byte[] challenge = Base64.decodeBase64( entry.substring( 6 
).getBytes() );
+        byte[] challenge = Base64.decodeBase64( entry.substring( 6 
).getBytes("UTF-8") );
 
         // Extract the password hash and salt
         byte[] passwordHash = extractPasswordHash( challenge );
@@ -195,7 +209,7 @@
      * @throws IllegalArgumentException if the length of the supplied digest is
      *             less than or equal to 20 bytes
      */
-    protected static byte[] extractPasswordHash( byte[] digest )
+    protected static byte[] extractPasswordHash( byte[] digest ) throws 
IllegalArgumentException
     {
         if( digest.length < 20 )
         {
@@ -222,7 +236,7 @@
      * @throws IllegalArgumentException if the length of the supplied digest is
      *             less than or equal to 20 bytes
      */
-    protected static byte[] extractSalt( byte[] digest )
+    protected static byte[] extractSalt( byte[] digest ) throws 
IllegalArgumentException
     {
         if( digest.length <= 20 )
         {

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/FormUtil.java
URL: 
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/FormUtil.java?rev=662256&r1=662255&r2=662256&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/FormUtil.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/FormUtil.java Sun Jun  1 
10:50:35 2008
@@ -60,7 +60,7 @@
         Object entry = params.get( key );
         if( entry != null )
         {
-            ArrayList rval = new ArrayList(1);
+            ArrayList<Object> rval = new ArrayList<Object>(1);
             rval.add( entry );
             return rval;
         }
@@ -89,7 +89,7 @@
      */
     public static ArrayList getNumberedValues( Map params, String keyPrefix )
     {
-        ArrayList rval = new ArrayList();
+        ArrayList<Object> rval = new ArrayList<Object>();
         if( params == null || 
             params.size() == 0 || 
             keyPrefix == null || 
@@ -139,7 +139,7 @@
     public static Map requestToMap( HttpServletRequest req, 
                                     String filterPrefix )
     {
-        HashMap params = new HashMap();
+        HashMap<String,String> params = new HashMap<String,String>();
         
         if( filterPrefix == null ) filterPrefix = "";
         

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/PriorityList.java
URL: 
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/PriorityList.java?rev=662256&r1=662255&r2=662256&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/PriorityList.java 
(original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/PriorityList.java Sun 
Jun  1 10:50:35 2008
@@ -32,10 +32,11 @@
  *  Priority is an integer, and the list is sorted in descending order
  *  (that is, 100 is before 10 is before 0 is before -40).
  */
[EMAIL PROTECTED]("unchecked")
 public class PriorityList
     extends AbstractList
 {
-    private ArrayList m_elements = new ArrayList();
+    private ArrayList<Object> m_elements = new ArrayList<Object>();
 
     /**
      *  This is the default priority, which is used if no priority

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/Serializer.java
URL: 
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/Serializer.java?rev=662256&r1=662255&r2=662256&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/Serializer.java 
(original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/Serializer.java Sun Jun  
1 10:50:35 2008
@@ -1,3 +1,23 @@
+/* 
+    JSPWiki - a JSP-based WikiWiki clone.
+
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.  
+ */
 package com.ecyrd.jspwiki.util;
 
 import java.io.*;
@@ -6,8 +26,18 @@
 
 import org.apache.commons.codec.binary.Base64;
 
-public class Serializer
+/**
+ *  Provides static helper functions for serializing different objects.
+ *  
+ *  @since 2.8
+ */
+public final class Serializer
 {
+    /**
+     *  Prevent instantiation.
+     */
+    private Serializer()
+    {}
     
     /**
      * Deserializes a Base64-encoded String into a HashMap. Both the keys and 
values
@@ -20,7 +50,7 @@
     public static Map<? extends Serializable,? extends Serializable> 
deserializeFromBase64( String rawString ) throws IOException
     {
         // Decode from Base64-encoded String to byte array
-        byte[] decodedBytes = Base64.decodeBase64( rawString.getBytes() );
+        byte[] decodedBytes = Base64.decodeBase64( rawString.getBytes("UTF-8") 
);
         
         // Deserialize from the input stream to the Map
         InputStream bytesIn = new ByteArrayInputStream( decodedBytes );
@@ -44,8 +74,9 @@
     /**
      * Serializes a Map and formats it into a Base64-encoded String. For ease 
of serialization, the Map contents
      * are first copied into a HashMap, then serialized into a byte array that 
is encoded as a Base64 String.
-     * @param the Map to serialize
+     * @param map the Map to serialize
      * @return a String representing the serialized form of the Map
+     * @throws IOException If serialization cannot be done
      */
     public static String serializeToBase64( Map<Serializable,Serializable> map 
) throws IOException
     {

Modified: 
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/TimedCounterList.java
URL: 
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/TimedCounterList.java?rev=662256&r1=662255&r2=662256&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/TimedCounterList.java 
(original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/TimedCounterList.java 
Sun Jun  1 10:50:35 2008
@@ -41,6 +41,9 @@
     private ArrayList<CounterItem<T>> m_list = new ArrayList<CounterItem<T>>();
     private ReadWriteLock             m_lock = new ReentrantReadWriteLock();
     
+    /**
+     *  [EMAIL PROTECTED]
+     */
     @Override
     public T set( int index, T element )
     {
@@ -60,6 +63,9 @@
         return t;
     }
     
+    /**
+     *  [EMAIL PROTECTED]
+     */
     @Override
     public T get( int index )
     {
@@ -79,6 +85,9 @@
         return t;
     }
 
+    /**
+     *  [EMAIL PROTECTED]
+     */
     @Override
     public int size()
     {
@@ -97,7 +106,9 @@
         return size;
     }
     
-   
+    /**
+     *  [EMAIL PROTECTED]
+     */
     @Override
     public void add( int index, T element )
     {
@@ -112,7 +123,10 @@
             m_lock.writeLock().unlock();
         }
     }
-
+    
+    /**
+     *  [EMAIL PROTECTED]
+     */
     @Override
     public T remove( int index )
     {
@@ -135,8 +149,8 @@
      *  Returns the count how many times this object is available in
      *  this list, using equals().
      *  
-     *  @param obj
-     *  @return
+     *  @param obj The object to count.
+     *  @return The count of the objects.
      */
     public int count( T obj )
     {

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/WatchDog.java
URL: 
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/WatchDog.java?rev=662256&r1=662255&r2=662256&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/WatchDog.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/WatchDog.java Sun Jun  1 
10:50:35 2008
@@ -50,13 +50,15 @@
 public final class WatchDog
 {
     private Watchable m_watchable;
-    private Stack     m_stateStack = new Stack();
+    private Stack<State> m_stateStack = new Stack<State>();
     private boolean   m_enabled    = true;
     private WikiEngine m_engine;
 
     private static Logger log = Logger.getLogger(WatchDog.class.getName());
 
-    private static HashMap              c_kennel = new HashMap();
+    private static HashMap<Integer,WeakReference<WatchDog>> c_kennel = 
+        new HashMap<Integer,WeakReference<WatchDog>>();
+    
     private static WikiBackgroundThread c_watcherThread;
 
     /**
@@ -74,14 +76,14 @@
         Thread t = Thread.currentThread();
         WatchDog wd = null;
 
-        WeakReference w = (WeakReference)c_kennel.get( new 
Integer(t.hashCode()) );
+        WeakReference<WatchDog> w = c_kennel.get( new Integer(t.hashCode()) );
 
-        if( w != null ) wd = (WatchDog)w.get();
+        if( w != null ) wd = w.get();
 
         if( w == null || wd == null )
         {
             wd = new WatchDog( engine, t );
-            w = new WeakReference(wd);
+            w = new WeakReference<WatchDog>(wd);
 
             synchronized( c_kennel )
             {
@@ -263,7 +265,7 @@
         {
             synchronized( m_stateStack )
             {
-                State st = (State)m_stateStack.peek();
+                State st = m_stateStack.peek();
 
                 if( state == null || st.getState().equals(state) )
                 {
@@ -294,7 +296,7 @@
         {
             try
             {
-                WatchDog.State st = (WatchDog.State)m_stateStack.peek();
+                WatchDog.State st = m_stateStack.peek();
 
                 long now = System.currentTimeMillis();
 
@@ -329,7 +331,7 @@
 
             try
             {
-                State st = (State) m_stateStack.peek();
+                State st = m_stateStack.peek();
                 state = st.getState();
             }
             catch( EmptyStackException e ) {}
@@ -401,8 +403,6 @@
 
     /**
      *  A class which just stores the state in our State stack.
-     *
-     *  @author Janne Jalkanen
      */
     private static class State
     {
@@ -430,9 +430,6 @@
 
     /**
      *  This class wraps a Thread so that it can become Watchable.
-     *
-     *  @author Janne Jalkanen
-     *
      */
     private static class ThreadWrapper implements Watchable
     {

Modified: 
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/WikiBackgroundThread.java
URL: 
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/WikiBackgroundThread.java?rev=662256&r1=662255&r2=662256&view=diff
==============================================================================
--- 
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/WikiBackgroundThread.java 
(original)
+++ 
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/WikiBackgroundThread.java 
Sun Jun  1 10:50:35 2008
@@ -64,6 +64,8 @@
     /**
      * Listens for [EMAIL PROTECTED] 
com.ecyrd.jspwiki.event.WikiEngineEvent#SHUTDOWN}
      * and, if detected, marks the thread for death.
+     * 
+     * @param event [EMAIL PROTECTED]
      * @see 
com.ecyrd.jspwiki.event.WikiEventListener#actionPerformed(com.ecyrd.jspwiki.event.WikiEvent)
      */
     public final void actionPerformed( WikiEvent event )
@@ -81,6 +83,8 @@
     /**
      * Abstract method that performs the actual work for this
      * background thread; subclasses must implement this method.
+     * 
+     * @throws Exception Any exception can be thrown
      */
     public abstract void backgroundTask() throws Exception;
     
@@ -177,6 +181,8 @@
      * Executes a task after shutdown signal was detected.
      * By default, this method does nothing; override it 
      * to implement custom functionality.
+     * 
+     * @throws Exception Any exception can be thrown.
      */
     public void shutdownTask() throws Exception
     {
@@ -187,6 +193,8 @@
      * method starts, but before the [EMAIL PROTECTED] #backgroundTask()}
      * task executes. By default, this method does nothing; 
      * override it to implement custom functionality.
+     * 
+     * @throws Exception Any exception can be thrown.
      */
     public void startupTask() throws Exception
     {

Modified: 
incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/util/CryptoUtilTest.java
URL: 
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/util/CryptoUtilTest.java?rev=662256&r1=662255&r2=662256&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/util/CryptoUtilTest.java 
(original)
+++ incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/util/CryptoUtilTest.java 
Sun Jun  1 10:50:35 2008
@@ -139,7 +139,7 @@
         byte[] password;
 
         // Verify with a known digest
-        password = "testing123".getBytes();
+        password = "testing123".getBytes("UTF-8");
         assertTrue( CryptoUtil.verifySaltedPassword( password, 
"{SSHA}yfT8SRT/WoOuNuA6KbJeF10OznZmb28=" ) );
 
         // Verify with two more known digests


Reply via email to