001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.util.DateUtil;
019    import com.liferay.portal.model.PasswordPolicy;
020    import com.liferay.portal.model.User;
021    
022    /**
023     * @author Scott Lee
024     */
025    public class UserLockoutException extends PortalException {
026    
027            /**
028             * @deprecated As of 7.0.0, replaced by the inner classes
029             */
030            public UserLockoutException() {
031                    super();
032            }
033    
034            /**
035             * @deprecated As of 7.0.0, replaced by the inner classes
036             */
037            public UserLockoutException(String msg) {
038                    super(msg);
039            }
040    
041            /**
042             * @deprecated As of 7.0.0, replaced by the inner classes
043             */
044            public UserLockoutException(String msg, Throwable cause) {
045                    super(msg, cause);
046            }
047    
048            /**
049             * @deprecated As of 7.0.0, replaced by the inner classes
050             */
051            public UserLockoutException(Throwable cause) {
052                    super(cause);
053            }
054    
055            public static class LDAPLockout extends UserLockoutException {
056    
057                    public LDAPLockout(String fullUserDN, String ldapMessage) {
058                            super(
059                                    String.format(
060                                            "User %s is locked out of a required LDAP server: %s",
061                                            fullUserDN, ldapMessage));
062    
063                            _fullUserDN = fullUserDN;
064                            _ldapMessage = ldapMessage;
065                    }
066    
067                    public String getFullUserDN() {
068                            return _fullUserDN;
069                    }
070    
071                    public String getLDAPMessage() {
072                            return _ldapMessage;
073                    }
074    
075                    private final String _fullUserDN;
076                    private final String _ldapMessage;
077    
078            }
079    
080            public static class PasswordPolicyLockout extends UserLockoutException {
081    
082                    public PasswordPolicyLockout(User user, PasswordPolicy passwordPolicy) {
083                            super(
084                                    String.format(
085                                            "User %s was locked on %s by password policy %s and will " +
086                                                    "be automatically unlocked on %s",
087                                            user.getUserId(), user.getLockoutDate(),
088                                            passwordPolicy.getName(),
089                                            DateUtil.newDate(
090                                                    user.getLockoutDate().getTime() +
091                                                            passwordPolicy.getLockoutDuration() * 1000)));
092    
093                            _user = user;
094                            _passwordPolicy = passwordPolicy;
095                    }
096    
097                    public PasswordPolicy getPasswordPolicy() {
098                            return _passwordPolicy;
099                    }
100    
101                    public User getUser() {
102                            return _user;
103                    }
104    
105                    private final PasswordPolicy _passwordPolicy;
106                    private final User _user;
107    
108            }
109    
110    }