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 @@
*/
package org.jivesoftware.openfire.clearspace;
import org.jivesoftware.openfire.lockout.LockOutProvider;
import org.jivesoftware.openfire.lockout.LockOutFlag;
import org.jivesoftware.openfire.lockout.NotLockedOutException;
import org.jivesoftware.openfire.user.UserNotFoundException;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.Node;
import static org.jivesoftware.openfire.clearspace.ClearspaceManager.HttpType.GET;
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.dom4j.Node;
import org.dom4j.Element;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import java.util.List;
/**
......@@ -46,13 +44,14 @@ public class ClearspaceLockOutProvider implements LockOutProvider {
* The ClearspaceLockOutProvider will retrieve lockout information from Clearspace's user properties.
* @see org.jivesoftware.openfire.lockout.LockOutProvider#getDisabledStatus(String)
*/
public LockOutFlag getDisabledStatus(String username) throws NotLockedOutException {
public LockOutFlag getDisabledStatus(String username) {
try {
// Retrieve the disabled status, translate it into a LockOutFlag, and return it.
return checkUserDisabled(getUserByUsername(username));
}
catch (UserNotFoundException e) {
// Not a valid user? We will leave it up to the user provider to handle rejecting this user.
Log.warn(e);
return null;
}
}
......@@ -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
* a NotLockedOutException if they are.
* Examines the XML returned about a user to find out if they are enabled or disabled. Returns
* <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)
* @return Either a LockOutFlag indicating that the user is disabled, or an exception is thrown.
* @throws NotLockedOutException if the user is not currently locked out.
* @return Either a LockOutFlag indicating that the user is disabled, or null if everything is fine.
*/
private LockOutFlag checkUserDisabled(Node responseNode) throws NotLockedOutException {
private LockOutFlag checkUserDisabled(Node responseNode) {
try {
Node userNode = responseNode.selectSingleNode("return");
......@@ -173,20 +171,17 @@ public class ClearspaceLockOutProvider implements LockOutProvider {
boolean isEnabled = Boolean.valueOf(userNode.selectSingleNode("enabled").getText());
if (isEnabled) {
// We're good, indicate that they're not locked out.
throw new NotLockedOutException();
return null;
}
else {
// Creates the lock out flag
return new LockOutFlag(username, null, null);
}
}
catch (NotLockedOutException e) {
throw e;
}
catch (Exception e) {
// 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);
throw new NotLockedOutException();
return null;
}
}
......
......@@ -10,6 +10,7 @@
package org.jivesoftware.openfire.lockout;
import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.StringUtils;
import java.sql.*;
......@@ -42,7 +43,7 @@ public class DefaultLockOutProvider implements LockOutProvider {
* Default provider retrieves disabled status from ofUserFlag table.
* @see org.jivesoftware.openfire.lockout.LockOutProvider#getDisabledStatus(String)
*/
public LockOutFlag getDisabledStatus(String username) throws NotLockedOutException {
public LockOutFlag getDisabledStatus(String username) {
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
......@@ -53,7 +54,7 @@ public class DefaultLockOutProvider implements LockOutProvider {
pstmt.setString(1, username);
rs = pstmt.executeQuery();
if (!rs.next()) {
throw new NotLockedOutException();
return null;
}
Date startTime = null;
if (rs.getString(2) != null) {
......@@ -67,7 +68,8 @@ public class DefaultLockOutProvider implements LockOutProvider {
ret = new LockOutFlag(username, startTime, endTime);
}
catch (Exception e) {
throw new NotLockedOutException();
Log.error("Error loading lockout information from DB", e);
return null;
}
finally {
DbConnectionManager.closeConnection(rs, pstmt, con);
......
......@@ -13,8 +13,8 @@ import org.jivesoftware.util.*;
import org.jivesoftware.util.cache.Cache;
import org.jivesoftware.util.cache.CacheFactory;
import java.util.Map;
import java.util.Date;
import java.util.Map;
/**
* The LockOutManager manages the LockOutProvider configured for this server, caches knowledge of
......@@ -122,10 +122,10 @@ public class LockOutManager {
* period that the specified account is going to be disabled.
*
* @param username Username of account to request status of.
* @return The LockOutFlag instance describing the accounts disabled status.
* @throws NotLockedOutException if user account specified is not currently locked out (disabled).
* @return The LockOutFlag instance describing the accounts disabled status or null if user
* account specified is not currently locked out (disabled).
*/
public LockOutFlag getDisabledStatus(String username) throws NotLockedOutException {
public LockOutFlag getDisabledStatus(String username) {
if (username == null) {
throw new UnsupportedOperationException("Null username not allowed!");
}
......@@ -154,23 +154,18 @@ public class LockOutManager {
* @return True or false if the account is currently locked out.
*/
public boolean isAccountDisabled(String username) {
try {
LockOutFlag flag = getDisabledStatus(username);
if (flag == null) {
return false;
}
Date curDate = new Date();
if (flag.getStartTime() != null && curDate.before(flag.getStartTime())) {
return false;
}
if (flag.getEndTime() != null && curDate.after(flag.getEndTime())) {
return false;
}
return true;
LockOutFlag flag = getDisabledStatus(username);
if (flag == null) {
return false;
}
Date curDate = new Date();
if (flag.getStartTime() != null && curDate.before(flag.getStartTime())) {
return false;
}
catch (NotLockedOutException e) {
if (flag.getEndTime() != null && curDate.after(flag.getEndTime())) {
return false;
}
return true;
}
/**
......
......@@ -20,13 +20,14 @@ public interface LockOutProvider {
/**
* 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.
* @return The LockOutFlag instance describing the accounts disabled status.
* @throws NotLockedOutException if user account specified is not currently locked out (disabled).
* @return The LockOutFlag instance describing the accounts disabled status or null if user
* 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.
......
/**
* $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 @@
- 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"
%>
<%@ 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.xmpp.packet.JID" %>
<%@ page import="org.xmpp.packet.StreamError" %>
<%@ page import="java.net.URLEncoder" %>
<%@ 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/fmt_rt" prefix="fmt" %>
......@@ -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>
......@@ -139,7 +139,8 @@
<%
}
catch (NotLockedOutException e) {
else {
// User is not locked out
%>
<p>
......
......@@ -8,21 +8,20 @@
- a copy of which is included in this distribution.
--%>
<%@ page import="org.jivesoftware.util.JiveGlobals,
org.jivesoftware.util.ParamUtils,
org.jivesoftware.openfire.PresenceManager,
<%@ page import="org.jivesoftware.openfire.PresenceManager,
org.jivesoftware.openfire.admin.AdminManager,
org.jivesoftware.openfire.group.Group,
org.jivesoftware.openfire.user.User,
org.jivesoftware.openfire.user.UserManager,
org.jivesoftware.openfire.user.UserNotFoundException"
errorPage="error.jsp"
%>
<%@ page import="org.xmpp.packet.Presence"%>
<%@ page import="java.net.URLEncoder"%>
<%@ page import="java.util.Collection"%>
<%@ page import="org.jivesoftware.openfire.user.UserManager"%><%@ page import="org.xmpp.packet.JID"%>
<%@ page import="org.jivesoftware.openfire.lockout.NotLockedOutException" %>
<%@ page import="org.jivesoftware.openfire.admin.AdminManager" %>
<%@ page import="org.jivesoftware.util.LocaleUtils" %>
<%@ page import="org.jivesoftware.util.JiveGlobals"%>
<%@ page import="org.jivesoftware.util.LocaleUtils"%>
<%@ page import="org.jivesoftware.util.ParamUtils"%>
<%@ page import="org.xmpp.packet.JID"%><%@ page import="org.xmpp.packet.Presence"%>
<%@ page import="java.net.URLEncoder" %>
<%@ page import="java.util.Collection" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>
......@@ -63,8 +62,8 @@
PresenceManager presenceManager = webManager.getPresenceManager();
Boolean lockedOut = false;
Boolean pendingLockOut = false;
try {
webManager.getLockOutManager().getDisabledStatus(username);
if (webManager.getLockOutManager().getDisabledStatus(username) != null) {
// User is locked out. Check if he is locket out now
if (webManager.getLockOutManager().isAccountDisabled(username)) {
lockedOut = true;
}
......@@ -72,9 +71,6 @@
pendingLockOut = true;
}
}
catch (NotLockedOutException e) {
// Nothing, we're good.
}
%>
<html>
......
......@@ -9,19 +9,18 @@
- a copy of which is included in this distribution.
--%>
<%@ page import="org.jivesoftware.util.JiveGlobals,
org.jivesoftware.util.LocaleUtils,
org.jivesoftware.util.ParamUtils,
org.jivesoftware.util.StringUtils,
org.jivesoftware.openfire.PresenceManager,
<%@ page import="org.jivesoftware.openfire.PresenceManager,
org.jivesoftware.openfire.admin.AdminManager,
org.jivesoftware.openfire.user.User,
org.jivesoftware.openfire.user.UserManager"
%><%@ page import="org.xmpp.packet.JID"%>
org.jivesoftware.openfire.user.UserManager,
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="java.net.URLEncoder" %>
<%@ 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/fmt_rt" prefix="fmt" %>
......@@ -180,8 +179,8 @@
i++;
Boolean lockedOut = false;
Boolean pendingLockOut = false;
try {
webManager.getLockOutManager().getDisabledStatus(user.getUsername());
if (webManager.getLockOutManager().getDisabledStatus(user.getUsername()) != null) {
// User is locked out. Check if its locked out now!
if (webManager.getLockOutManager().isAccountDisabled(user.getUsername())) {
lockedOut = true;
}
......@@ -189,9 +188,6 @@
pendingLockOut = true;
}
}
catch (NotLockedOutException e) {
// Nothing, we're good.
}
Boolean isAdmin = AdminManager.getInstance().isUserAdmin(user.getUsername(), false);
%>
<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