1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.security.spi.impl;
18
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21 import org.apache.jetspeed.security.SecurityException;
22 import org.apache.jetspeed.security.om.InternalCredential;
23 import org.apache.jetspeed.security.spi.InternalPasswordCredentialInterceptor;
24 import org.apache.jetspeed.security.spi.PasswordCredentialProvider;
25
26 /***
27 * <p>
28 * Checks if a (pre)set password in the persitent store is valid according to the configured
29 * {@link PasswordCredentialProvider#getValidator() validator} when loaded from the persistent store.</p>
30 * <p>
31 * If the password checks out to be invalid, an error is logged and the credential is flagged to be
32 * {@link InternalCredential#isUpdateRequired() updateRequired}.</p>
33 *
34 * @author <a href="mailto:ate@douma.nu">Ate Douma</a>
35 * @version $Id$
36 */
37 public class ValidatePasswordOnLoadInterceptor extends AbstractInternalPasswordCredentialInterceptorImpl
38 {
39 private static final Log log = LogFactory.getLog(InternalPasswordCredentialInterceptor.class);
40
41 /***
42 * @return true is the password was invalid and update is required
43 * @see org.apache.jetspeed.security.spi.InternalPasswordCredentialInterceptor#afterLoad(org.apache.jetspeed.security.spi.PasswordCredentialProvider, java.lang.String, org.apache.jetspeed.security.om.InternalCredential)
44 */
45 public boolean afterLoad(PasswordCredentialProvider pcProvider, String userName, InternalCredential credential)
46 throws SecurityException
47 {
48 boolean updated = false;
49 if (!credential.isEncoded() && pcProvider.getValidator() != null )
50 {
51 try
52 {
53 pcProvider.getValidator().validate(credential.getValue());
54 }
55 catch (SecurityException e)
56 {
57 log.error("Loaded password for user "+userName+" is invalid. The user will be required to change it.");
58
59
60 credential.setUpdateRequired(true);
61 updated = true;
62 }
63 }
64 return updated;
65 }
66 }