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            @Deprecated
031            public UserLockoutException() {
032            }
033    
034            /**
035             * @deprecated As of 7.0.0, replaced by the inner classes
036             */
037            @Deprecated
038            public UserLockoutException(String msg) {
039                    super(msg);
040            }
041    
042            /**
043             * @deprecated As of 7.0.0, replaced by the inner classes
044             */
045            @Deprecated
046            public UserLockoutException(String msg, Throwable cause) {
047                    super(msg, cause);
048            }
049    
050            /**
051             * @deprecated As of 7.0.0, replaced by the inner classes
052             */
053            @Deprecated
054            public UserLockoutException(Throwable cause) {
055                    super(cause);
056            }
057    
058            public static class LDAPLockout extends UserLockoutException {
059    
060                    public LDAPLockout(String fullUserDN, String ldapMessage) {
061                            super(
062                                    String.format(
063                                            "User %s is locked out of a required LDAP server: %s",
064                                            fullUserDN, ldapMessage));
065    
066                            this.fullUserDN = fullUserDN;
067                            this.ldapMessage = ldapMessage;
068                    }
069    
070                    public final String fullUserDN;
071                    public final String ldapMessage;
072    
073            }
074    
075            public static class PasswordPolicyLockout extends UserLockoutException {
076    
077                    public PasswordPolicyLockout(User user, PasswordPolicy passwordPolicy) {
078                            super(
079                                    String.format(
080                                            "User %s was locked on %s by password policy %s and will " +
081                                                    "be automatically unlocked on %s",
082                                            user.getUserId(), user.getLockoutDate(),
083                                            passwordPolicy.getName(),
084                                            DateUtil.newDate(
085                                                    user.getLockoutDate().getTime() +
086                                                            passwordPolicy.getLockoutDuration() * 1000)));
087    
088                            this.user = user;
089                            this.passwordPolicy = passwordPolicy;
090                    }
091    
092                    public final PasswordPolicy passwordPolicy;
093                    public final User user;
094    
095            }
096    
097    }