Commit 8fa0ed01 authored by Daniel Henninger's avatar Daniel Henninger Committed by dhenninger

[GATE-145] Access controls can now be set from web interface.

Cosmetic improvements here and there.  Done with settings interface for now at least!

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk/src/plugins/gateway@6374 b35dd754-fafc-0310-a699-88a17e54d16e
parent b6fc147e
...@@ -41,9 +41,9 @@ public class PermissionManager { ...@@ -41,9 +41,9 @@ public class PermissionManager {
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 = private static final String DELETE_ALL_USERS =
"DELETE FROM gatewayRestrictions WHERE transportType=?"; "DELETE FROM gatewayRestrictions WHERE transportType=? AND username IS NOT NULL";
private static final String DELETE_ALL_GROUPS = private static final String DELETE_ALL_GROUPS =
"DELETE FROM gatewayRestrictions WHERE transportType=?"; "DELETE FROM gatewayRestrictions WHERE transportType=? AND groupname IS NOT NULL";
private static final String ADD_NEW_USER = private static final String ADD_NEW_USER =
"INSERT INTO gatewayRestrictions(transportType,username) VALUES(?,?)"; "INSERT INTO gatewayRestrictions(transportType,username) VALUES(?,?)";
private static final String ADD_NEW_GROUP = private static final String ADD_NEW_GROUP =
...@@ -152,20 +152,19 @@ public class PermissionManager { ...@@ -152,20 +152,19 @@ public class PermissionManager {
Connection con = null; Connection con = null;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
try { try {
Log.warn("clearing users for "+transportType.toString());
con = DbConnectionManager.getConnection(); con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(DELETE_ALL_USERS); pstmt = con.prepareStatement(DELETE_ALL_USERS);
pstmt.setString(1, transportType.toString()); pstmt.setString(1, transportType.toString());
pstmt.executeUpdate(); pstmt.executeUpdate();
pstmt.close();
pstmt = con.prepareStatement(ADD_NEW_USER);
pstmt.setString(1, transportType.toString());
for (User user : users) { for (User user : users) {
Log.warn("saving user "+user.getUsername());
pstmt = con.prepareStatement(ADD_NEW_USER);
pstmt.setString(1, transportType.toString());
pstmt.setString(2, user.getUsername()); pstmt.setString(2, user.getUsername());
pstmt.executeUpdate(); pstmt.executeUpdate();
} }
pstmt.close();
} }
catch (SQLException sqle) { catch (SQLException sqle) {
Log.error(sqle); Log.error(sqle);
...@@ -189,14 +188,15 @@ public class PermissionManager { ...@@ -189,14 +188,15 @@ public class PermissionManager {
pstmt = con.prepareStatement(DELETE_ALL_GROUPS); pstmt = con.prepareStatement(DELETE_ALL_GROUPS);
pstmt.setString(1, transportType.toString()); pstmt.setString(1, transportType.toString());
pstmt.executeUpdate(); pstmt.executeUpdate();
pstmt.close();
pstmt = con.prepareStatement(ADD_NEW_GROUP);
pstmt.setString(1, transportType.toString());
for (Group group : groups) { for (Group group : groups) {
pstmt = con.prepareStatement(ADD_NEW_GROUP);
pstmt.setString(1, transportType.toString());
pstmt.setString(2, group.getName()); pstmt.setString(2, group.getName());
pstmt.executeUpdate(); pstmt.executeUpdate();
} }
pstmt.close();
} }
catch (SQLException sqle) { catch (SQLException sqle) {
Log.error(sqle); Log.error(sqle);
......
...@@ -157,10 +157,11 @@ public class ConfigManager { ...@@ -157,10 +157,11 @@ public class ConfigManager {
if (username.matches("\\s+")) { continue; } if (username.matches("\\s+")) { continue; }
try { try {
User user = userManager.getUser(username); User user = userManager.getUser(username);
if (user == null || user.getUsername() == null) { throw new UserNotFoundException(); }
userList.add(user); userList.add(user);
} }
catch (UserNotFoundException e) { catch (UserNotFoundException e) {
Log.error("User "+username+" not found while adding access rules."); Log.warn("User "+username+" not found while adding access rules.");
} }
} }
permissionManager.storeUserList(userList); permissionManager.storeUserList(userList);
...@@ -171,10 +172,11 @@ public class ConfigManager { ...@@ -171,10 +172,11 @@ public class ConfigManager {
if (grpname.matches("\\s+")) { continue; } if (grpname.matches("\\s+")) { continue; }
try { try {
Group group = groupManager.getGroup(grpname); Group group = groupManager.getGroup(grpname);
if (group == null || group.getName() == null) { throw new GroupNotFoundException(); }
groupList.add(group); groupList.add(group);
} }
catch (GroupNotFoundException e) { catch (GroupNotFoundException e) {
Log.error("Group "+grpname+" not found while adding access rules."); Log.warn("Group "+grpname+" not found while adding access rules.");
} }
} }
permissionManager.storeGroupList(groupList); permissionManager.storeGroupList(groupList);
......
...@@ -313,17 +313,17 @@ ...@@ -313,17 +313,17 @@
<input type="radio" name="<%= this.gatewayType.toString() %>userreg" value="all" onClick="hideSpecificChoices('<%= this.gatewayType.toString() %>')" <%= (this.globalPermSetting == 1 ? "checked='checked'" : "") %> /> All users can register<br> <input type="radio" name="<%= this.gatewayType.toString() %>userreg" value="all" onClick="hideSpecificChoices('<%= this.gatewayType.toString() %>')" <%= (this.globalPermSetting == 1 ? "checked='checked'" : "") %> /> All users can register<br>
<input type="radio" name="<%= this.gatewayType.toString() %>userreg" value="specific" onClick="showSpecificChoices('<%= this.gatewayType.toString() %>')" <%= (this.globalPermSetting == 2 ? "checked='checked'" : "") %> /> These users and/or groups can register<br> <input type="radio" name="<%= this.gatewayType.toString() %>userreg" value="specific" onClick="showSpecificChoices('<%= this.gatewayType.toString() %>')" <%= (this.globalPermSetting == 2 ? "checked='checked'" : "") %> /> These users and/or groups can register<br>
<div id="<%= this.gatewayType.toString() %>userreg_specific" style="<%= (this.globalPermSetting == 2 ? "" : "display: none; ") %>margin: 0; padding: 0; font-size: 80%"> <div id="<%= this.gatewayType.toString() %>userreg_specific" style="<%= (this.globalPermSetting == 2 ? "" : "display: none; ") %>margin: 0; padding: 0; font-size: 80%">
<table border="0" cellpadding="0" cellspacing="0" style="padding-left: 30.0px"> <table border="0" cellpadding="0" cellspacing="0" style="margin-left: 30.0px" width='100%'>
<tr valign="top"> <tr valign="top">
<td align="left"> <td align="left" style="padding-right: 15.0px" width='50%'>
<span style="font-weight: bold">Users</span> <a href="javascript:noop()" onClick="activateModifyUsers('<%= this.gatewayType.toString() %>'); return false">(Modify Users)</a><br /> <span style="font-weight: bold">Users</span> <a href="javascript:noop()" onClick="activateModifyUsers('<%= this.gatewayType.toString() %>'); return false">(Modify Users)</a><br />
<span id="<%= this.gatewayType.toString() %>userpermtext"><%= this.userPermText %></span> <div id="<%= this.gatewayType.toString() %>userpermtextdiv" style="margin: 0px; padding: 0px" class='permissionListDiv'><span id="<%= this.gatewayType.toString() %>userpermtext"><%= this.userPermText %></span></div>
<div id="<%= this.gatewayType.toString() %>userpermentrydiv" style="display:none" class='permissionListDiv'><textarea class='permissionListTextArea' rows="5" cols="20" id="<%= this.gatewayType.toString() %>userpermentry" name="<%= this.gatewayType.toString() %>userpermentry"><%= this.userPermEntry %></textarea></div> <div id="<%= this.gatewayType.toString() %>userpermentrydiv" style="margin: 0px; padding: 0px; display:none" class='permissionListDiv'><textarea style="margin: 0px" class='permissionListTextArea' rows="5" cols="20" id="<%= this.gatewayType.toString() %>userpermentry" name="<%= this.gatewayType.toString() %>userpermentry"><%= this.userPermEntry %></textarea></div>
</td> </td>
<td align="left" style="padding-left: 30.0px"> <td align="left" style="margin-left: 15.0px" width='50%'>
<span style="font-weight: bold">Groups</span> <a href="javascript:noop()" onClick="activateModifyGroups('<%= this.gatewayType.toString() %>'); return false">(Modify Groups)</a><br /> <span style="font-weight: bold">Groups</span> <a href="javascript:noop()" onClick="activateModifyGroups('<%= this.gatewayType.toString() %>'); return false">(Modify Groups)</a><br />
<span id="<%= this.gatewayType.toString() %>grouppermtext"><%= this.groupPermText %></span> <div id="<%= this.gatewayType.toString() %>grouppermtextdiv" style="margin: 0px; padding: 0px" class='permissionListDiv'><span id="<%= this.gatewayType.toString() %>grouppermtext"><%= this.groupPermText %></span></div>
<div id="<%= this.gatewayType.toString() %>grouppermentrydiv" style="display:none" class='permissionListDiv'><textarea class='permissionListTextArea' rows="5" cols="20" id="<%= this.gatewayType.toString() %>grouppermentry" name="<%= this.gatewayType.toString() %>grouppermentry"><%= this.groupPermEntry %></textarea></div> <div id="<%= this.gatewayType.toString() %>grouppermentrydiv" style="margin: 0px; padding: 0px; display:none" class='permissionListDiv'><textarea style="margin: 0px" class='permissionListTextArea' rows="5" cols="20" id="<%= this.gatewayType.toString() %>grouppermentry" name="<%= this.gatewayType.toString() %>grouppermentry"><%= this.groupPermEntry %></textarea></div>
</td> </td>
</tr> </tr>
</table> </table>
...@@ -447,6 +447,10 @@ ...@@ -447,6 +447,10 @@
var userList = userEntry.split(/\s+/); var userList = userEntry.split(/\s+/);
var groupList = groupEntry.split(/\s+/); var groupList = groupEntry.split(/\s+/);
ConfigManager.savePermissions(transportID, globalSetting, userList, groupList); ConfigManager.savePermissions(transportID, globalSetting, userList, groupList);
document.getElementById(transportID+"userpermtext").innerHTML = userList.join(" ");
document.getElementById(transportID+"grouppermtext").innerHTML = groupList.join(" ");
deactivateModifyUsers(transportID);
deactivateModifyGroups(transportID);
document.getElementById(transportID+"permsresults").style.display = ""; document.getElementById(transportID+"permsresults").style.display = "";
document.getElementById(transportID+"permsresults").innerHTML = "<span class='successresults'><img src='images/success-16x16.gif' align='absmiddle' />Permissions Saved!</span>"; document.getElementById(transportID+"permsresults").innerHTML = "<span class='successresults'><img src='images/success-16x16.gif' align='absmiddle' />Permissions Saved!</span>";
setTimeout("to_savePermissions('"+transportID+"')", 5000); setTimeout("to_savePermissions('"+transportID+"')", 5000);
...@@ -465,23 +469,47 @@ ...@@ -465,23 +469,47 @@
} }
function activateModifyUsers(transportID) { function activateModifyUsers(transportID) {
document.getElementById(transportID+"userpermtext").style.display = "none"; var textElem = document.getElementById(transportID+"userpermtextdiv");
document.getElementById(transportID+"userpermentrydiv").style.display = "inline"; var entryElem = document.getElementById(transportID+"userpermentrydiv");
if (textElem.style.display != "none") {
Effect.SlideUp(textElem,{duration: .4});
}
if (entryElem.style.display == "none") {
Effect.SlideDown(entryElem, {duration: .4, delay: .5});
}
} }
function deactivateModifyUsers(transportID) { function deactivateModifyUsers(transportID) {
document.getElementById(transportID+"userpermtext").style.display = "inline"; var textElem = document.getElementById(transportID+"userpermtextdiv");
document.getElementById(transportID+"userpermentrydiv").style.display = "none"; var entryElem = document.getElementById(transportID+"userpermentrydiv");
if (entryElem.style.display != "none") {
Effect.SlideUp(entryElem,{duration: .4});
}
if (textElem.style.display == "none") {
Effect.SlideDown(textElem, {duration: .4, delay: .5});
}
} }
function activateModifyGroups(transportID) { function activateModifyGroups(transportID) {
document.getElementById(transportID+"grouppermtext").style.display = "none"; var textElem = document.getElementById(transportID+"grouppermtextdiv");
document.getElementById(transportID+"grouppermentrydiv").style.display = "inline"; var entryElem = document.getElementById(transportID+"grouppermentrydiv");
if (textElem.style.display != "none") {
Effect.SlideUp(textElem,{duration: .4});
}
if (entryElem.style.display == "none") {
Effect.SlideDown(entryElem, {duration: .4, delay: .5});
}
} }
function deactivateModifyGroups(transportID) { function deactivateModifyGroups(transportID) {
document.getElementById(transportID+"grouppermtext").style.display = "inline"; var textElem = document.getElementById(transportID+"grouppermtextdiv");
document.getElementById(transportID+"grouppermentrydiv").style.display = "none"; var entryElem = document.getElementById(transportID+"grouppermentrydiv");
if (entryElem.style.display != "none") {
Effect.SlideUp(entryElem,{duration: .4});
}
if (textElem.style.display == "none") {
Effect.SlideDown(textElem, {duration: .4, delay: .5});
}
} }
function hideSpecificChoices(transportID) { function hideSpecificChoices(transportID) {
......
...@@ -126,9 +126,9 @@ a.jive-gatewayButtonOn { ...@@ -126,9 +126,9 @@ a.jive-gatewayButtonOn {
margin-bottom: 2px; margin-bottom: 2px;
} }
.saveResultsMsg .warningresults { .saveResultsMsg .warningresults {
border: 1.0px solid #550000; border: 1.0px solid #D9B04C;
background-color: #ffff00; background-color: #FFE9B2;
color: #550000; color: #915a15;
padding: 3.0px; padding: 3.0px;
} }
.saveResultsMsg .warningresults img { .saveResultsMsg .warningresults img {
...@@ -144,6 +144,10 @@ a.jive-gatewayButtonOn { ...@@ -144,6 +144,10 @@ a.jive-gatewayButtonOn {
padding: 0px; padding: 0px;
margin: 0px; margin: 0px;
} }
.permissionListDiv span {
padding: 0px;
margin: 0px;
}
/* ******************************************** */ /* ******************************************** */
......
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