http://www.ja-sig.org/issues/browse/CAS-581

Cheers!

On 10/24/07, Scott Battaglia <[EMAIL PROTECTED]> wrote:
>
> right now that's the best way.  If you can submit a JIRA issue for an
> enhancement, we can add that in for 3.1.2:
>
> http://www.ja-sig.org/issues
>
> Thanks!
> -Scott
>
> On 10/24/07, jashaffner <[EMAIL PROTECTED]> wrote:
> >
> >
> > I need to make use of UTF-8 so I tweaked DefaultPasswordEncoder. Is
> > there
> > better way to do so?
> >
> > public final class DefaultPasswordEncoder implements PasswordEncoder {
> >
> >     private static final char[] HEX_DIGITS = {'0', '1', '2', '3', '4',
> > '5',
> >         '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
> >
> >     @NotNull
> >     private final String encodingAlgorithm;
> >
> >         private boolean useUTF8;
> >
> >     public DefaultPasswordEncoder(final String encodingAlgorithm) {
> >         this.encodingAlgorithm = encodingAlgorithm;
> >     }
> >
> >     public DefaultPasswordEncoder(final String encodingAlgorithm, final
> > boolean useUTF8) {
> >         this.encodingAlgorithm = encodingAlgorithm;
> >         this.useUTF8 = useUTF8;
> >     }
> >
> >     public String encode(final String password) {
> >         if (password == null) {
> >             return null;
> >         }
> >
> >         try {
> >             MessageDigest messageDigest = MessageDigest
> >                 .getInstance(this.encodingAlgorithm);
> >             if (useUTF8) {
> >                                 messageDigest.update (password.getBytes
> > ("UTF-8"));
> >
> >                     final byte[] digest = messageDigest.digest();
> >
> >                     BASE64Encoder encoder = new BASE64Encoder();
> >
> >                     return encoder.encode (digest);
> >             } else {
> >                 messageDigest.update(password.getBytes());
> >
> >                 final byte[] digest = messageDigest.digest();
> >
> >                 return getFormattedText(digest);
> >             }
> >         } catch (NoSuchAlgorithmException e) {
> >             throw new SecurityException(e);
> >         } catch (UnsupportedEncodingException e){
> >                 throw new SecurityException(e);
> >         }
> >     }
> >
> >     /**
> >      * Takes the raw bytes from the digest and formats them correct.
> >      *
> >      * @param bytes the raw bytes from the digest.
> >      * @return the formatted bytes.
> >      */
> >     private String getFormattedText(byte[] bytes) {
> >
> >         final StringBuilder buf = new StringBuilder(bytes.length * 2);
> >
> >         for (int j = 0; j < bytes.length; j++) {
> >             buf.append(HEX_DIGITS[(bytes[j] >> 4) & 0x0f]);
> >              buf.append(HEX_DIGITS[bytes[j] & 0x0f]);
> >         }
> >         return buf.toString();
> >     }
> > }
> > --
> > View this message in context:
> > http://www.nabble.com/Use-UTF-8-in-DefaultPasswordEncoder-tf4686761.html#a13394070
> > Sent from the CAS Users mailing list archive at Nabble.com.
> >
> > _______________________________________________
> > Yale CAS mailing list
> > [email protected]
> > http://tp.its.yale.edu/mailman/listinfo/cas
> >
>
>
>
> --
> -Scott Battaglia
>
> LinkedIn: http://www.linkedin.com/in/scottbattaglia
> _______________________________________________
> Yale CAS mailing list
> [email protected]
> http://tp.its.yale.edu/mailman/listinfo/cas
>
>
_______________________________________________
Yale CAS mailing list
[email protected]
http://tp.its.yale.edu/mailman/listinfo/cas

Reply via email to