Question: I am using Spring Security for permission checking on methods. I would like to call a private method to collect some data to send to `hasPermission()` method. Following is something I am trying to execute and I get SpelEvaluationException because Spring is looking for the `localPrivateMethod` in `MethodSecurityExpressionRoot`. Is there a way to achieve this? Thanks.

```
@PreAuthorize("hasPermission(new Object[]{#arg3, #localPrivateMethod(#arg1,#arg2)}, 'canDoThis')")  
public long publicMethod1(long arg1, long arg2, long arg3) {}

private String localPrivateMethod(long a1, long a2) {}

```

Answer: 
Private methods cannot be called, but you can refer to "this component" through `this.`:

```
@PreAuthorize("hasPermission(new Object[]{#arg3, /* HERE: */ this.localPublicMethod(#arg1,#arg2)}, 'canDoThis')")   
public long publicMethod1(long arg1, long arg2, long arg3)
{
}

public String localPublicMethod(long a1, long a2)
{
}

```
It can be done in simple way using **@someController.localPublicMethod(#arg1,#arg2)**

no need to implement permissionEvaluator

```
@RestController
public class SomeController{

@PreAuthorize("hasPermission(new Object[]{#arg3, @someController.localPublicMethod(#arg1,#arg2)}, 'canDoThis')")  
public long publicMethod1(long arg1, long arg2, long arg3) {}

public String localPublicMethod(long a1, long a2) {}

}
}

```

localPublicMethod cannot be private

For Permission evaluator - There is better way to do it one can refer below link
<https://www.baeldung.com/spring-security-create-new-custom-security-expression>