Spring Security 與 MongoDB 身份驗證

NoSQL,Spring Security
Remote
0
07:37 AM · Nov 30 ,2025

1. 概述

Spring Security 提供不同的身份驗證系統,例如通過數據庫和 UserDetailService

與其使用  JPA 持久層,我們也可以考慮使用,例如一個  MongoDB 倉庫。 在本教程中,我們將看到如何使用 Spring Security 和 MongoDB 認證用户。

2. Spring Security Authentication with MongoDB

Similar to using a JPA repository, we can use a MongoDB repository。但是,我們需要配置不同的設置才能使用它。

2.1. Maven Dependencies

For this tutorial, we’re going to use Embedded MongoDB。但是,MongoDB 實例和 Testcontainer 可能是生產環境的有效選項。首先,讓我們添加 spring-boot-starter-data-mongodbde.flapdoodle.embed.mongo.spring30x 依賴項:


<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
    <groupId>de.flapdoodle.embed</groupId>
    <artifactId>de.flapdoodle.embed.mongo.spring30x</artifactId>
    <version>4.11.0</version>
</dependency>

2.2. Configuration

Once we set dependencies, we need configure our AuthenticationManager with, for example, an HTTP basic authentication:

@Configuration
@EnableWebSecurity
@EnableMethodSecurity(securedEnabled = true, jsr250Enabled = true)
public class SecurityConfig {

    //....

    public SecurityConfig(UserDetailsService userDetailsService) {
        this.userDetailsService = userDetailsService;
    }

    @Bean
    public AuthenticationManager customAuthenticationManager(HttpSecurity http) throws Exception {
        AuthenticationManagerBuilder authenticationManagerBuilder = http.getSharedObject(AuthenticationManagerBuilder.class);
        authenticationManagerBuilder.userDetailsService(userDetailsService)
            .passwordEncoder(bCryptPasswordEncoder());
        return authenticationManagerBuilder.build();
    }

    @Bean
    public BCryptPasswordEncoder bCryptPasswordEncoder() {
        return new BCryptPasswordEncoder();
    }

    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
        http.csrf(AbstractHttpConfigurer::disable)
            .authorizeHttpRequests(Customizer.withDefaults())
            .httpBasic(Customizer.withDefaults())
            .authorizeHttpRequests(authorizationManagerRequestMatcherRegistry -> authorizationManagerRequestMatcherRegistry.anyRequest().permitAll())
            .sessionManagement(httpSecuritySessionManagementConfigurer -> httpSecuritySessionManagementConfigurer.sessionCreationPolicy(SessionCreationPolicy.STATELESS));
        return http.build();
    }

}

2.3. User Domain and Repository

First, let’s define a simple user with roles for our authentication. We’ll have it implement the UserDetails interface to reuse commons methods of a Principal object:

@Document
public class User implements UserDetails {
    private @MongoId ObjectId id;
    private String username;
    private String password;
    private Set<UserRole> userRoles;
    // getters and setters
}

Now that we have our user, let’s define a simple repository:

public interface UserRepository extends MongoRepository<User, String> {

    @Query("{username:'?0'}")
    User findUserByUsername(String username);
}

2.4. Authentication Service

Finally, let’s implement our UserDetailService in order to retrieve a user and check if it’s authenticated:

@Service
public class MongoAuthUserDetailService implements UserDetailsService {
    // ...
    @Override
    public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException {

        com.baeldung.mongoauth.domain.User user = userRepository.findUserByUsername(userName);

        Set<GrantedAuthority> grantedAuthorities = new HashSet<>();

        user.getAuthorities()
          .forEach(role -> grantedAuthorities.add(new SimpleGrantedAuthority(role.getRole().getName())));

        return new User(user.getUsername(), user.getPassword(), grantedAuthorities);
    }

}

2.5. Test Authentication

To test our application, let’s define a simple controller. As an example, we’ve defined two different roles to test authentication and authorization for specific endpoints:

@RestController
public class ResourceController {

    @RolesAllowed("ROLE_ADMIN")
    @GetMapping("/admin")
    public String admin() {
        return "Hello Admin!";
    }

    @RolesAllowed({ "ROLE_ADMIN", "ROLE_USER" })
    @GetMapping("/user")
    public String user() {
        return "Hello User!";
    }

}

Let’s wrap it all up in a Spring Boot Test to check if our authentication works. As we can see, class MongoAuthApplicationTest { // set up @Test void givenUserCredentials_whenInvokeUserAuthorizedEndPoint_thenReturn200() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, PASSWORD))) .andExpect(status().isOk()); } @Test void givenUserNotExists_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic("not_existing_user", "password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_ चिंग_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void ಗೊGivenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").འgivenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user").with(httpBasic(USER_NAME, "wrong_password"))) .andExpect(status().isUnauthorized()); } @Test void givenUserExistsAndWrongPassword_whenInvokeEndPoint_thenReturn401() throws Exception { mvc.perform(get("/user"). отдельно } }

3. 結論

在本文中,我們探討了使用 Spring Security 進行 MongoDB 身份驗證。

我們已經瞭解瞭如何創建可工作的配置以及實現自定義 UserDetailService。我們還了解了如何模擬 MVC 上下文並測試身份驗證和授權。

user avatar
0 位用戶收藏了這個故事!
收藏

發佈 評論

Some HTML is okay.