-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathProfileController.cs
76 lines (66 loc) · 1.63 KB
/
ProfileController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
public class RequirePermissionAttribute : AuthorizeAttribute { }
public class ProfileController : Controller
{
private void doThings() { }
private bool isAuthorized() { return false; }
// BAD: This is a Delete method, but no auth is specified.
public ActionResult Delete1(int id) // $ Alert
{
doThings();
return View();
}
// GOOD: isAuthorized is checked.
public ActionResult Delete2(int id)
{
if (!isAuthorized())
{
return null;
}
doThings();
return View();
}
// GOOD: The Authorize attribute is used.
[Authorize]
public ActionResult Delete3(int id)
{
doThings();
return View();
}
// GOOD: The RequirePermission attribute is used (which extends AuthorizeAttribute).
[RequirePermission]
public ActionResult Delete4(int id)
{
doThings();
return View();
}
}
[Authorize]
public class AuthBaseController : Controller
{
protected void doThings() { }
}
public class SubController : AuthBaseController
{
// GOOD: The Authorize attribute is used on the base class.
public ActionResult Delete4(int id)
{
doThings();
return View();
}
}
[Authorize]
public class AuthBaseGenericController<T> : Controller
{
protected void doThings() { }
}
public class SubGenericController : AuthBaseGenericController<string>
{
// GOOD: The Authorize attribute is used on the base class.
public ActionResult Delete5(int id)
{
doThings();
return View();
}
}