Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
CAP
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
CAP
Commits
3c6b704b
Commit
3c6b704b
authored
Aug 28, 2019
by
Zhenyu,Liu
Committed by
Savorboard
Aug 28, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change DashboardMiddleware to async (#390)
parent
b8a9584d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
10 deletions
+20
-10
CAP.DashboardMiddleware.cs
src/DotNetCore.CAP/Dashboard/CAP.DashboardMiddleware.cs
+13
-8
IDashboardAuthorizationFilter.cs
...DotNetCore.CAP/Dashboard/IDashboardAuthorizationFilter.cs
+3
-1
LocalRequestsOnlyAuthorizationFilter.cs
...ore.CAP/Dashboard/LocalRequestsOnlyAuthorizationFilter.cs
+4
-1
No files found.
src/DotNetCore.CAP/Dashboard/CAP.DashboardMiddleware.cs
View file @
3c6b704b
...
...
@@ -27,12 +27,13 @@ namespace DotNetCore.CAP
_routes
=
routes
??
throw
new
ArgumentNullException
(
nameof
(
routes
));
}
public
Task
Invoke
(
HttpContext
context
)
public
async
Task
Invoke
(
HttpContext
context
)
{
if
(!
context
.
Request
.
Path
.
StartsWithSegments
(
_options
.
PathMatch
,
out
var
matchedPath
,
out
var
remainingPath
))
{
return
_next
(
context
);
await
_next
(
context
);
return
;
}
// Update the path
...
...
@@ -48,23 +49,27 @@ namespace DotNetCore.CAP
if
(
findResult
==
null
)
{
return
_next
.
Invoke
(
context
);
await
_next
.
Invoke
(
context
);
return
;
}
if
(
_options
.
Authorization
.
Any
(
filter
=>
!
filter
.
Authorize
(
dashboardContext
))
)
foreach
(
var
authorizationFilter
in
_options
.
Authorization
)
{
var
authenticateResult
=
await
authorizationFilter
.
AuthorizeAsync
(
dashboardContext
);
if
(
authenticateResult
)
continue
;
var
isAuthenticated
=
context
.
User
?.
Identity
?.
IsAuthenticated
;
context
.
Response
.
StatusCode
=
isAuthenticated
==
true
?
(
int
)
HttpStatusCode
.
Forbidden
:
(
int
)
HttpStatusCode
.
Unauthorized
;
?
(
int
)
HttpStatusCode
.
Forbidden
:
(
int
)
HttpStatusCode
.
Unauthorized
;
return
Task
.
CompletedTask
;
return
;
}
dashboardContext
.
UriMatch
=
findResult
.
Item2
;
return
findResult
.
Item1
.
Dispatch
(
dashboardContext
);
await
findResult
.
Item1
.
Dispatch
(
dashboardContext
);
}
finally
{
...
...
src/DotNetCore.CAP/Dashboard/IDashboardAuthorizationFilter.cs
View file @
3c6b704b
// Copyright (c) .NET Core Community. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using
System.Threading.Tasks
;
namespace
DotNetCore.CAP.Dashboard
{
public
interface
IDashboardAuthorizationFilter
{
bool
Authorize
(
DashboardContext
context
);
Task
<
bool
>
AuthorizeAsync
(
DashboardContext
context
);
}
}
\ No newline at end of file
src/DotNetCore.CAP/Dashboard/LocalRequestsOnlyAuthorizationFilter.cs
View file @
3c6b704b
// Copyright (c) .NET Core Community. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using
System.Threading.Tasks
;
using
DotNetCore.CAP.Infrastructure
;
namespace
DotNetCore.CAP.Dashboard
{
public
class
LocalRequestsOnlyAuthorizationFilter
:
IDashboardAuthorizationFilter
{
public
bool
Authorize
(
DashboardContext
context
)
#pragma warning disable 1998
public
async
Task
<
bool
>
AuthorizeAsync
(
DashboardContext
context
)
#pragma warning restore 1998
{
var
ipAddress
=
context
.
Request
.
RemoteIpAddress
;
// if unknown, assume not local
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment