SpEL for spring security: passing values ​​from XML-based Spel configuration in Java

I want to pass property values ​​assigned in an XML file to a Spring (SpEL) expression in Java. Can you tell me how to achieve this? To make it clear, I gave the following example.

example.xml file:

<beans>
    <bean id="user" class="x.y.User">
        <property name="name" value="A"/>
        <property name="userId" value="33"/>

    <bean id="customer" class="x.y.Customer">
        <property name="name" value="B"/>
        <property name="customerId" value="33"/>      
    </bean>   
</beans>

Keep in mind that I have user and client model classes.

I want to protect a method called "edit" with the Pre-Authorize annotation and Spring expressions as follows.

@PreAuthorize("(#user.userId == #customer.customerId)")    
public Boolean edit(User user, Customer custmer)  {              
    return true; 
}

The question is, how do I pass the userId and customerId values ​​from the example.xml file into the above expression to compare the two values ​​and then protect the “edit” method?

. . , , . !

+1
3

beans SpEL @.

, , SpEL beans, . :

<beans>
    <bean id="userBean" class="x.y.User">
        <property name="name" value="A"/>
        <property name="userId" value="33"/>

    <bean id="customerBean" class="x.y.Customer">
        <property name="name" value="B"/>
        <property name="customerId" value="33"/>      
    </bean>   
</beans>

, User userId of 33 ( userBean userId).

@PreAuthorize("#user.userId == @userBean.userId")    
public Boolean edit(User user, Customer custmer)  {              
    return true; 
}

, customerBean ( XML) :

@PreAuthorize("#custmer.userId == @customerBean.userId")    
public Boolean edit(User user, Customer custmer)  {              
    return true; 
}

, XML, . , @ bean.

@PreAuthorize("#user.userId == @user.userId")    
public Boolean edit(User user, Customer custmer)  {              
    return true; 
}
+1

@Rob, . "edit" , userBean userId customerBean customerId . , :

@PreAuthorize("@userBean.userId == @customerBean.customerId")    
public Boolean edit(User user, Customer custmer)  {              
    return true; 
}   

:

java.lang.IllegalArgumentException: Failed to evaluate expression '(@userBean.userId == @customerBean.customerId)'

?

. @userBean.userId @user.userId @customerBean.customerId @customer.customerId

+1

spring bean?

0
source