Commit dfa3ad35 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

1) Removed NotLockedOutException and return null if no lock info was found

2) Added printing of exceptions when an error occurs

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@10172 b35dd754-fafc-0310-a699-88a17e54d16e
parent c2d2a7a0
...@@ -9,19 +9,17 @@ ...@@ -9,19 +9,17 @@
*/ */
package org.jivesoftware.openfire.clearspace; package org.jivesoftware.openfire.clearspace;
import org.jivesoftware.openfire.lockout.LockOutProvider; import org.dom4j.Document;
import org.jivesoftware.openfire.lockout.LockOutFlag; import org.dom4j.DocumentHelper;
import org.jivesoftware.openfire.lockout.NotLockedOutException; import org.dom4j.Element;
import org.jivesoftware.openfire.user.UserNotFoundException; import org.dom4j.Node;
import static org.jivesoftware.openfire.clearspace.ClearspaceManager.HttpType.GET; import static org.jivesoftware.openfire.clearspace.ClearspaceManager.HttpType.GET;
import static org.jivesoftware.openfire.clearspace.ClearspaceManager.HttpType.PUT; import static org.jivesoftware.openfire.clearspace.ClearspaceManager.HttpType.PUT;
import org.jivesoftware.openfire.lockout.LockOutFlag;
import org.jivesoftware.openfire.lockout.LockOutProvider;
import org.jivesoftware.openfire.user.UserNotFoundException;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.dom4j.Node;
import org.dom4j.Element;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import java.util.List; import java.util.List;
/** /**
...@@ -46,13 +44,14 @@ public class ClearspaceLockOutProvider implements LockOutProvider { ...@@ -46,13 +44,14 @@ public class ClearspaceLockOutProvider implements LockOutProvider {
* The ClearspaceLockOutProvider will retrieve lockout information from Clearspace's user properties. * The ClearspaceLockOutProvider will retrieve lockout information from Clearspace's user properties.
* @see org.jivesoftware.openfire.lockout.LockOutProvider#getDisabledStatus(String) * @see org.jivesoftware.openfire.lockout.LockOutProvider#getDisabledStatus(String)
*/ */
public LockOutFlag getDisabledStatus(String username) throws NotLockedOutException { public LockOutFlag getDisabledStatus(String username) {
try { try {
// Retrieve the disabled status, translate it into a LockOutFlag, and return it. // Retrieve the disabled status, translate it into a LockOutFlag, and return it.
return checkUserDisabled(getUserByUsername(username)); return checkUserDisabled(getUserByUsername(username));
} }
catch (UserNotFoundException e) { catch (UserNotFoundException e) {
// Not a valid user? We will leave it up to the user provider to handle rejecting this user. // Not a valid user? We will leave it up to the user provider to handle rejecting this user.
Log.warn(e);
return null; return null;
} }
} }
...@@ -155,14 +154,13 @@ public class ClearspaceLockOutProvider implements LockOutProvider { ...@@ -155,14 +154,13 @@ public class ClearspaceLockOutProvider implements LockOutProvider {
} }
/** /**
* Examines the XML returned about a user to find out if they are enabled or disabled, throwing * Examines the XML returned about a user to find out if they are enabled or disabled. Returns
* a NotLockedOutException if they are. * <tt>null</tt> when user can log in or a LockOutFlag if user cannot log in.
* *
* @param responseNode Element returned from REST service. (@see #getUserByUsername) * @param responseNode Element returned from REST service. (@see #getUserByUsername)
* @return Either a LockOutFlag indicating that the user is disabled, or an exception is thrown. * @return Either a LockOutFlag indicating that the user is disabled, or null if everything is fine.
* @throws NotLockedOutException if the user is not currently locked out.
*/ */
private LockOutFlag checkUserDisabled(Node responseNode) throws NotLockedOutException { private LockOutFlag checkUserDisabled(Node responseNode) {
try { try {
Node userNode = responseNode.selectSingleNode("return"); Node userNode = responseNode.selectSingleNode("return");
...@@ -173,20 +171,17 @@ public class ClearspaceLockOutProvider implements LockOutProvider { ...@@ -173,20 +171,17 @@ public class ClearspaceLockOutProvider implements LockOutProvider {
boolean isEnabled = Boolean.valueOf(userNode.selectSingleNode("enabled").getText()); boolean isEnabled = Boolean.valueOf(userNode.selectSingleNode("enabled").getText());
if (isEnabled) { if (isEnabled) {
// We're good, indicate that they're not locked out. // We're good, indicate that they're not locked out.
throw new NotLockedOutException(); return null;
} }
else { else {
// Creates the lock out flag // Creates the lock out flag
return new LockOutFlag(username, null, null); return new LockOutFlag(username, null, null);
} }
} }
catch (NotLockedOutException e) {
throw e;
}
catch (Exception e) { catch (Exception e) {
// Hrm. This is not good. We have to opt on the side of positive. // Hrm. This is not good. We have to opt on the side of positive.
Log.error("Error while looking up user's disabled status from Clearspace: ", e); Log.error("Error while looking up user's disabled status from Clearspace: ", e);
throw new NotLockedOutException(); return null;
} }
} }
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
package org.jivesoftware.openfire.lockout; package org.jivesoftware.openfire.lockout;
import org.jivesoftware.database.DbConnectionManager; import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.StringUtils; import org.jivesoftware.util.StringUtils;
import java.sql.*; import java.sql.*;
...@@ -42,7 +43,7 @@ public class DefaultLockOutProvider implements LockOutProvider { ...@@ -42,7 +43,7 @@ public class DefaultLockOutProvider implements LockOutProvider {
* Default provider retrieves disabled status from ofUserFlag table. * Default provider retrieves disabled status from ofUserFlag table.
* @see org.jivesoftware.openfire.lockout.LockOutProvider#getDisabledStatus(String) * @see org.jivesoftware.openfire.lockout.LockOutProvider#getDisabledStatus(String)
*/ */
public LockOutFlag getDisabledStatus(String username) throws NotLockedOutException { public LockOutFlag getDisabledStatus(String username) {
Connection con = null; Connection con = null;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null; ResultSet rs = null;
...@@ -53,7 +54,7 @@ public class DefaultLockOutProvider implements LockOutProvider { ...@@ -53,7 +54,7 @@ public class DefaultLockOutProvider implements LockOutProvider {
pstmt.setString(1, username); pstmt.setString(1, username);
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if (!rs.next()) { if (!rs.next()) {
throw new NotLockedOutException(); return null;
} }
Date startTime = null; Date startTime = null;
if (rs.getString(2) != null) { if (rs.getString(2) != null) {
...@@ -67,7 +68,8 @@ public class DefaultLockOutProvider implements LockOutProvider { ...@@ -67,7 +68,8 @@ public class DefaultLockOutProvider implements LockOutProvider {
ret = new LockOutFlag(username, startTime, endTime); ret = new LockOutFlag(username, startTime, endTime);
} }
catch (Exception e) { catch (Exception e) {
throw new NotLockedOutException(); Log.error("Error loading lockout information from DB", e);
return null;
} }
finally { finally {
DbConnectionManager.closeConnection(rs, pstmt, con); DbConnectionManager.closeConnection(rs, pstmt, con);
......
...@@ -13,8 +13,8 @@ import org.jivesoftware.util.*; ...@@ -13,8 +13,8 @@ import org.jivesoftware.util.*;
import org.jivesoftware.util.cache.Cache; import org.jivesoftware.util.cache.Cache;
import org.jivesoftware.util.cache.CacheFactory; import org.jivesoftware.util.cache.CacheFactory;
import java.util.Map;
import java.util.Date; import java.util.Date;
import java.util.Map;
/** /**
* The LockOutManager manages the LockOutProvider configured for this server, caches knowledge of * The LockOutManager manages the LockOutProvider configured for this server, caches knowledge of
...@@ -122,10 +122,10 @@ public class LockOutManager { ...@@ -122,10 +122,10 @@ public class LockOutManager {
* period that the specified account is going to be disabled. * period that the specified account is going to be disabled.
* *
* @param username Username of account to request status of. * @param username Username of account to request status of.
* @return The LockOutFlag instance describing the accounts disabled status. * @return The LockOutFlag instance describing the accounts disabled status or null if user
* @throws NotLockedOutException if user account specified is not currently locked out (disabled). * account specified is not currently locked out (disabled).
*/ */
public LockOutFlag getDisabledStatus(String username) throws NotLockedOutException { public LockOutFlag getDisabledStatus(String username) {
if (username == null) { if (username == null) {
throw new UnsupportedOperationException("Null username not allowed!"); throw new UnsupportedOperationException("Null username not allowed!");
} }
...@@ -154,23 +154,18 @@ public class LockOutManager { ...@@ -154,23 +154,18 @@ public class LockOutManager {
* @return True or false if the account is currently locked out. * @return True or false if the account is currently locked out.
*/ */
public boolean isAccountDisabled(String username) { public boolean isAccountDisabled(String username) {
try { LockOutFlag flag = getDisabledStatus(username);
LockOutFlag flag = getDisabledStatus(username); if (flag == null) {
if (flag == null) { return false;
return false; }
} Date curDate = new Date();
Date curDate = new Date(); if (flag.getStartTime() != null && curDate.before(flag.getStartTime())) {
if (flag.getStartTime() != null && curDate.before(flag.getStartTime())) { return false;
return false;
}
if (flag.getEndTime() != null && curDate.after(flag.getEndTime())) {
return false;
}
return true;
} }
catch (NotLockedOutException e) { if (flag.getEndTime() != null && curDate.after(flag.getEndTime())) {
return false; return false;
} }
return true;
} }
/** /**
......
...@@ -20,13 +20,14 @@ public interface LockOutProvider { ...@@ -20,13 +20,14 @@ public interface LockOutProvider {
/** /**
* Returns a LockOutFlag for a given username, which contains information about the time * Returns a LockOutFlag for a given username, which contains information about the time
* period that the specified account is going to be disabled. * period that the specified account is going to be disabled or null if user can log in
* just fine.
* *
* @param username Username of account to request status of. * @param username Username of account to request status of.
* @return The LockOutFlag instance describing the accounts disabled status. * @return The LockOutFlag instance describing the accounts disabled status or null if user
* @throws NotLockedOutException if user account specified is not currently locked out (disabled). * account specified is not currently locked out (disabled).
*/ */
public LockOutFlag getDisabledStatus(String username) throws NotLockedOutException; public LockOutFlag getDisabledStatus(String username);
/** /**
* Sets the locked out (disabled) status of an account according to a LockOutFlag. * Sets the locked out (disabled) status of an account according to a LockOutFlag.
......
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright (C) 2008 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.openfire.lockout;
/**
* Thrown if a username is queried for lockout status that is not locked out.
*
* @author Daniel Henninger
*/
public class NotLockedOutException extends Exception {
public NotLockedOutException() {
super();
}
public NotLockedOutException(String message) {
super(message);
}
public NotLockedOutException(Throwable cause) {
super(cause);
}
public NotLockedOutException(String message, Throwable cause) {
super(message, cause);
}
}
\ No newline at end of file
...@@ -8,18 +8,17 @@ ...@@ -8,18 +8,17 @@
- a copy of which is included in this distribution. - a copy of which is included in this distribution.
--%> --%>
<%@ page import="org.jivesoftware.openfire.session.ClientSession" <%@ page import="org.jivesoftware.openfire.lockout.LockOutFlag"
errorPage="error.jsp" errorPage="error.jsp"
%> %>
<%@ page import="org.jivesoftware.openfire.lockout.LockOutManager" %>
<%@ page import="org.jivesoftware.openfire.security.SecurityAuditManager" %>
<%@ page import="org.jivesoftware.openfire.session.ClientSession" %>
<%@ page import="org.jivesoftware.util.ParamUtils" %> <%@ page import="org.jivesoftware.util.ParamUtils" %>
<%@ page import="org.xmpp.packet.JID" %> <%@ page import="org.xmpp.packet.JID" %>
<%@ page import="org.xmpp.packet.StreamError" %> <%@ page import="org.xmpp.packet.StreamError" %>
<%@ page import="java.net.URLEncoder" %> <%@ page import="java.net.URLEncoder" %>
<%@ page import="java.util.Date" %> <%@ page import="java.util.Date" %>
<%@ page import="org.jivesoftware.openfire.lockout.LockOutManager" %>
<%@ page import="org.jivesoftware.openfire.lockout.LockOutFlag" %>
<%@ page import="org.jivesoftware.openfire.lockout.NotLockedOutException" %>
<%@ page import="org.jivesoftware.openfire.security.SecurityAuditManager" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %> <%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %> <%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>
...@@ -118,8 +117,9 @@ ...@@ -118,8 +117,9 @@
<% } %> <% } %>
<% <%
try { LockOutFlag flag = LockOutManager.getInstance().getDisabledStatus(username);
LockOutFlag flag = LockOutManager.getInstance().getDisabledStatus(username); if (flag != null) {
// User is locked out
%> %>
<p> <p>
...@@ -139,7 +139,8 @@ ...@@ -139,7 +139,8 @@
<% <%
} }
catch (NotLockedOutException e) { else {
// User is not locked out
%> %>
<p> <p>
......
...@@ -8,21 +8,20 @@ ...@@ -8,21 +8,20 @@
- a copy of which is included in this distribution. - a copy of which is included in this distribution.
--%> --%>
<%@ page import="org.jivesoftware.util.JiveGlobals, <%@ page import="org.jivesoftware.openfire.PresenceManager,
org.jivesoftware.util.ParamUtils, org.jivesoftware.openfire.admin.AdminManager,
org.jivesoftware.openfire.PresenceManager,
org.jivesoftware.openfire.group.Group, org.jivesoftware.openfire.group.Group,
org.jivesoftware.openfire.user.User, org.jivesoftware.openfire.user.User,
org.jivesoftware.openfire.user.UserManager,
org.jivesoftware.openfire.user.UserNotFoundException" org.jivesoftware.openfire.user.UserNotFoundException"
errorPage="error.jsp" errorPage="error.jsp"
%> %>
<%@ page import="org.xmpp.packet.Presence"%> <%@ page import="org.jivesoftware.util.JiveGlobals"%>
<%@ page import="java.net.URLEncoder"%> <%@ page import="org.jivesoftware.util.LocaleUtils"%>
<%@ page import="java.util.Collection"%> <%@ page import="org.jivesoftware.util.ParamUtils"%>
<%@ page import="org.jivesoftware.openfire.user.UserManager"%><%@ page import="org.xmpp.packet.JID"%> <%@ page import="org.xmpp.packet.JID"%><%@ page import="org.xmpp.packet.Presence"%>
<%@ page import="org.jivesoftware.openfire.lockout.NotLockedOutException" %> <%@ page import="java.net.URLEncoder" %>
<%@ page import="org.jivesoftware.openfire.admin.AdminManager" %> <%@ page import="java.util.Collection" %>
<%@ page import="org.jivesoftware.util.LocaleUtils" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %> <%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %> <%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>
...@@ -63,8 +62,8 @@ ...@@ -63,8 +62,8 @@
PresenceManager presenceManager = webManager.getPresenceManager(); PresenceManager presenceManager = webManager.getPresenceManager();
Boolean lockedOut = false; Boolean lockedOut = false;
Boolean pendingLockOut = false; Boolean pendingLockOut = false;
try { if (webManager.getLockOutManager().getDisabledStatus(username) != null) {
webManager.getLockOutManager().getDisabledStatus(username); // User is locked out. Check if he is locket out now
if (webManager.getLockOutManager().isAccountDisabled(username)) { if (webManager.getLockOutManager().isAccountDisabled(username)) {
lockedOut = true; lockedOut = true;
} }
...@@ -72,9 +71,6 @@ ...@@ -72,9 +71,6 @@
pendingLockOut = true; pendingLockOut = true;
} }
} }
catch (NotLockedOutException e) {
// Nothing, we're good.
}
%> %>
<html> <html>
......
...@@ -9,19 +9,18 @@ ...@@ -9,19 +9,18 @@
- a copy of which is included in this distribution. - a copy of which is included in this distribution.
--%> --%>
<%@ page import="org.jivesoftware.util.JiveGlobals, <%@ page import="org.jivesoftware.openfire.PresenceManager,
org.jivesoftware.util.LocaleUtils, org.jivesoftware.openfire.admin.AdminManager,
org.jivesoftware.util.ParamUtils,
org.jivesoftware.util.StringUtils,
org.jivesoftware.openfire.PresenceManager,
org.jivesoftware.openfire.user.User, org.jivesoftware.openfire.user.User,
org.jivesoftware.openfire.user.UserManager" org.jivesoftware.openfire.user.UserManager,
%><%@ page import="org.xmpp.packet.JID"%> org.jivesoftware.util.JiveGlobals,
org.jivesoftware.util.LocaleUtils,
org.jivesoftware.util.ParamUtils"
%><%@ page import="org.jivesoftware.util.StringUtils"%>
<%@ page import="org.xmpp.packet.JID" %>
<%@ page import="org.xmpp.packet.Presence" %> <%@ page import="org.xmpp.packet.Presence" %>
<%@ page import="java.net.URLEncoder" %> <%@ page import="java.net.URLEncoder" %>
<%@ page import="java.util.Collection" %> <%@ page import="java.util.Collection" %>
<%@ page import="org.jivesoftware.openfire.lockout.NotLockedOutException" %>
<%@ page import="org.jivesoftware.openfire.admin.AdminManager" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %> <%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %> <%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>
...@@ -180,8 +179,8 @@ ...@@ -180,8 +179,8 @@
i++; i++;
Boolean lockedOut = false; Boolean lockedOut = false;
Boolean pendingLockOut = false; Boolean pendingLockOut = false;
try { if (webManager.getLockOutManager().getDisabledStatus(user.getUsername()) != null) {
webManager.getLockOutManager().getDisabledStatus(user.getUsername()); // User is locked out. Check if its locked out now!
if (webManager.getLockOutManager().isAccountDisabled(user.getUsername())) { if (webManager.getLockOutManager().isAccountDisabled(user.getUsername())) {
lockedOut = true; lockedOut = true;
} }
...@@ -189,9 +188,6 @@ ...@@ -189,9 +188,6 @@
pendingLockOut = true; pendingLockOut = true;
} }
} }
catch (NotLockedOutException e) {
// Nothing, we're good.
}
Boolean isAdmin = AdminManager.getInstance().isUserAdmin(user.getUsername(), false); Boolean isAdmin = AdminManager.getInstance().isUserAdmin(user.getUsername(), false);
%> %>
<tr class="jive-<%= (((i%2)==0) ? "even" : "odd") %>"> <tr class="jive-<%= (((i%2)==0) ? "even" : "odd") %>">
......
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