added emergency fix to display a "login or create" dialog for all AccessErrors

thrown by the engine when trying to view a conference/topic/post and the user
is not logged in
This commit is contained in:
Eric J. Bowersox 2001-12-14 17:14:10 +00:00
parent ae129e5410
commit 0bbd01e385
18 changed files with 290 additions and 26 deletions

View File

@ -278,5 +278,48 @@ public class StringUtil
} // end join } // end join
} // end class StringUtil public static final List splitList(String data, String delims)
{
if ((data==null) || (delims==null))
return Collections.EMPTY_LIST;
ArrayList rc = new ArrayList();
StringBuffer buf = new StringBuffer();
boolean accumulate = false;
for (int i=0; i<data.length(); i++)
{ // look at each character in turn
char ch = data.charAt(i);
if (delims.indexOf(ch)>=0)
{ // delimiter character - flush the string if we have one
if (accumulate)
{ // flush the buffer
rc.add(buf.toString());
buf.setLength(0);
accumulate = false;
} // end if
} // end if
else
{ // ordinary character - accumulate it
accumulate = true;
buf.append(ch);
} // end else
} // end for
if (rc.isEmpty())
return Collections.EMPTY_LIST;
else
return Collections.unmodifiableList(rc);
} // end splitList
public static final String[] splitArray(String data, String delims)
{
List tmp = splitList(data,delims);
return (String[])(tmp.toArray(new String[0]));
} // end splitArray
} // end class StringUtil

View File

@ -164,6 +164,8 @@ public interface CommunityContext extends SearchMode
public abstract void delete() throws DataException, AccessError; public abstract void delete() throws DataException, AccessError;
public abstract void deleteCommunity() throws DataException, AccessError;
public abstract void sendInvitation(String address, String personal_message) public abstract void sendInvitation(String address, String personal_message)
throws AccessError, DataException, EmailException; throws AccessError, DataException, EmailException;

View File

@ -147,6 +147,8 @@ public interface ConferenceContext
public abstract void delete() throws DataException, AccessError; public abstract void delete() throws DataException, AccessError;
public abstract void deleteConference() throws DataException, AccessError;
public abstract boolean canDeleteConference(); public abstract boolean canDeleteConference();
public abstract boolean isInHotlist(); public abstract boolean isInHotlist();

View File

