From 46c8a064ef9c9b43976f81d974f5ddd73b612b5f Mon Sep 17 00:00:00 2001
From: inga-lovinde <52715130+inga-lovinde@users.noreply.github.com>
Date: Tue, 5 Oct 2010 15:39:13 +0000
Subject: [PATCH] AccessDeniedException implemented
---
Builder/IISMainHandler/build.txt | 2 +-
Common/dataobjects/PMConversation.cs | 4 ++--
Common/dataobjects/PMMessage.cs | 4 ++--
Common/dataobjects/Post.cs | 2 +-
Core/Core.csproj | 1 +
IISMainHandler/WebContext.cs | 8 +++++++-
IISMainHandler/handlers/response/UploadHandler.cs | 2 +-
IISMainHandler/handlers/response/UploadInfoHandler.cs | 2 +-
IISMainHandler/handlers/response/UploadListHandler.cs | 2 +-
9 files changed, 17 insertions(+), 10 deletions(-)
diff --git a/Builder/IISMainHandler/build.txt b/Builder/IISMainHandler/build.txt
index b533493..249240a 100644
--- a/Builder/IISMainHandler/build.txt
+++ b/Builder/IISMainHandler/build.txt
@@ -1 +1 @@
-1757
\ No newline at end of file
+1761
\ No newline at end of file
diff --git a/Common/dataobjects/PMConversation.cs b/Common/dataobjects/PMConversation.cs
index cb52164..b48e2e1 100644
--- a/Common/dataobjects/PMConversation.cs
+++ b/Common/dataobjects/PMConversation.cs
@@ -113,7 +113,7 @@ namespace FLocal.Common.dataobjects {
}
public XElement exportToXml(UserContext context, bool includeFirstPost, params XElement[] additional) {
- if((context.account == null) || (context.account.id != this.owner.id)) throw new AccessViolationException();
+ if((context.account == null) || (context.account.id != this.owner.id)) throw new AccessDeniedException();
XElement result = new XElement("conversation",
new XElement("id", this.id),
new XElement("owner", this.owner.exportToXml(context)),
@@ -186,7 +186,7 @@ namespace FLocal.Common.dataobjects {
}
public void markAsRead(Account account, PMMessage minMessage, PMMessage maxMessage) {
- if(this.ownerId != account.id) throw new AccessViolationException();
+ if(this.ownerId != account.id) throw new AccessDeniedException();
ChangeSetUtil.ApplyChanges(new AbstractChange[] {
new UpdateChange(
TableSpec.instance,
diff --git a/Common/dataobjects/PMMessage.cs b/Common/dataobjects/PMMessage.cs
index e9fccbb..3194215 100644
--- a/Common/dataobjects/PMMessage.cs
+++ b/Common/dataobjects/PMMessage.cs
@@ -151,7 +151,7 @@ namespace FLocal.Common.dataobjects {
public XElement exportToXml(UserContext context, params XElement[] additional) {
if((context.account == null) || (context.account.id != this.owner.id)) {
- throw new AccessViolationException();
+ throw new AccessDeniedException();
}
XElement result = new XElement("message",
@@ -176,7 +176,7 @@ namespace FLocal.Common.dataobjects {
private readonly object MarkAsRead_locker = new object();
public void MarkAsRead(Account account) {
- if(account.id != this.owner.id) throw new AccessViolationException();
+ if(account.id != this.owner.id) throw new AccessDeniedException();
if(!this.isRead) {
lock(MarkAsRead_locker) {
//so we can safely decrease ReadPrivateMessages counter
diff --git a/Common/dataobjects/Post.cs b/Common/dataobjects/Post.cs
index 4f92fcf..3e8fe16 100644
--- a/Common/dataobjects/Post.cs
+++ b/Common/dataobjects/Post.cs
@@ -299,7 +299,7 @@ namespace FLocal.Common.dataobjects {
private readonly object Edit_locker = new object(); //TODO: move locking to DB
public void Edit(User user, string newTitle, string newBody, PostLayer newDesiredLayer) {
if(this.poster.id != user.id) {
- throw new AccessViolationException();
+ throw new AccessDeniedException();
}
PostLayer actualLayer = poster.getActualLayer(this.thread.board, newDesiredLayer);
if(actualLayer.id < this.layer.id) {
diff --git a/Core/Core.csproj b/Core/Core.csproj
index 0b3cbcf..bc1f798 100644
--- a/Core/Core.csproj
+++ b/Core/Core.csproj
@@ -70,6 +70,7 @@
+
diff --git a/IISMainHandler/WebContext.cs b/IISMainHandler/WebContext.cs
index be6d788..47756be 100644
--- a/IISMainHandler/WebContext.cs
+++ b/IISMainHandler/WebContext.cs
@@ -186,7 +186,13 @@ namespace FLocal.IISHandler {
}
public void LogError(Exception e) {
- using(StreamWriter writer = new StreamWriter(Common.Config.instance.dataDir + "Logs\\" + DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") + "." + e.GetGuid().ToString() + ".txt")) {
+ string dir;
+ if(e is AccessDeniedException) {
+ dir = Common.Config.instance.dataDir + "Logs\\AccessDenied\\";
+ } else {
+ dir = Common.Config.instance.dataDir + "Logs\\";
+ }
+ using(StreamWriter writer = new StreamWriter(dir + DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") + "." + e.GetGuid().ToString() + ".txt")) {
writer.WriteLine("Requested url: " + this.httprequest.Url.ToString());
foreach(string key in this.httprequest.Form.Keys) {
writer.WriteLine(string.Format("Form[{0}]: {1}", key, this.httprequest.Form[key]));
diff --git a/IISMainHandler/handlers/response/UploadHandler.cs b/IISMainHandler/handlers/response/UploadHandler.cs
index bee64b8..2ab9500 100644
--- a/IISMainHandler/handlers/response/UploadHandler.cs
+++ b/IISMainHandler/handlers/response/UploadHandler.cs
@@ -21,7 +21,7 @@ namespace FLocal.IISHandler.handlers.response {
protected override string getRedirectUrl(WebContext context) {
Uri referer = context.httprequest.UrlReferrer;
if(referer == null || referer.Host != context.httprequest.Url.Host) {
- throw new AccessViolationException();
+ throw new AccessDeniedException();
}
string mime = Util.getMimeByExtension(this.url.upload.extension);
diff --git a/IISMainHandler/handlers/response/UploadInfoHandler.cs b/IISMainHandler/handlers/response/UploadInfoHandler.cs
index 57d2215..f1f33ba 100644
--- a/IISMainHandler/handlers/response/UploadInfoHandler.cs
+++ b/IISMainHandler/handlers/response/UploadInfoHandler.cs
@@ -20,7 +20,7 @@ namespace FLocal.IISHandler.handlers.response {
protected override IEnumerable getSpecificData(WebContext context) {
if(context.session == null) {
- throw new AccessViolationException();
+ throw new AccessDeniedException();
}
return new XElement[] {
this.url.upload.exportToXml(context),
diff --git a/IISMainHandler/handlers/response/UploadListHandler.cs b/IISMainHandler/handlers/response/UploadListHandler.cs
index 9c53595..3f20911 100644
--- a/IISMainHandler/handlers/response/UploadListHandler.cs
+++ b/IISMainHandler/handlers/response/UploadListHandler.cs
@@ -19,7 +19,7 @@ namespace FLocal.IISHandler.handlers.response {
}
protected override IEnumerable getSpecificData(WebContext context) {
- if(context.session == null) throw new AccessViolationException();
+ if(context.session == null) throw new AccessDeniedException();
PageOuter pageOuter = PageOuter.createFromUrl(this.url, context.userSettings.uploadsPerPage);
List uploads = Upload.LoadByIds(
from stringId in Config.instance.mainConnection.LoadIdsByConditions(