在Spring Boot应用中,我们经常需要实现用户认证和授权来保护我们的应用程序。为了简化开发过程,我们可以使用Spring Security框架来处理这些任务。

我们需要在pom.xml文件中添加Spring Security的依赖:
```org.springframework.bootspring-boot-starter-security
```

然后,我们可以创建一个配置类来配置Spring Security:
```
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests()
                .antMatchers("/admin/**").hasRole("ADMIN")
                .antMatchers("/user/**").hasRole("USER")
                .anyRequest().authenticated()
                .and()
            .formLogin()
                .loginPage("/login")
                .defaultSuccessUrl("/index")
                .and()
            .logout()
                .logoutUrl("/logout")
                .logoutSuccessUrl("/login?logout")
                .and()
            .csrf().disable();
    }
    
    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth
            .inMemoryAuthentication()
                .withUser("admin").password("{noop}password").roles("ADMIN")
                .and()
                .withUser("user").password("{noop}password").roles("USER");
    }
}
```

在上面的配置类中,我们通过`configure()`方法来定义URL的访问规则和相关的认证配置。我们使用`.antMatchers()`方法来匹配URL,并使用`.hasRole()`方法来限制只有具有特定角色的用户才能访问。

我们还通过`configureGlobal()`方法配置了两个用户,一个是管理员(role为"ADMIN"),一个是普通用户(role为"USER")。这里我们使用了内存认证,实际项目中应该使用数据库或LDAP等进行用户认证。

我们可以在需要保护的Controller类或方法中使用`@PreAuthorize`注解来限制访问权限。例如:
```
@Controller
public class UserController {
    @GetMapping("/user")
    @PreAuthorize("hasRole('USER')")
    public String userHome() {
        return "user_home";
    }
}
```

通过上述步骤,我们可以在Spring Boot应用中轻松实现用户认证和授权,保护我们的应用程序的安全性。