Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
111 views
in Technique[技术] by (71.8m points)

java - Spring security and() function

Can you please explain in a simple way for what reason we need to use and() method in HttpSecurity.

Code:

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests().antMatchers("/").hasAnyRole("Employee", "Manager", "HR")
            .antMatchers("/hr_info").hasRole("HR")
            .antMatchers("/manager_info/**").hasRole("Manager")
            .and().formLogin().permitAll();
}
question from:https://stackoverflow.com/questions/65906296/spring-security-and-function

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The spring security reference explains it as follows.

The Java Configuration equivalent of closing an XML tag is expressed using the and() method which allows us to continue configuring the parent. If you read the code it also makes sense. I want to configure authorized requests and configure form login and configure HTTP Basic authentication.

Accordingly, you say the following with your own settings:

  • Ensures that any request to our application requires the user to be authenticated,
  • Allows authentication for some links only to the specified role,
  • Allows users to authenticate with form based login.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...