001: /*
002: * SSHTools - Java SSH2 API
003: *
004: * Copyright (C) 2002-2003 Lee David Painter and Contributors.
005: *
006: * Contributions made by:
007: *
008: * Brett Smith
009: * Richard Pernavas
010: * Erwin Bolwidt
011: *
012: * This program is free software; you can redistribute it and/or
013: * modify it under the terms of the GNU General Public License
014: * as published by the Free Software Foundation; either version 2
015: * of the License, or (at your option) any later version.
016: *
017: * This program is distributed in the hope that it will be useful,
018: * but WITHOUT ANY WARRANTY; without even the implied warranty of
019: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
020: * GNU General Public License for more details.
021: *
022: * You should have received a copy of the GNU General Public License
023: * along with this program; if not, write to the Free Software
024: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
025: */
026: package com.sshtools.daemon.platform;
027:
028: import com.sshtools.daemon.configuration.*;
029:
030: import com.sshtools.j2ssh.configuration.*;
031:
032: import org.apache.commons.logging.*;
033:
034: import java.io.*;
035:
036: /**
037: *
038: *
039: * @author $author$
040: * @version $Revision: 1.13 $
041: */
042: public abstract class NativeAuthenticationProvider {
043: private static Log log = LogFactory
044: .getLog(NativeAuthenticationProvider.class);
045: private static Class cls;
046: private static NativeAuthenticationProvider instance;
047:
048: static {
049: try {
050: if (ConfigurationLoader
051: .isConfigurationAvailable(PlatformConfiguration.class)) {
052: cls = ConfigurationLoader
053: .getExtensionClass(((PlatformConfiguration) ConfigurationLoader
054: .getConfiguration(PlatformConfiguration.class))
055: .getNativeAuthenticationProvider());
056:
057: //
058: }
059: } catch (Exception e) {
060: log.error("Failed to load native authentication provider",
061: e);
062: instance = null;
063: }
064: }
065:
066: /**
067: *
068: *
069: * @param cls
070: */
071: public static void setProvider(Class cls) {
072: NativeAuthenticationProvider.cls = cls;
073: }
074:
075: /**
076: *
077: *
078: * @param username
079: *
080: * @return
081: *
082: * @throws IOException
083: */
084: public abstract String getHomeDirectory(String username)
085: throws IOException;
086:
087: /**
088: *
089: *
090: * @param username
091: * @param password
092: *
093: * @return
094: *
095: * @throws PasswordChangeException
096: * @throws IOException
097: */
098: public abstract boolean logonUser(String username, String password)
099: throws PasswordChangeException, IOException;
100:
101: /**
102: *
103: *
104: * @param username
105: *
106: * @return
107: *
108: * @throws IOException
109: */
110: public abstract boolean logonUser(String username)
111: throws IOException;
112:
113: /**
114: *
115: *
116: * @throws IOException
117: */
118: public abstract void logoffUser() throws IOException;
119:
120: /**
121: *
122: *
123: * @param username
124: * @param oldpassword
125: * @param newpassword
126: *
127: * @return
128: */
129: public abstract boolean changePassword(String username,
130: String oldpassword, String newpassword);
131:
132: /**
133: *
134: *
135: * @return
136: *
137: * @throws IOException
138: */
139: public static NativeAuthenticationProvider getInstance()
140: throws IOException {
141: if (instance == null) {
142: try {
143: if (cls == null) {
144: throw new IOException(
145: "There is no authentication provider configured");
146: }
147:
148: instance = (NativeAuthenticationProvider) cls
149: .newInstance();
150: } catch (Exception e) {
151: throw new IOException(
152: "The authentication provider failed to initialize: "
153: + e.getMessage());
154: }
155: }
156:
157: return instance;
158: }
159: }
|