Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9001f9e

Browse files
committed
[Security] Expose the required roles in AccessDeniedException
1 parentf146f84 commit9001f9e

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

‎src/Symfony/Component/Security/Core/Exception/AccessDeniedException.php‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,43 @@
1818
*/
1919
class AccessDeniedExceptionextends \RuntimeException
2020
{
21+
private$attributes = [];
22+
private$object;
23+
2124
publicfunction__construct($message ='Access Denied.',\Exception$previous =null)
2225
{
2326
parent::__construct($message,403,$previous);
2427
}
28+
29+
/**
30+
* @return array
31+
*/
32+
publicfunctiongetAttributes()
33+
{
34+
return$this->attributes;
35+
}
36+
37+
/**
38+
* @param array $attributes
39+
*/
40+
publicfunctionsetAttributes(array$attributes)
41+
{
42+
$this->attributes =$attributes;
43+
}
44+
45+
/**
46+
* @return mixed
47+
*/
48+
publicfunctiongetObject()
49+
{
50+
return$this->object;
51+
}
52+
53+
/**
54+
* @param mixed $object
55+
*/
56+
publicfunctionsetObject($object)
57+
{
58+
$this->object =$object;
59+
}
2560
}

‎src/Symfony/Component/Security/Http/Firewall/AccessListener.php‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ public function handle(GetResponseEvent $event)
6767
}
6868

6969
if (!$this->accessDecisionManager->decide($token,$attributes,$request)) {
70-
thrownewAccessDeniedException();
70+
$exception =newAccessDeniedException();
71+
$exception->setAttributes($attributes);
72+
$exception->setObject($request);
73+
74+
throw$exception;
7175
}
7276
}
7377
}

‎src/Symfony/Component/Security/Http/Firewall/SwitchUserListener.php‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,10 @@ private function attemptSwitchUser(Request $request)
122122
}
123123

124124
if (false ===$this->accessDecisionManager->decide($token,array($this->role))) {
125-
thrownewAccessDeniedException();
125+
$exception =newAccessDeniedException();
126+
$exception->setAttributes(array($this->role));
127+
128+
throw$exception;
126129
}
127130

128131
$username =$request->get($this->usernameParameter);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp