Skip to content

Commit 57f7eff

Browse files
committed
Polish method-security.adoc
1 parent 6e16053 commit 57f7eff

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

docs/modules/ROOT/pages/servlet/authorization/method-security.adoc

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,9 +1214,9 @@ Kotlin::
12141214
companion object {
12151215
@Bean
12161216
fun methodSecurityExpressionHandler(val roleHierarchy: RoleHierarchy) : MethodSecurityExpressionHandler {
1217-
val handler = DefaultMethodSecurityExpressionHandler();
1218-
handler.setRoleHierarchy(roleHierarchy);
1219-
return handler;
1217+
val handler = DefaultMethodSecurityExpressionHandler()
1218+
handler.setRoleHierarchy(roleHierarchy)
1219+
return handler
12201220
}
12211221
}
12221222
----
@@ -1260,41 +1260,43 @@ Java::
12601260
+
12611261
[source,java,role="primary"]
12621262
----
1263-
import static org.springframework.security.authorization.AuthorityAuthorizationManager.hasRole;
1263+
import static org.springframework.security.authorization.AuthorityAuthorizationManager.hasRole
12641264
12651265
@Bean
12661266
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
12671267
static Advisor protectServicePointcut() {
1268-
AspectJExpressionPointcut pattern = new AspectJExpressionPointcut();
1269-
pattern.setExpression("execution(* com.mycompany.*Service.*(..))");
1270-
return new AuthorizationManagerBeforeMethodInterceptor(pattern, hasRole("USER"));
1268+
AspectJExpressionPointcut pattern = new AspectJExpressionPointcut()
1269+
pattern.setExpression("execution(* com.mycompany.*Service.*(..))")
1270+
return new AuthorizationManagerBeforeMethodInterceptor(pattern, hasRole("USER"))
12711271
}
12721272
----
12731273
12741274
Kotlin::
12751275
+
12761276
[source,kotlin,role="secondary"]
12771277
----
1278-
import static org.springframework.security.authorization.AuthorityAuthorizationManager.hasRole;
1278+
import static org.springframework.security.authorization.AuthorityAuthorizationManager.hasRole
12791279
12801280
companion object {
12811281
@Bean
12821282
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
12831283
fun protectServicePointcut(): Advisor {
1284-
val pattern = AspectJExpressionPointcut();
1285-
pattern.setExpression("execution(* com.mycompany.*Service.*(..))");
1286-
return new AuthorizationManagerBeforeMethodInterceptor(pattern, hasRole("USER"));
1284+
val pattern = AspectJExpressionPointcut()
1285+
pattern.setExpression("execution(* com.mycompany.*Service.*(..))")
1286+
return new AuthorizationManagerBeforeMethodInterceptor(pattern, hasRole("USER"))
12871287
}
12881288
}
12891289
----
1290-
======
12911290
1292-
[source,xml]
1291+
Xml::
1292+
+
1293+
[source,xml,role="secondary"]
12931294
----
12941295
<sec:method-security>
12951296
<protect-pointcut expression="execution(* com.mycompany.*Service.*(..))" access="hasRole('USER')"/>
12961297
</sec:method-security>
12971298
----
1299+
======
12981300

12991301
[[weave-aspectj]]
13001302
=== Integrate with AspectJ Byte-weaving
@@ -1445,7 +1447,7 @@ open class MyService {
14451447
fun readResource(...): MyResource
14461448
14471449
@PreAuthorize("@authz.check(#root)")
1448-
fun shareResource(...): MyResource;
1450+
fun shareResource(...): MyResource
14491451
}
14501452
----
14511453
@@ -1769,8 +1771,8 @@ class MyExpressionHandler: DefaultMethodSecurityExpressionHandler {
17691771
val context = super.createEvaluationContext(authentication, mi) as StandardEvaluationContext
17701772
val delegate = context.getRootObject().getValue() as MethodSecurityExpressionOperations
17711773
val root = MySecurityExpressionRoot(delegate)
1772-
context.setRootObject(root);
1773-
return context;
1774+
context.setRootObject(root)
1775+
return context
17741776
}
17751777
}
17761778
----

0 commit comments

Comments
 (0)