01: /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
02: *
03: * Licensed under the Apache License, Version 2.0 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * 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.springframework.dao.DataAccessException;
19:
20: /**
21: * <p>
22: * Interface for performing authentication operations on a password.
23: * </p>
24: *
25: * @author colin sampaleanu
26: * @version $Id: PasswordEncoder.java 1784 2007-02-24 21:00:24Z luke_t $
27: */
28: public interface PasswordEncoder {
29: //~ Methods ========================================================================================================
30:
31: /**
32: * <p>Encodes the specified raw password with an implementation specific algorithm.</p>
33: * <P>This will generally be a one-way message digest such as MD5 or SHA, but may also be a plaintext
34: * variant which does no encoding at all, but rather returns the same password it was fed. The latter is useful to
35: * plug in when the original password must be stored as-is.</p>
36: * <p>The specified salt will potentially be used by the implementation to "salt" the initial value before
37: * encoding. A salt is usually a user-specific value which is added to the password before the digest is computed.
38: * This means that computation of digests for common dictionary words will be different than those in the backend
39: * store, because the dictionary word digests will not reflect the addition of the salt. If a per-user salt is
40: * used (rather than a system-wide salt), it also means users with the same password will have different digest
41: * encoded passwords in the backend store.</p>
42: * <P>If a salt value is provided, the same salt value must be use when calling the {@link
43: * #isPasswordValid(String, String, Object)} method. Note that a specific implementation may choose to ignore the
44: * salt value (via <code>null</code>), or provide its own.</p>
45: *
46: * @param rawPass the password to encode
47: * @param salt optionally used by the implementation to "salt" the raw password before encoding. A
48: * <code>null</code> value is legal.
49: *
50: * @return encoded password
51: *
52: * @throws DataAccessException DOCUMENT ME!
53: */
54: String encodePassword(String rawPass, Object salt)
55: throws DataAccessException;
56:
57: /**
58: * <p>Validates a specified "raw" password against an encoded password.</p>
59: * <P>The encoded password should have previously been generated by {@link #encodePassword(String,
60: * Object)}. This method will encode the <code>rawPass</code> (using the optional <code>salt</code>), and then
61: * compared it with the presented <code>encPass</code>.</p>
62: * <p>For a discussion of salts, please refer to {@link #encodePassword(String, Object)}.</p>
63: *
64: * @param encPass a pre-encoded password
65: * @param rawPass a raw password to encode and compare against the pre-encoded password
66: * @param salt optionally used by the implementation to "salt" the raw password before encoding. A
67: * <code>null</code> value is legal.
68: *
69: * @return true if the password is valid , false otherwise
70: *
71: * @throws DataAccessException DOCUMENT ME!
72: */
73: boolean isPasswordValid(String encPass, String rawPass, Object salt)
74: throws DataAccessException;
75: }
|