You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/modules/ROOT/pages/servlet/authorization/method-security.adoc
+22-45
Original file line number
Diff line number
Diff line change
@@ -2200,10 +2200,10 @@ Java::
2200
2200
----
2201
2201
@RestController
2202
2202
public class UserController {
2203
-
@Autowired
2203
+
@Autowired
2204
2204
AuthorizationProxyFactory proxyFactory;
2205
2205
2206
-
@GetMapping
2206
+
@GetMapping
2207
2207
User currentUser(@AuthenticationPrincipal User user) {
2208
2208
return this.proxyFactory.proxy(user);
2209
2209
}
@@ -2227,7 +2227,7 @@ class UserController {
2227
2227
----
2228
2228
======
2229
2229
2230
-
Finally, you will need to publish a <<custom_advice, custom interceptor>> to catch the `AccessDeniedException` thrown for each field, which you can do like so:
2230
+
You will need to <<fallback-values-authorization-denied,add a `MethodAuthorizationDeniedHandler`>> like this one:
2231
2231
2232
2232
[tabs]
2233
2233
======
@@ -2236,32 +2236,18 @@ Java::
2236
2236
[source,java,role="primary"]
2237
2237
----
2238
2238
@Component
2239
-
public class AccessDeniedExceptionInterceptor implements AuthorizationAdvisor {
2240
-
private final AuthorizationAdvisor advisor = AuthorizationManagerBeforeMethodInterceptor.preAuthorize();
2241
-
2242
-
@Override
2243
-
public Object invoke(MethodInvocation invocation) throws Throwable {
2244
-
try {
2245
-
return invocation.proceed();
2246
-
} catch (AccessDeniedException ex) {
2247
-
return null;
2248
-
}
2249
-
}
2250
-
2251
-
@Override
2252
-
public Pointcut getPointcut() {
2253
-
return this.advisor.getPointcut();
2254
-
}
2239
+
public class Null implements MethodAuthorizationDeniedHandler {
2240
+
@Override
2241
+
public Object handleDeniedInvocation(MethodInvocation methodInvocation, AuthorizationResult authorizationResult) {
@@ -2317,7 +2294,7 @@ And if they do have that authority, they'll see:
2317
2294
2318
2295
[TIP]
2319
2296
====
2320
-
You can also add the Spring Boot property `spring.jackson.default-property-inclusion=non_null` to exclude the null value, if you also don't want to reveal the JSON key to an unauthorized user.
2297
+
You can also add the Spring Boot property `spring.jackson.default-property-inclusion=non_null` to exclude the null value from serialization, if you also don't want to reveal the JSON key to an unauthorized user.
0 commit comments