Commit fc109cf4 authored by Daniel Henninger's avatar Daniel Henninger Committed by dhenninger

More exciting web interface work!

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@6362 b35dd754-fafc-0310-a699-88a17e54d16e
parent 4bbabbaf
...@@ -59,6 +59,7 @@ public abstract class BaseTransport implements Component, RosterEventListener { ...@@ -59,6 +59,7 @@ public abstract class BaseTransport implements Component, RosterEventListener {
public void setup(TransportType type, String description) { public void setup(TransportType type, String description) {
this.description = description; this.description = description;
this.transportType = type; this.transportType = type;
permissionManager = new PermissionManager(transportType);
} }
/** /**
...@@ -86,7 +87,7 @@ public abstract class BaseTransport implements Component, RosterEventListener { ...@@ -86,7 +87,7 @@ public abstract class BaseTransport implements Component, RosterEventListener {
* Manages permission information. * Manages permission information.
* @see org.jivesoftware.wildfire.gateway.PermissionManager * @see org.jivesoftware.wildfire.gateway.PermissionManager
*/ */
public final PermissionManager permissionManager = new PermissionManager(); public PermissionManager permissionManager = null;
/** /**
* JID of the transport in question. * JID of the transport in question.
...@@ -601,7 +602,7 @@ public abstract class BaseTransport implements Component, RosterEventListener { ...@@ -601,7 +602,7 @@ public abstract class BaseTransport implements Component, RosterEventListener {
registered = true; registered = true;
} }
if (!registered && !permissionManager.hasAccess(this.transportType, from)) { if (!registered && !permissionManager.hasAccess(from)) {
// User does not have permission to register with transport. // User does not have permission to register with transport.
// We want to allow them to change settings if they are already registered. // We want to allow them to change settings if they are already registered.
IQ result = IQ.createResultIQ(packet); IQ result = IQ.createResultIQ(packet);
...@@ -694,7 +695,7 @@ public abstract class BaseTransport implements Component, RosterEventListener { ...@@ -694,7 +695,7 @@ public abstract class BaseTransport implements Component, RosterEventListener {
registered = true; registered = true;
} }
if (!registered && !permissionManager.hasAccess(this.transportType, from)) { if (!registered && !permissionManager.hasAccess(from)) {
// User does not have permission to register with transport. // User does not have permission to register with transport.
// We want to allow them to change settings if they are already registered. // We want to allow them to change settings if they are already registered.
result.setError(Condition.bad_request); result.setError(Condition.bad_request);
......
...@@ -16,6 +16,7 @@ import org.jivesoftware.util.Log; ...@@ -16,6 +16,7 @@ import org.jivesoftware.util.Log;
import org.jivesoftware.database.DbConnectionManager; import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.wildfire.group.GroupManager; import org.jivesoftware.wildfire.group.GroupManager;
import org.jivesoftware.wildfire.group.Group; import org.jivesoftware.wildfire.group.Group;
import org.jivesoftware.wildfire.user.User;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
...@@ -39,24 +40,60 @@ public class PermissionManager { ...@@ -39,24 +40,60 @@ public class PermissionManager {
"SELECT count(*) FROM gatewayRestrictions WHERE transportType=? AND username=?"; "SELECT count(*) FROM gatewayRestrictions WHERE transportType=? AND username=?";
private static final String GROUPS_LISTED = private static final String GROUPS_LISTED =
"SELECT groupname FROM gatewayRestrictions WHERE transportType=?"; "SELECT groupname FROM gatewayRestrictions WHERE transportType=?";
private static final String DELETE_ALL_USERS =
"DELETE FROM gatewayRestrictions WHERE transportType=?";
private static final String DELETE_ALL_GROUPS =
"DELETE FROM gatewayRestrictions WHERE transportType=?";
private static final String ADD_NEW_USER =
"INSERT INTO gatewayRestrictions(transportType,username) VALUES(?,?)";
private static final String ADD_NEW_GROUP =
"INSERT INTO gatewayRestrictions(transportType,groupname) VALUES(?,?)";
private static final String GET_ALL_USERS =
"SELECT username FROM gatewayRestrictions WHERE transportType=? AND username IS NOT NULL ORDER BY username";
private static final String GET_ALL_GROUPS =
"SELECT groupname FROM gatewayRestrictions WHERE transportType=? AND groupname IS NOT NULL ORDER BY groupname";
public boolean hasAccess(TransportType type, JID jid) { private TransportType transportType = null;
int setting = JiveGlobals.getIntProperty("plugin.gateway."+type.toString()+".registration", 1);
/**
* Create a permissionManager instance.
*
* @param type Type of the transport that this permission manager serves.
*/
public PermissionManager(TransportType type) {
this.transportType = type;
}
/**
* Checks if a user has access to the transport, via a number of methods.
*
* @param jid JID of the user who may or may not have access.
* @return True or false if the user has access.
*/
public boolean hasAccess(JID jid) {
int setting = JiveGlobals.getIntProperty("plugin.gateway."+transportType.toString()+".registration", 1);
if (setting == 1) { return true; } if (setting == 1) { return true; }
if (setting == 3) { return false; } if (setting == 3) { return false; }
if (isUserAllowed(type, jid)) { return true; } if (isUserAllowed(jid)) { return true; }
if (isUserInAllowedGroup(type, jid)) { return true; } if (isUserInAllowedGroup(jid)) { return true; }
return false; return false;
} }
public boolean isUserAllowed(TransportType type, JID jid) { /**
* Checks if a user has specific access to the transport.
*
* @param jid JID of the user who may or may not have access.
* @return True or false of the user has access.
*/
public boolean isUserAllowed(JID jid) {
Connection con = null; Connection con = null;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null; ResultSet rs = null;
try { try {
con = DbConnectionManager.getConnection(); con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(IS_USER_LISTED); pstmt = con.prepareStatement(IS_USER_LISTED);
pstmt.setString(1, type.toString()); pstmt.setString(1, transportType.toString());
pstmt.setString(2, jid.getNode()); pstmt.setString(2, jid.getNode());
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
rs.next(); rs.next();
...@@ -71,7 +108,13 @@ public class PermissionManager { ...@@ -71,7 +108,13 @@ public class PermissionManager {
return false; return false;
} }
public boolean isUserInAllowedGroup(TransportType type, JID jid) { /**
* Checks if a user is in a group that has access to the transport.
*
* @param jid JID of the user who may or may not have access.
* @return True or false of the user is in a group that has access.
*/
public boolean isUserInAllowedGroup(JID jid) {
ArrayList<String> allowedGroups = new ArrayList<String>(); ArrayList<String> allowedGroups = new ArrayList<String>();
Connection con = null; Connection con = null;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
...@@ -79,7 +122,7 @@ public class PermissionManager { ...@@ -79,7 +122,7 @@ public class PermissionManager {
try { try {
con = DbConnectionManager.getConnection(); con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(GROUPS_LISTED); pstmt = con.prepareStatement(GROUPS_LISTED);
pstmt.setString(1, type.toString()); pstmt.setString(1, transportType.toString());
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while (rs.next()) { while (rs.next()) {
allowedGroups.add(rs.getString(1)); allowedGroups.add(rs.getString(1));
...@@ -100,4 +143,121 @@ public class PermissionManager { ...@@ -100,4 +143,121 @@ public class PermissionManager {
return false; return false;
} }
/**
* Stores a list of users as having access to the transport in question.
*
* @param users list of users who should have access.
*/
public void storeUserList(ArrayList<User> users) {
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(DELETE_ALL_USERS);
pstmt.setString(1, transportType.toString());
pstmt.executeUpdate();
for (User user : users) {
pstmt = con.prepareStatement(ADD_NEW_USER);
pstmt.setString(1, transportType.toString());
pstmt.setString(2, user.getUsername());
pstmt.executeUpdate();
}
}
catch (SQLException sqle) {
Log.error(sqle);
}
finally {
DbConnectionManager.closeConnection(pstmt, con);
}
}
/**
* Stores a list of groups as having access to the transport in question.
*
* @param groups list of groups who should have access.
*/
public void storeGroupList(ArrayList<Group> groups) {
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(DELETE_ALL_GROUPS);
pstmt.setString(1, transportType.toString());
pstmt.executeUpdate();
for (Group group : groups) {
pstmt = con.prepareStatement(ADD_NEW_GROUP);
pstmt.setString(1, transportType.toString());
pstmt.setString(2, group.getName());
pstmt.executeUpdate();
}
}
catch (SQLException sqle) {
Log.error(sqle);
}
finally {
DbConnectionManager.closeConnection(pstmt, con);
}
}
/**
* Retrieves a list of all of the users permitted to access this transport.
*
* @return List of users (as strings)
*/
public ArrayList<String> getAllUsers() {
ArrayList<String> userList = new ArrayList<String>();
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(GET_ALL_USERS);
pstmt.setString(1, transportType.toString());
rs = pstmt.executeQuery();
while (rs.next()) {
userList.add(rs.getString(1));
}
}
catch (SQLException sqle) {
Log.error(sqle);
}
finally {
DbConnectionManager.closeConnection(rs, pstmt, con);
}
return userList;
}
/**
* Retrieves a list of all of the groups permitted to access this transport.
*
* @return List of groups (as strings)
*/
public ArrayList<String> getAllGroups() {
ArrayList<String> groupList = new ArrayList<String>();
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(GET_ALL_GROUPS);
pstmt.setString(1, transportType.toString());
rs = pstmt.executeQuery();
while (rs.next()) {
groupList.add(rs.getString(1));
}
}
catch (SQLException sqle) {
Log.error(sqle);
}
finally {
DbConnectionManager.closeConnection(rs, pstmt, con);
}
return groupList;
}
} }
...@@ -11,8 +11,15 @@ package org.jivesoftware.wildfire.gateway.web; ...@@ -11,8 +11,15 @@ package org.jivesoftware.wildfire.gateway.web;
import org.jivesoftware.wildfire.container.PluginManager; import org.jivesoftware.wildfire.container.PluginManager;
import org.jivesoftware.wildfire.XMPPServer; import org.jivesoftware.wildfire.XMPPServer;
import org.jivesoftware.wildfire.user.UserManager;
import org.jivesoftware.wildfire.user.UserNotFoundException;
import org.jivesoftware.wildfire.user.User;
import org.jivesoftware.wildfire.group.Group;
import org.jivesoftware.wildfire.group.GroupManager;
import org.jivesoftware.wildfire.group.GroupNotFoundException;
import org.jivesoftware.wildfire.gateway.GatewayPlugin; import org.jivesoftware.wildfire.gateway.GatewayPlugin;
import org.jivesoftware.wildfire.gateway.TransportType; import org.jivesoftware.wildfire.gateway.TransportType;
import org.jivesoftware.wildfire.gateway.PermissionManager;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.util.JiveGlobals;
import org.dom4j.Document; import org.dom4j.Document;
...@@ -20,6 +27,7 @@ import org.dom4j.Element; ...@@ -20,6 +27,7 @@ import org.dom4j.Element;
import org.dom4j.Attribute; import org.dom4j.Attribute;
import java.util.HashMap; import java.util.HashMap;
import java.util.ArrayList;
/** /**
* Transport Configuration Manager (for web interface) * Transport Configuration Manager (for web interface)
...@@ -129,4 +137,43 @@ public class ConfigManager { ...@@ -129,4 +137,43 @@ public class ConfigManager {
} }
} }
/**
* Saves permissions settings from web interface.
*
* We validate all of the groups before actually adding them.
*
* @param transportName Name of the transport to have it's options saved (type of transport)
* @param overallSetting The general "all(1), some(2), or none(3)" setting for the permissions.
* @param users List of specific users that have access.
* @param groups List of specific groups that have access.
*/
public void savePermissions(String transportName, Integer overallSetting, ArrayList<String> users, ArrayList<String> groups) {
JiveGlobals.setProperty("plugin.gateway."+transportName+".registration", overallSetting.toString());
PermissionManager permissionManager = new PermissionManager(TransportType.valueOf(transportName));
ArrayList<User> userList = new ArrayList<User>();
UserManager userManager = UserManager.getInstance();
for (String username : users) {
try {
User user = userManager.getUser(username);
userList.add(user);
}
catch (UserNotFoundException e) {
Log.error("User "+username+" not found while adding access rules.");
}
}
permissionManager.storeUserList(userList);
ArrayList<Group> groupList = new ArrayList<Group>();
GroupManager groupManager = GroupManager.getInstance();
for (String grpname : groups) {
try {
Group group = groupManager.getGroup(grpname);
groupList.add(group);
}
catch (GroupNotFoundException e) {
Log.error("Group "+grpname+" not found while adding access rules.");
}
}
permissionManager.storeGroupList(groupList);
}
} }
...@@ -18,9 +18,9 @@ function togglePanel(thisID) { ...@@ -18,9 +18,9 @@ function togglePanel(thisID) {
Effect.toggle($(thisID),'slide', {duration: .4}); Effect.toggle($(thisID),'slide', {duration: .4});
$(activeLink).className = ""; $(activeLink).className = "";
} else if ($(thisID).style.display == 'none' && $(lastID).style.display != 'none') { } else if ($(thisID).style.display == 'none' && $(lastID).style.display != 'none') {
$(lastID).style.display = 'none'; Effect.toggle($(lastID),'slide', {duration: .4});
$(thisID).style.display = 'block'; $(oldLink).className = "";
$(oldLink).className = ""; Effect.toggle($(thisID),'slide', {duration: .4, delay: .5});
$(activeLink).className = "jive-gatewayButtonOn"; $(activeLink).className = "jive-gatewayButtonOn";
} else { } else {
Effect.toggle($(thisID),'slide', {duration: .4}); Effect.toggle($(thisID),'slide', {duration: .4});
......
...@@ -125,8 +125,19 @@ a.jive-gatewayButtonOn { ...@@ -125,8 +125,19 @@ a.jive-gatewayButtonOn {
margin-right: 3px; margin-right: 3px;
margin-bottom: 2px; margin-bottom: 2px;
} }
.saveResultsMsg .warningresults {
border: 1.0px solid #550000;
background-color: #ffff00;
color: #550000;
padding: 3.0px;
}
.saveResultsMsg .warningresults img {
margin-right: 3px;
margin-bottom: 2px;
}
.permissionListTextArea {
font-size: 70%;
}
/* ******************************************** */ /* ******************************************** */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment