Guest User

Untitled

a guest
Apr 25th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. @Override
  2. protected void configure(HttpSecurity http) throws Exception {
  3. // .csrf().disable()
  4. http
  5. .exceptionHandling()
  6. .authenticationEntryPoint(new Http401AuthenticationEntryPoint("App header"))
  7. .and()
  8. .authenticationProvider(getProvider())
  9. .formLogin()
  10. .loginProcessingUrl("/logins/login")
  11. .successHandler(new SimpleUrlAuthenticationSuccessHandler())
  12. .failureHandler(new SimpleUrlAuthenticationFailureHandler())
  13. .and().httpBasic();
  14.  
  15. http.logout()
  16. .logoutUrl("/logout")
  17. .logoutSuccessHandler(new AuthentificationLogoutSuccessHandler())
  18. .invalidateHttpSession(true)
  19. .and().httpBasic();
  20. http.authorizeRequests()
  21. .antMatchers("/docs").hasAnyRole(Role.USER.name(), Role.ADMIN.toString())
  22. .antMatchers("/logins/login").permitAll()
  23. .antMatchers("/logout").permitAll()
  24. .anyRequest().authenticated().and()
  25. .requestCache()
  26. .requestCache(new NullRequestCache())
  27. .and().httpBasic();
  28.  
  29. System.out.println(" 1 : " + Role.USER.name() + " --- " + Role.USER.toString());
  30. }
  31.  
  32. [ X-Frame-Options=[DENY],
  33. Transfer-Encoding=[chunked],
  34. Strict-Transport-Security=[max-age=31536000 ; includeSubDomains],
  35. Cache-Control=[private],
  36. X-Content-Type-Options=[nosniff],
  37. Set-Cookie=[JSESSIONID=615FD3642011AE7558D598255D10C85E; Path=/; Secure; HttpOnly],
  38. Expires=[Thu, 01 Jan 1970 01:00:00 CET],
  39. X-XSS-Protection=[1; mode=block],
  40. Date=[Wed, 25 Apr 2018 21:35:16 GMT],
  41. Content-Type=[application/json;charset=UTF-8]]
  42.  
  43. HttpClient httpClient = HttpClients.custom()
  44. .disableCookieManagement()
  45. .build();
  46. Unirest.setHttpClient(httpClient);
  47.  
  48. Predicate<? super Map.Entry<String, List<String>>> prdct = (key) ->{
  49. return key.getKey().equals("Set-Cookie");
  50. };
  51. final String jSessionID = asJson.getHeaders().entrySet().stream().filter(prdct).findFirst().get().getValue().get(0);
  52. System.out.println("jsession id "+jSessionID.split(";")[0]);
  53. Unirest.setDefaultHeader("Cookie", jSessionID.split(";")[0]);
  54. Unirest.setDefaultHeader("authorization", "Basic " + value);
  55. Unirest.setDefaultHeader("Content-Type", "application/json");
  56.  
  57. {"timestamp":"2018-04-25T21:35:32.659+0000","status":403,"error":"Forbidden","message":"Forbidden","path":"/user/1"}
Add Comment
Please, Sign In to add comment