@ -21,6 +21,8 @@ public interface SideBoxDescriptor
{ {
public abstract int getID(); public abstract int getID();
public abstract int getSideBoxID();
public abstract int getSequence(); public abstract int getSequence();
public abstract String getTitle(boolean anonymous); public abstract String getTitle(boolean anonymous);

View File

@ -81,6 +81,8 @@ public interface TopicContext
public abstract void delete() throws DataException, AccessError; public abstract void delete() throws DataException, AccessError;
public abstract void deleteTopic() throws DataException, AccessError;
public abstract List getActivePosters(int skip, int limit) throws DataException, AccessError; public abstract List getActivePosters(int skip, int limit) throws DataException, AccessError;
public abstract List getActivePosters(int limit) throws DataException, AccessError; public abstract List getActivePosters(int limit) throws DataException, AccessError;

View File

@ -1193,6 +1193,12 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
} // end delete } // end delete
public void deleteCommunity() throws DataException, AccessError
{
this.delete();
} // end delete
public void sendInvitation(String address, String personal_message) public void sendInvitation(String address, String personal_message)
throws AccessError, DataException, EmailException throws AccessError, DataException, EmailException
{ {

View File

@ -875,7 +875,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
{ {
if (!(getConferenceData().canReadConference(level))) if (!(getConferenceData().canReadConference(level)))
{ // the luser can't even read the conference... { // the luser can't even read the conference...
logger.error("getTopic(): user not permitted to change membership"); logger.error("getTopic(): user not permitted to read");
throw new AccessError("You are not permitted to read this conference."); throw new AccessError("You are not permitted to read this conference.");
} // end if } // end if
@ -1253,6 +1253,12 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
} // end delete } // end delete
public void deleteConference() throws DataException, AccessError
{
this.delete();
} // end deleteConference
public boolean canDeleteConference() public boolean canDeleteConference()
{ {
ConferenceCommunityContext c = getConferenceDataNE(); ConferenceCommunityContext c = getConferenceDataNE();

View File

@ -66,6 +66,12 @@ class SideBoxDescriptorImpl implements UserSideBoxDescriptor
} // end getID } // end getID
public int getSideBoxID()
{
return parent.getID();
} // end getSideBoxID
public int getSequence() public int getSequence()
{ {
return sequence; return sequence;

View File

@ -958,6 +958,12 @@ class TopicUserContextImpl implements TopicContext
} // end delete } // end delete
public void deleteTopic() throws DataException, AccessError
{
this.delete();
} // end deleteTopic
public List getActivePosters(int skip, int limit) throws DataException public List getActivePosters(int skip, int limit) throws DataException
{ {
Connection conn = null; Connection conn = null;

View File

@ -84,6 +84,12 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
} // end getID } // end getID
public int getSideBoxID()
{
return id;
} // end getSideBoxID
public int getSequence() public int getSequence()
{ {
return -1; return -1;

View File

@ -72,9 +72,10 @@ public class AuditRecord implements AuditData
if (rc==null) if (rc==null)
{ // OK, get it from the database { // OK, get it from the database
ResultSet rs = stmt.executeQuery("SELECT username FROM users WHERE uid = " + uid + ";"); ResultSet rs = stmt.executeQuery("SELECT username FROM users WHERE uid = " + uid + ";");
if (!(rs.next())) if (rs.next())
throw new DataException("user name not found for UID " + uid);
rc = rs.getString(1); rc = rs.getString(1);
else
rc = "(UID #" + uid + ")";
uname_cache.put(uid_x,rc); uname_cache.put(uid_x,rc);
} // end if } // end if
@ -92,9 +93,10 @@ public class AuditRecord implements AuditData
if (rc==null) if (rc==null)
{ // OK, get it from the database { // OK, get it from the database
ResultSet rs = stmt.executeQuery("SELECT signame FROM sigs WHERE sigid = " + cid + ";"); ResultSet rs = stmt.executeQuery("SELECT signame FROM sigs WHERE sigid = " + cid + ";");
if (!(rs.next())) if (rs.next())
throw new DataException("community name not found for community ID " + cid);
rc = rs.getString(1); rc = rs.getString(1);
else
rc = "(CID #" + cid + ")";
commname_cache.put(cid_x,rc); commname_cache.put(cid_x,rc);
} // end if } // end if

View File

@ -318,7 +318,7 @@ public class CommunityOperations extends VeniceServlet
if (user.isLoggedIn()) if (user.isLoggedIn())
return new ErrorBox("Community Error","You are not permitted to create communities.","top"); return new ErrorBox("Community Error","You are not permitted to create communities.","top");
else else
return new ErrorBox("Community Error","You must be logged in to create a new community.","top"); return new LogInOrCreate("sigops?cmd=C");
} // end if } // end if

View File

@ -348,14 +348,15 @@ public class ConfDisplay extends VeniceServlet
ConferenceContext conf = getConferenceParameter(request,comm,true,"top"); ConferenceContext conf = getConferenceParameter(request,comm,true,"top");
// get the topic, if we have it // get the topic, if we have it
TopicContext topic = getTopicParameter(request,conf,false,"top"); TopicContext topic = getTopicParameter(request,user,conf,false,"top",
"confdisp?" + request.getQueryString());
if (topic!=null) if (topic!=null)
{ // we're handling messages within a single topic { // we're handling messages within a single topic
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
logger.debug("MODE: display messages in topic"); logger.debug("MODE: display messages in topic");
String on_error = "confdisp?sig=" + comm.getCommunityID() + "&conf=" + conf.getConfID(); String on_error = "confdisp?sig=" + comm.getCommunityID() + "&conf=" + conf.getConfID();
setMyLocation(request,on_error + "&topic=" + topic.getTopicNumber()); setMyLocation(request,on_error + "&top=" + topic.getTopicNumber());
// if this request is restoring the number of unread posts in another topic, try to do so // if this request is restoring the number of unread posts in another topic, try to do so
boolean do_readnew = restorePosts(request,conf,topic); boolean do_readnew = restorePosts(request,conf,topic);
@ -380,7 +381,10 @@ public class ConfDisplay extends VeniceServlet
} // end catch } // end catch
catch (AccessError ae) catch (AccessError ae)
{ // we were unable to retrieve the message list { // we were unable to retrieve the message list
if (user.isLoggedIn())
return new ErrorBox("Access Error",ae.getMessage(),on_error); return new ErrorBox("Access Error",ae.getMessage(),on_error);
else
return new LogInOrCreate(getMyLocation(request));
} // end catch } // end catch
@ -393,7 +397,7 @@ public class ConfDisplay extends VeniceServlet
String my_location = "confdisp?sig=" + comm.getCommunityID() + "&conf=" + conf.getConfID(); String my_location = "confdisp?sig=" + comm.getCommunityID() + "&conf=" + conf.getConfID();
boolean read_new = !(StringUtil.isStringEmpty(request.getParameter("rnm"))); boolean read_new = !(StringUtil.isStringEmpty(request.getParameter("rnm")));
if (read_new) if (read_new)
my_location += "&rn=1"; my_location += "&rnm=1";
setMyLocation(request,my_location); setMyLocation(request,my_location);
// get any changes to view or sort options // get any changes to view or sort options
@ -441,7 +445,10 @@ public class ConfDisplay extends VeniceServlet
} // end catch } // end catch
catch (AccessError ae) catch (AccessError ae)
{ // we were unable to retrieve the message list { // we were unable to retrieve the message list
if (user.isLoggedIn())
return new ErrorBox("Access Error",ae.getMessage(),on_error); return new ErrorBox("Access Error",ae.getMessage(),on_error);
else
return new LogInOrCreate(getMyLocation(request));
} // end catch } // end catch
@ -462,7 +469,10 @@ public class ConfDisplay extends VeniceServlet
} // end catch } // end catch
catch (AccessError ae) catch (AccessError ae)
{ // we were unable to retrieve the topic list { // we were unable to retrieve the topic list
if (user.isLoggedIn())
return new ErrorBox("Access Error",ae.getMessage(),on_error); return new ErrorBox("Access Error",ae.getMessage(),on_error);
else
return new LogInOrCreate(getMyLocation(request));
} // end catch } // end catch

View File

@ -710,8 +710,8 @@ public class ConfOperations extends VeniceServlet
String message = "You are about to permanently delete the \"" + conf.getName() + "\" conference! " String message = "You are about to permanently delete the \"" + conf.getName() + "\" conference! "
+ "Are you sure you want to do this?"; + "Are you sure you want to do this?";
return new ConfirmBox(request,DELETE_CONFIRM_ATTR,DELETE_CONFIRM_PARAM,"Delete Conference",message, return new ConfirmBox(request,DELETE_CONFIRM_ATTR,DELETE_CONFIRM_PARAM,"Delete Conference",message,
"confops?sig=" + comm.getCommunityID() + "&conf=" + conf.getConfID() + "&cmd=DEL", "confops?sig=" + comm.getCommunityID() + "&conf=" + conf.getConfID()
on_error); + "&cmd=DEL",on_error);
} // end else } // end else
@ -732,7 +732,14 @@ public class ConfOperations extends VeniceServlet
} // end catch } // end catch
catch (AccessError ae) catch (AccessError ae)
{ // some lack of access is causing problems { // some lack of access is causing problems
if (user.isLoggedIn())
return new ErrorBox("Access Error",ae.getMessage(),on_error); return new ErrorBox("Access Error",ae.getMessage(),on_error);
else
{ // they might need to log in first
setMyLocation(request,"confops?sig=" + comm.getCommunityID());
return new LogInOrCreate("confops?sig=" + comm.getCommunityID());
} // end else
} // end catch } // end catch

View File

@ -108,8 +108,9 @@ public abstract class VeniceServlet extends HttpServlet
} // end getCommunityParameter } // end getCommunityParameter
private static TopicContext getTopicParameter(String str, ConferenceContext conf, boolean required, private static TopicContext getTopicParameter(String str, UserContext user, ConferenceContext conf,
String on_error) throws ErrorBox boolean required, String on_error, String target)
throws ErrorBox, LogInOrCreate
{ {
if (StringUtil.isStringEmpty(str)) if (StringUtil.isStringEmpty(str))
{ // there's no topic parameter { // there's no topic parameter
@ -153,6 +154,9 @@ public abstract class VeniceServlet extends HttpServlet
} // end catch } // end catch
catch (AccessError ae) catch (AccessError ae)
{ // these all get handled in pretty much the same way { // these all get handled in pretty much the same way
logger.error("getTopicParameter(): Access error retrieving topic parameter");
if ((user!=null) && (target!=null) && !(user.isLoggedIn()))
throw new LogInOrCreate(target);
throw new ErrorBox("Access Error",ae.getMessage(),on_error); throw new ErrorBox("Access Error",ae.getMessage(),on_error);
} // end catch } // end catch
@ -454,19 +458,29 @@ public abstract class VeniceServlet extends HttpServlet
} // end getConferenceParameter } // end getConferenceParameter
protected final static TopicContext getTopicParameter(ServletRequest request, ConferenceContext conf, protected final static TopicContext getTopicParameter(ServletRequest request, ConferenceContext conf,
boolean required, String on_error) throws ErrorBox boolean required, String on_error)
throws ErrorBox, LogInOrCreate
{ {
return getTopicParameter(request.getParameter("top"),conf,required,on_error); return getTopicParameter(request.getParameter("top"),null,conf,required,on_error,null);
} // end getTopicParameter
protected final static TopicContext getTopicParameter(ServletRequest request, UserContext user,
ConferenceContext conf, boolean required,
String on_error, String target)
throws ErrorBox, LogInOrCreate
{
return getTopicParameter(request.getParameter("top"),user,conf,required,on_error,target);
} // end getTopicParameter } // end getTopicParameter
protected final static TopicContext getTopicParameter(ServletMultipartHandler mphandler, protected final static TopicContext getTopicParameter(ServletMultipartHandler mphandler,
ConferenceContext conf, boolean required, ConferenceContext conf, boolean required,
String on_error) throws ErrorBox String on_error) throws ErrorBox, LogInOrCreate
{ {
if (mphandler.isFileParam("top")) if (mphandler.isFileParam("top"))
throw new ErrorBox(null,"Internal Error: topic should be a normal param",on_error); throw new ErrorBox(null,"Internal Error: topic should be a normal param",on_error);
return getTopicParameter(mphandler.getValue("top"),conf,required,on_error); return getTopicParameter(mphandler.getValue("top"),null,conf,required,on_error,null);
} // end getTopicParameter } // end getTopicParameter
@ -511,10 +525,16 @@ public abstract class VeniceServlet extends HttpServlet
*-------------------------------------------------------------------------------- *--------------------------------------------------------------------------------
*/ */
protected String getMyLocation(HttpServletRequest request)
{
return (String)(request.getAttribute(LOCATION_ATTR));
} // end getMyLocation
protected String getMyLocation(HttpServletRequest request, VeniceEngine engine, UserContext user, protected String getMyLocation(HttpServletRequest request, VeniceEngine engine, UserContext user,
RenderData rdat) RenderData rdat)
{ {
return (String)(request.getAttribute(LOCATION_ATTR)); return getMyLocation(request);
} // end getMyLocation } // end getMyLocation

View File

@ -0,0 +1,112 @@
/*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
*
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* The Original Code is the Venice Web Communities System.
*
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.servlets.format;
import java.net.URLEncoder;
import java.io.Writer;
import java.io.IOException;
import javax.servlet.*;
import com.silverwrist.util.StringUtil;
import com.silverwrist.venice.servlets.VeniceServletResult;
public class LogInOrCreate extends VeniceServletResult implements JSPRender, ColorSelectors
{
/*--------------------------------------------------------------------------------
* Static data members
*--------------------------------------------------------------------------------
*/
// Attribute name for request attribute
protected static final String ATTR_NAME = "com.silverwrist.venice.content.LogInOrCreate";
/*--------------------------------------------------------------------------------
* Attributes
*--------------------------------------------------------------------------------
*/
private String target;
/*--------------------------------------------------------------------------------
* Constructor
*--------------------------------------------------------------------------------
*/
public LogInOrCreate(String target)
{
super();
this.target = target;
} // end constructor
/*--------------------------------------------------------------------------------
* External static functions
*--------------------------------------------------------------------------------
*/
public static LogInOrCreate retrieve(ServletRequest request)
{
return (LogInOrCreate)(request.getAttribute(ATTR_NAME));
} // end retrieve
/*--------------------------------------------------------------------------------
* Implementations from interface VeniceContent
*--------------------------------------------------------------------------------
*/
public String getPageTitle(RenderData rdat)
{
return "Log In or Create Account";
} // end getPageTitle
public String getPageQID()
{
return null;
} // end getPageQID
/*--------------------------------------------------------------------------------
* Implementations from interface JSPRender
*--------------------------------------------------------------------------------
*/
public void store(ServletRequest request)
{
request.setAttribute(ATTR_NAME,this);
} // end store
public String getTargetJSPName()
{
return "login_or_create.jsp";
} // end getTargetJSPName
/*--------------------------------------------------------------------------------
* External operations
*--------------------------------------------------------------------------------
*/
public String getTargetURL(RenderData rdat, String base_URL)
{
return rdat.getEncodedServletPath(base_URL + URLEncoder.encode(target));
} // end getTargetURL
} // end class LogInOrCreate

View File

@ -0,0 +1,32 @@
<%--
The contents of this file are subject to the Mozilla Public License Version 1.1
(the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
WARRANTY OF ANY KIND, either express or implied. See the License for the specific
language governing rights and limitations under the License.
The Original Code is the Venice Web Communities System.
The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
Contributor(s):
--%>
<%@ page import = "java.util.*" %>
<%@ page import = "com.silverwrist.util.StringUtil" %>
<%@ page import = "com.silverwrist.venice.core.*" %>
<%@ page import = "com.silverwrist.venice.servlets.Variables" %>
<%@ page import = "com.silverwrist.venice.servlets.format.*" %>
<%
LogInOrCreate data = LogInOrCreate.retrieve(request);
RenderData rdat = RenderConfig.createRenderData(application,request,response);
%>
<% rdat.writeContentHeader(out,"Log In or Create Account",null); %>
<%= rdat.getStdFontTag(ColorSelectors.CONTENT_FOREGROUND,2) %>
You must log in or create an account before you can view this page.<P>
Returning users <A HREF="<%= data.getTargetURL(rdat,"account?cmd=L&tgt=") %>">log in here</A>.<P>
New users <A HREF="<%= data.getTargetURL(rdat,"account?cmd=C&tgt=") %>">create an account here.<P>
</FONT>