Entering property values ​​from a property file or xml file in PreAuthorize (...) java annotation (Unresolved)

I asked this question in my previous post here: SpEL for spring security: passing values ​​from XML-based Spel configuration in Java . But he was not yet permitted. I want to enter values ​​either from the xml configuration or from an external file into the annotation @PreAuthorize(...). This is not as easy as injecting using annotation @Value.

To answer the question, I provide the following information.

  • I have the following xml configuration file (example.xml) that has properties and initializes the corresponding values.

    <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>
    
  • (example.properties) / WEB-INF. XML, .

    user.id = 33
    customer.id =33
    
  • applicationContext.xml

    <context:property-placeholder location="/WEB-INF/*.properties" ignore-unresolvable="true" />
    
    <bean id="propertyConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
          p:location="/WEB-INF/example.properties" p:ignoreUnresolvablePlaceholders="true" />
    
  • : User Customer

    public class User {
        private int userId;
    
    public int getUserId() {
            return userId;
        }
    }
    
    public class Customer {
        private int customerId;
    
        public int getCustomerId(){
            return customerId;
        }
    }
    
  • /, 'edit' @PreAuthorize.

    The restriction: ( ) , 'userId' 'customerId' !.

    , :

    • 'userId' 'customerId' XML (example.xml) 1 . , (, !). Spring .

    • 'userId' 'customerId' (example.properties) 2 . , spring .

      @Service("..") or @Controller
      public class MyMainClass {
      
          //Expression 1
          @PreAuthorize("@userBean.userId == @customerBean.customerId")
              public Boolean edit(User user, Customer custmer)  {
          return true;
          }
      
          //Expression 2
          ////I've tried other ways as well, but end up with similar exceptions
          @PreAuthorize("${user.id} == ${customer.id}")
          public Boolean edit(User user, Customer customer)  {
              return true;
          }
      }
      

:

Q1. @PreAuthorize xml (example.xml) (example.properties) @PreAuthorize(...), ?

Q2. , , .

Q3. 1 000 000 , , !!!. , , !

+4
1

, <context:property-placeholder location="classpath:my.properties"/> xml , @Value, . my.properties some.userid=33, , :

@Value("${some.userid}")
private int someId;

ignoreUnresolvablePlaceholders false, , , , ...

, .

+4

All Articles