use of com.biglybt.ui.console.UserProfile in project BiglyBT by BiglySoftware.
the class SocketServer method login.
/**
* if usermanager is null (ie: multi user is not enabled), returns the default user profile
* otherwise, requests username and password and authenticates user before returning
* the user profile for this user
* @param in input stream to read from
* @param out stream to write messages to
* @return username if login was successful, null otherwise
* @throws IOException
*/
private UserProfile login(InputStream in, OutputStream out) throws IOException {
if (userManager == null)
return UserProfile.DEFAULT_USER_PROFILE;
PrintStream ps = new PrintStream(out);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
ps.print("Username: ");
String username = br.readLine();
ps.print("Password: ");
String password = br.readLine();
UserProfile userProfile = userManager.authenticate(username, password);
if (userProfile != null) {
ps.println("Login successful");
return userProfile;
}
ps.println("Login failed");
return null;
}
use of com.biglybt.ui.console.UserProfile in project BiglyBT by BiglySoftware.
the class SocketServer method run.
/**
* start up the server socket and when a new connection is received, check that
* the source address is in our permitted list and if so, start a new console input
* on that socket.
*/
@Override
public void run() {
int threadNum = 1;
System.out.println("Telnet server started. Listening on port: " + serverSocket.getLocalPort());
while (true) {
try {
Socket socket = serverSocket.accept();
InetSocketAddress addr = (InetSocketAddress) socket.getRemoteSocketAddress();
if (addr.isUnresolved() || !isAllowed(addr)) {
System.out.println("TelnetUI: rejecting connection from: " + addr + " as address is not allowed");
socket.close();
} else {
System.out.println("TelnetUI: accepting connection from: " + addr);
int loginAttempts = 0;
while (true) {
// TODO: might want to put this in another thread so the port doesnt block while the user logs in
// System.out.println("TelnetUI: starting login" );
UserProfile profile = login(socket.getInputStream(), socket.getOutputStream());
if (profile != null) {
// System.out.println("TelnetUI: creating console input" );
ui.createNewConsoleInput("Telnet Console " + threadNum++, socket.getInputStream(), new PrintStream(socket.getOutputStream()), profile);
break;
}
// System.out.println("TelnetUI: failed to obtain login profile" );
loginAttempts++;
if (loginAttempts >= maxLoginAttempts) {
System.out.println("TelnetUI: rejecting connection from: " + addr + " as number of failed connections > max login attempts (" + maxLoginAttempts + ")");
socket.close();
break;
}
}
}
} catch (Throwable t) {
t.printStackTrace();
break;
}
}
}
use of com.biglybt.ui.console.UserProfile in project BiglyBT by BiglySoftware.
the class UserManagerXMLPersist method doLoad.
@Override
public void doLoad(InputStream in, Map usersMap) {
XMLDecoder decoder = new XMLDecoder(in);
UserManagerConfig managerConfig = (UserManagerConfig) decoder.readObject();
for (Iterator iter = managerConfig.getUsers().iterator(); iter.hasNext(); ) {
UserProfile user = (UserProfile) iter.next();
usersMap.put(user.getUsername().toLowerCase(), user);
}
System.out.println("UserManager: registered " + usersMap.size() + " users");
decoder.close();
}
Aggregations