1 /* Copyright 2004, 2005, 2006 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.springframework.ws.soap.security.support;
17
18 import org.springframework.security.userdetails.UserDetails;
19 import org.springframework.security.LockedException;
20 import org.springframework.security.DisabledException;
21 import org.springframework.security.AccountExpiredException;
22 import org.springframework.security.CredentialsExpiredException;
23
24 /**
25 * Generic utility methods for Spring Security
26 *
27 * @author Tareq Abedrabbo
28 * @since 1.5.8
29 */
30 public abstract class SpringSecurityUtils {
31
32 /**
33 * Checks the validity of a user's account and credentials.
34 * @param user the user to check
35 * @throws AccountExpiredException if the account has expired
36 * @throws CredentialsExpiredException if the credentials have expired
37 * @throws DisabledException if the account is disabled
38 * @throws LockedException if the account is locked
39 */
40 public static void checkUserValidity(UserDetails user)
41 throws AccountExpiredException, CredentialsExpiredException, DisabledException, LockedException {
42 if (!user.isAccountNonLocked()) {
43 throw new LockedException("User account is locked", user);
44 }
45
46 if (!user.isEnabled()) {
47 throw new DisabledException("User is disabled", user);
48 }
49
50 if (!user.isAccountNonExpired()) {
51 throw new AccountExpiredException("User account has expired", user);
52 }
53
54 if (!user.isCredentialsNonExpired()) {
55 throw new CredentialsExpiredException("User credentials have expired", user);
56 }
57 }
58 }