method-security: fix invalid Kotlin syntax

val/var on function parameters is invalid Kotlin syntax. It has been removed quite some time ago. This change updates the method-security page to reflect that.

Signed-off-by: Simão Gomes Viana <simao.gomes@toowoxx.de>
This commit is contained in:
Simão Gomes Viana 2025-01-08 11:53:31 +01:00 committed by Rob Winch
parent 0e3cfd1efb
commit 980564838d

View File

@ -108,7 +108,7 @@ Kotlin::
open class MyCustomerService { open class MyCustomerService {
@PreAuthorize("hasAuthority('permission:read')") @PreAuthorize("hasAuthority('permission:read')")
@PostAuthorize("returnObject.owner == authentication.name") @PostAuthorize("returnObject.owner == authentication.name")
fun readCustomer(val id: String): Customer { ... } fun readCustomer(id: String): Customer { ... }
} }
---- ----
====== ======
@ -338,7 +338,7 @@ Kotlin::
@Component @Component
open class BankService { open class BankService {
@PreAuthorize("hasRole('ADMIN')") @PreAuthorize("hasRole('ADMIN')")
fun readAccount(val id: Long): Account { fun readAccount(id: Long): Account {
// ... is only invoked if the `Authentication` has the `ROLE_ADMIN` authority // ... is only invoked if the `Authentication` has the `ROLE_ADMIN` authority
} }
} }
@ -426,7 +426,7 @@ Kotlin::
@Component @Component
open class BankService { open class BankService {
@PostAuthorize("returnObject.owner == authentication.name") @PostAuthorize("returnObject.owner == authentication.name")
fun readAccount(val id: Long): Account { fun readAccount(id: Long): Account {
// ... is only returned if the `Account` belongs to the logged in user // ... is only returned if the `Account` belongs to the logged in user
} }
} }
@ -536,7 +536,7 @@ Kotlin::
@Component @Component
open class BankService { open class BankService {
@RequireOwnership @RequireOwnership
fun readAccount(val id: Long): Account { fun readAccount(id: Long): Account {
// ... is only returned if the `Account` belongs to the logged in user // ... is only returned if the `Account` belongs to the logged in user
} }
} }
@ -993,7 +993,7 @@ Kotlin::
@Component @Component
open class BankService { open class BankService {
@IsAdmin @IsAdmin
fun readAccount(val id: Long): Account { fun readAccount(id: Long): Account {
// ... is only returned if the `Account` belongs to the logged in user // ... is only returned if the `Account` belongs to the logged in user
} }
} }
@ -1084,7 +1084,7 @@ Kotlin::
@Component @Component
open class BankService { open class BankService {
@HasRole("ADMIN") @HasRole("ADMIN")
fun readAccount(val id: Long): Account { fun readAccount(id: Long): Account {
// ... is only returned if the `Account` belongs to the logged in user // ... is only returned if the `Account` belongs to the logged in user
} }
} }
@ -1144,7 +1144,7 @@ Kotlin::
@Component @Component
open class BankService { open class BankService {
@HasAnyRole(roles = arrayOf("'USER'", "'ADMIN'")) @HasAnyRole(roles = arrayOf("'USER'", "'ADMIN'"))
fun readAccount(val id: Long): Account { fun readAccount(id: Long): Account {
// ... is only returned if the `Account` belongs to the logged in user // ... is only returned if the `Account` belongs to the logged in user
} }
} }
@ -1271,7 +1271,7 @@ Kotlin::
---- ----
@Component("authz") @Component("authz")
open class AuthorizationLogic { open class AuthorizationLogic {
fun decide(val operations: MethodSecurityExpressionOperations): boolean { fun decide(operations: MethodSecurityExpressionOperations): boolean {
// ... authorization logic // ... authorization logic
} }
} }
@ -1342,7 +1342,7 @@ Kotlin::
---- ----
@Component("authz") @Component("authz")
open class AuthorizationLogic { open class AuthorizationLogic {
fun decide(val operations: MethodSecurityExpressionOperations): AuthorizationDecision { fun decide(operations: MethodSecurityExpressionOperations): AuthorizationDecision {
// ... authorization logic // ... authorization logic
return MyAuthorizationDecision(false, details) return MyAuthorizationDecision(false, details)
} }
@ -1435,13 +1435,13 @@ Kotlin::
class MethodSecurityConfig { class MethodSecurityConfig {
@Bean @Bean
@Role(BeanDefinition.ROLE_INFRASTRUCTURE) @Role(BeanDefinition.ROLE_INFRASTRUCTURE)
fun preAuthorize(val manager: MyAuthorizationManager) : Advisor { fun preAuthorize(manager: MyAuthorizationManager) : Advisor {
return AuthorizationManagerBeforeMethodInterceptor.preAuthorize(manager) return AuthorizationManagerBeforeMethodInterceptor.preAuthorize(manager)
} }
@Bean @Bean
@Role(BeanDefinition.ROLE_INFRASTRUCTURE) @Role(BeanDefinition.ROLE_INFRASTRUCTURE)
fun postAuthorize(val manager: MyAuthorizationManager) : Advisor { fun postAuthorize(manager: MyAuthorizationManager) : Advisor {
return AuthorizationManagerAfterMethodInterceptor.postAuthorize(manager) return AuthorizationManagerAfterMethodInterceptor.postAuthorize(manager)
} }
} }
@ -1501,7 +1501,7 @@ Kotlin::
---- ----
companion object { companion object {
@Bean @Bean
fun methodSecurityExpressionHandler(val roleHierarchy: RoleHierarchy) : MethodSecurityExpressionHandler { fun methodSecurityExpressionHandler(roleHierarchy: RoleHierarchy) : MethodSecurityExpressionHandler {
val handler = DefaultMethodSecurityExpressionHandler() val handler = DefaultMethodSecurityExpressionHandler()
handler.setRoleHierarchy(roleHierarchy) handler.setRoleHierarchy(roleHierarchy)
return handler return handler
@ -3236,7 +3236,7 @@ Kotlin::
[source,kotlin,role="secondary"] [source,kotlin,role="secondary"]
---- ----
class MyAuthorizer { class MyAuthorizer {
fun isAdmin(val root: MethodSecurityExpressionOperations): boolean { fun isAdmin(root: MethodSecurityExpressionOperations): boolean {
val decision = root.hasAuthority("ADMIN"); val decision = root.hasAuthority("ADMIN");
// custom work ... // custom work ...
return decision; return decision;
@ -3295,7 +3295,7 @@ Kotlin::
---- ----
@Component @Component
class MyExpressionHandler: DefaultMethodSecurityExpressionHandler { class MyExpressionHandler: DefaultMethodSecurityExpressionHandler {
override fun createEvaluationContext(val authentication: Supplier<Authentication>, override fun createEvaluationContext(authentication: Supplier<Authentication>,
val mi: MethodInvocation): EvaluationContext { val mi: MethodInvocation): EvaluationContext {
val context = super.createEvaluationContext(authentication, mi) as StandardEvaluationContext val context = super.createEvaluationContext(authentication, mi) as StandardEvaluationContext
val delegate = context.getRootObject().getValue() as MethodSecurityExpressionOperations val delegate = context.getRootObject().getValue() as MethodSecurityExpressionOperations