1 /*
2 * SSHTools - Java SSH2 API
3 *
4 * Copyright (C) 2002-2003 Lee David Painter and Contributors.
5 *
6 * Contributions made by:
7 *
8 * Brett Smith
9 * Richard Pernavas
10 * Erwin Bolwidt
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 */
26 package com.sshtools.daemon.platform;
27
28 import com.sshtools.daemon.configuration;
29
30 import com.sshtools.j2ssh.configuration;
31
32 import org.apache.commons.logging;
33
34 import java.io;
35
36
37 /**
38 *
39 *
40 * @author $author$
41 * @version $Revision: 1.13 $
42 */
43 public abstract class NativeAuthenticationProvider {
44 private static Log log = LogFactory.getLog(NativeAuthenticationProvider.class);
45 private static Class cls;
46 private static NativeAuthenticationProvider instance;
47
48 static {
49 try {
50 if (ConfigurationLoader.isConfigurationAvailable(
51 PlatformConfiguration.class)) {
52 cls = ConfigurationLoader.getExtensionClass(((PlatformConfiguration) ConfigurationLoader.getConfiguration(
53 PlatformConfiguration.class)).getNativeAuthenticationProvider());
54
55 //
56 }
57 } catch (Exception e) {
58 log.error("Failed to load native authentication provider", e);
59 instance = null;
60 }
61 }
62
63 /**
64 *
65 *
66 * @param cls
67 */
68 public static void setProvider(Class cls) {
69 NativeAuthenticationProvider.cls = cls;
70 }
71
72 /**
73 *
74 *
75 * @param username
76 *
77 * @return
78 *
79 * @throws IOException
80 */
81 public abstract String getHomeDirectory(String username)
82 throws IOException;
83
84 /**
85 *
86 *
87 * @param username
88 * @param password
89 *
90 * @return
91 *
92 * @throws PasswordChangeException
93 * @throws IOException
94 */
95 public abstract boolean logonUser(String username, String password)
96 throws PasswordChangeException, IOException;
97
98 /**
99 *
100 *
101 * @param username
102 *
103 * @return
104 *
105 * @throws IOException
106 */
107 public abstract boolean logonUser(String username)
108 throws IOException;
109
110 /**
111 *
112 *
113 * @throws IOException
114 */
115 public abstract void logoffUser() throws IOException;
116
117 /**
118 *
119 *
120 * @param username
121 * @param oldpassword
122 * @param newpassword
123 *
124 * @return
125 */
126 public abstract boolean changePassword(String username, String oldpassword,
127 String newpassword);
128
129 /**
130 *
131 *
132 * @return
133 *
134 * @throws IOException
135 */
136 public static NativeAuthenticationProvider getInstance()
137 throws IOException {
138 if (instance == null) {
139 try {
140 if (cls == null) {
141 throw new IOException(
142 "There is no authentication provider configured");
143 }
144
145 instance = (NativeAuthenticationProvider) cls.newInstance();
146 } catch (Exception e) {
147 throw new IOException(
148 "The authentication provider failed to initialize: " +
149 e.getMessage());
150 }
151 }
152
153 return instance;
154 }
155 }