Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- request to REST Service
- User-Agent: MyApp/1.0 (my-app-feedback@example.com)
- @Override
- protected void configure(HttpSecurity http) throws Exception {
- http
- .formLogin()
- .and()
- .httpBasic().disable()
- .anonymous().disable()
- .authorizeRequests().anyRequest().authenticated()
- }
- }
- protected void configure(AuthenticationManagerBuilder auth) throws Exception {
- log.info("Defining inMemoryAuthentication (2 users)");
- auth
- .inMemoryAuthentication()
- .withUser("user").password("password")
- .roles("USER")
- .and()
- .withUser("admin").password("password")
- .roles("USER", "ADMIN")
- }
- @Override
- protected void configure(final HttpSecurity http) throws Exception {
- http.authorizeRequests()
- .antMatchers("/anonymous*").anonymous()
- .antMatchers("/login*").permitAll()
- .anyRequest().authenticated()
- .and()
- .formLogin()
- .loginPage("/login.html")
- .loginProcessingUrl("/login")
- .failureUrl("/login.html?error=true")
- .and()
- .logout().deleteCookies("JSESSIONID")
- .and()
- .rememberMe().key("uniqueAndSecret")
- ;
- }
- @Controller
- public class MainController {
- ...
- // Login form
- @RequestMapping("/login.html")
- public String login() {
- return "login.html";
- }
- // Login form with error
- @RequestMapping("/login-error.html")
- public String loginError(Model model) {
- model.addAttribute("loginError", true);
- return "login.html";
- }
- }
- @RequestMapping("/messages/inbox")
- public ModelAndView findMessagesForUser(CsrfToken token) {
- SecurityContext context = SecurityContextHolder.getContext();
- Authentication authentication = context.getAuthentication();
- if (authentication != null && authentication.getPrincipal() instanceof UserDetails) {
- CustomUser customUser = (CustomUser) authentication.getPrincipal();
- // .. find messages for this user and return them ...
- }
- // todo
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement