1 /** 2 This file is part of GoldenGate Project (named also GoldenGate or GG). 3 4 Copyright 2009, Frederic Bregier, and individual contributors by the @author 5 tags. See the COPYRIGHT.txt in the distribution for a full listing of 6 individual contributors. 7 8 All GoldenGate Project is free software: you can redistribute it and/or 9 modify it under the terms of the GNU General Public License as published 10 by the Free Software Foundation, either version 3 of the License, or 11 (at your option) any later version. 12 13 GoldenGate is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 GNU General Public License for more details. 17 18 You should have received a copy of the GNU General Public License 19 along with GoldenGate . If not, see <http://www.gnu.org/licenses/>. 20 */ 21 package goldengate.ftp.filesystembased; 22 23 import goldengate.common.command.NextCommandReply; 24 import goldengate.common.command.ReplyCode; 25 import goldengate.common.command.exception.Reply421Exception; 26 import goldengate.common.command.exception.Reply502Exception; 27 import goldengate.common.command.exception.Reply530Exception; 28 import goldengate.common.file.filesystembased.FilesystemBasedAuthImpl; 29 import goldengate.ftp.core.file.FtpAuth; 30 import goldengate.ftp.core.file.FtpDir; 31 import goldengate.ftp.core.session.FtpSession; 32 33 /** 34 * Filesystem implementation of a AuthInterface 35 * 36 * @author Frederic Bregier 37 * 38 */ 39 public abstract class FilesystemBasedFtpAuth extends FilesystemBasedAuthImpl implements FtpAuth { 40 41 /** 42 * Account name 43 */ 44 protected String account = null; 45 46 /** 47 * 48 * @param session 49 */ 50 public FilesystemBasedFtpAuth(FtpSession session) { 51 super(session); 52 } 53 54 /** 55 * @return the account 56 */ 57 public String getAccount() { 58 return account; 59 } 60 61 /** 62 * Set the account according to any implementation and could set the 63 * rootFromAuth. If NOOP is returned, isIdentifed must be TRUE. 64 * 65 * @param account 66 * @return (NOOP,230) if the Account is OK, else return the following 67 * command that must follow and the associated reply 68 * @throws Reply421Exception 69 * if there is a problem during the authentication 70 * @throws Reply530Exception 71 * if there is a problem during the authentication 72 * @throws Reply502Exception 73 * if there is a problem during the authentication 74 */ 75 protected abstract NextCommandReply setBusinessAccount(String account) 76 throws Reply421Exception, Reply530Exception, Reply502Exception; 77 78 /** 79 * @param account 80 * the account to set 81 * @return (NOOP,230) if the Account is OK, else return the following 82 * command that must follow and the associated reply 83 * @throws Reply421Exception 84 * if there is a problem during the authentication 85 * @throws Reply530Exception 86 * if there is a problem during the authentication 87 * @throws Reply502Exception 88 */ 89 public NextCommandReply setAccount(String account) 90 throws Reply421Exception, Reply530Exception, Reply502Exception { 91 NextCommandReply next = setBusinessAccount(account); 92 this.account = account; 93 if (next.reply == ReplyCode.REPLY_230_USER_LOGGED_IN) { 94 setRootFromAuth(); 95 session.getDir().initAfterIdentification(); 96 } 97 return next; 98 } 99 100 /** 101 * Set the root relative Path from current status of Authentication (should 102 * be the highest level for the current authentication). If 103 * setBusinessRootFromAuth returns null, by default set /user or 104 * /user/account. 105 * 106 * @exception Reply421Exception 107 * if the business root is not available 108 */ 109 private void setRootFromAuth() throws Reply421Exception { 110 rootFromAuth = setBusinessRootFromAuth(); 111 if (rootFromAuth == null) { 112 if (account == null) { 113 rootFromAuth = FtpDir.SEPARATOR + user; 114 } else { 115 rootFromAuth = FtpDir.SEPARATOR + user + 116 FtpDir.SEPARATOR + account; 117 } 118 } 119 } 120 121 /** 122 * Clean object 123 * 124 */ 125 public void clear() { 126 super.clear(); 127 account = null; 128 } 129 130 @Override 131 public String getBaseDirectory() { 132 return ((FtpSession) getSession()).getConfiguration() 133 .getBaseDirectory(); 134 } 135 }