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.kernel.exception;
016    
017    import com.liferay.portal.kernel.model.PasswordPolicy;
018    import com.liferay.portal.kernel.model.User;
019    
020    /**
021     * @author Scott Lee
022     */
023    public class UserLockoutException extends PortalException {
024    
025            /**
026             * @deprecated As of 7.0.0, replaced by the inner classes
027             */
028            @Deprecated
029            public UserLockoutException() {
030            }
031    
032            /**
033             * @deprecated As of 7.0.0, replaced by the inner classes
034             */
035            @Deprecated
036            public UserLockoutException(String msg) {
037                    super(msg);
038            }
039    
040            /**
041             * @deprecated As of 7.0.0, replaced by the inner classes
042             */
043            @Deprecated
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            @Deprecated
052            public UserLockoutException(Throwable cause) {
053                    super(cause);
054            }
055    
056            public static class LDAPLockout extends UserLockoutException {
057    
058                    public LDAPLockout(String fullUserDN, String ldapMessage) {
059                            super(
060                                    String.format(
061                                            "User %s is locked out of a required LDAP server: %s",
062                                            fullUserDN, ldapMessage));
063    
064                            this.fullUserDN = fullUserDN;
065                            this.ldapMessage = ldapMessage;
066                    }
067    
068                    public final String fullUserDN;
069                    public final String ldapMessage;
070    
071            }
072    
073            public static class PasswordPolicyLockout extends UserLockoutException {
074    
075                    public PasswordPolicyLockout(User user, PasswordPolicy passwordPolicy) {
076                            super(
077                                    String.format(
078                                            "User %s was locked on %s by password policy %s and will " +
079                                                    "be automatically unlocked on %s",
080                                            user.getUserId(), user.getLockoutDate(),
081                                            passwordPolicy.getName(),
082                                            user.getUnlockDate(passwordPolicy)));
083    
084                            this.user = user;
085                            this.passwordPolicy = passwordPolicy;
086                    }
087    
088                    public final PasswordPolicy passwordPolicy;
089                    public final User user;
090    
091            }
092    
093    }