Clover coverage report - Acegi Security System for Spring - 1.0.0-RC1
Coverage timestamp: Mon Dec 5 2005 09:05:15 EST
file stats: LOC: 64   Methods: 3
NCLOC: 21   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ShaPasswordEncoder.java 100% 100% 100% 100%
coverage
 1    /* Copyright 2004 Acegi Technology Pty Limited
 2    *
 3    * Licensed under the Apache License, Version 2.0 (the "License");
 4    * you may not use this file except in compliance with the License.
 5    * You may obtain a copy of the License at
 6    *
 7    * http://www.apache.org/licenses/LICENSE-2.0
 8    *
 9    * Unless required by applicable law or agreed to in writing, software
 10    * distributed under the License is distributed on an "AS IS" BASIS,
 11    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12    * See the License for the specific language governing permissions and
 13    * limitations under the License.
 14    */
 15   
 16    package org.acegisecurity.providers.encoding;
 17   
 18    import org.apache.commons.codec.binary.Base64;
 19    import org.apache.commons.codec.digest.DigestUtils;
 20   
 21   
 22    /**
 23    * <p>
 24    * SHA implementation of PasswordEncoder.
 25    * </p>
 26    *
 27    * <p>
 28    * If a <code>null</code> password is presented, it will be treated as an empty
 29    * <code>String</code> ("") password.
 30    * </p>
 31    *
 32    * <P>
 33    * As SHA is a one-way hash, the salt can contain any characters.
 34    * </p>
 35    *
 36    * @author colin sampaleanu
 37    * @author Ben Alex
 38    * @version $Id: ShaPasswordEncoder.java,v 1.4 2005/11/17 00:55:49 benalex Exp $
 39    */
 40    public class ShaPasswordEncoder extends BaseDigestPasswordEncoder
 41    implements PasswordEncoder {
 42    //~ Methods ================================================================
 43   
 44  4 public boolean isPasswordValid(String encPass, String rawPass, Object salt) {
 45  4 String pass1 = "" + encPass;
 46  4 String pass2 = encodeInternal(mergePasswordAndSalt(rawPass, salt, false));
 47   
 48  4 return pass1.equals(pass2);
 49    }
 50   
 51  2 public String encodePassword(String rawPass, Object salt) {
 52  2 return encodeInternal(mergePasswordAndSalt(rawPass, salt, false));
 53    }
 54   
 55  6 private String encodeInternal(String input) {
 56  6 if (!getEncodeHashAsBase64()) {
 57  3 return DigestUtils.shaHex(input);
 58    }
 59   
 60  3 byte[] encoded = Base64.encodeBase64(DigestUtils.sha(input));
 61   
 62  3 return new String(encoded);
 63    }
 64    }