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