Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.10 KB | None | 0 0
  1. @PostMapping(consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, value = "/v1/notification")
  2. public ResponseEntity<String> handleNotifications(@RequestBody MultiValueMap<String, Object> keyValuePairs) {
  3. .....
  4. return new ResponseEntity<>(HttpStatus.OK);
  5. }
  6.  
  7. @SpringBootApplication(scanBasePackages = { "org.rest.api.*", "org.plugin.service", "org.plugin.transactions.factory" })
  8. @EntityScan("org.plugin.entity")
  9. @EnableJpaRepositories("org.plugin.service")
  10. @EnableScheduling
  11. public class Application extends SpringBootServletInitializer implements WebMvcConfigurer {
  12.  
  13. @Override
  14. protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
  15. return application.sources(Application.class);
  16. }
  17.  
  18. public static void main(String[] args) {
  19. SpringApplication.run(Application.class, args);
  20. }
  21.  
  22. @Override
  23. public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
  24. converters.removeIf(converter -> converter instanceof MappingJackson2XmlHttpMessageConverter);
  25. converters.removeIf(converter -> converter instanceof MappingJackson2HttpMessageConverter);
  26. converters.add(new MappingJackson2XmlHttpMessageConverter(
  27. ((XmlMapper) createObjectMapper(Jackson2ObjectMapperBuilder.xml()))
  28. .enable(ToXmlGenerator.Feature.WRITE_XML_DECLARATION)));
  29. converters.add(new MappingJackson2HttpMessageConverter(createObjectMapper(Jackson2ObjectMapperBuilder.json())));
  30. }
  31.  
  32. private ObjectMapper createObjectMapper(Jackson2ObjectMapperBuilder builder) {
  33. builder.indentOutput(true);
  34. builder.modules(new JaxbAnnotationModule());
  35. builder.serializationInclusion(JsonInclude.Include.NON_NULL);
  36. builder.defaultUseWrapper(false);
  37. return builder.build();
  38. }
  39. }
  40.  
  41. <h1>Forbidden <span>(403)</span></h1>
  42. <p>CSRF verification failed. Request aborted.</p>
  43. <p>You are seeing this message because this site requires a CSRF cookie when submitting forms. This cookie is required for security reasons, to ensure that your browser is not being hijacked by third parties.</p>
  44. <p>If you have configured your browser to disable cookies, please re-enable them, at least for this site, or for &#39;same-origin&#39; requests.</p>
  45.  
  46. @Configuration
  47. @EnableWebSecurity
  48. @Import(value = { Application.class, ContextDatasource.class })
  49. @ComponentScan(basePackages = { "org.rest.api.server.*" })
  50. public class ApplicationSecurityConfig extends WebSecurityConfigurerAdapter {
  51.  
  52. @Autowired
  53. private RestAuthEntryPoint authenticationEntryPoint;
  54.  
  55. @Autowired
  56. MerchantAuthService myUserDetailsService;
  57.  
  58. @Autowired
  59. public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
  60. auth.userDetailsService(myUserDetailsService);
  61. auth.authenticationProvider(authenticationProvider());
  62. }
  63.  
  64. @Bean
  65. public DaoAuthenticationProvider authenticationProvider() {
  66. DaoAuthenticationProvider authenticationProvider = new DaoAuthenticationProvider();
  67. authenticationProvider.setUserDetailsService(myUserDetailsService);
  68. authenticationProvider.setPasswordEncoder(passwordEncoder());
  69. return authenticationProvider;
  70. }
  71.  
  72. @Override
  73. protected void configure(HttpSecurity http) throws Exception {
  74. http.authorizeRequests().antMatchers("/notification").permitAll().anyRequest().permitAll();
  75. http.httpBasic().authenticationEntryPoint(authenticationEntryPoint);
  76. http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
  77. http.csrf().disable();
  78. }
  79.  
  80. @Bean
  81. public PasswordEncoder passwordEncoder() {
  82. return NoOpPasswordEncoder.getInstance();
  83. }
  84. }
  85.  
  86. <parent>
  87. <groupId>org.springframework.boot</groupId>
  88. <artifactId>spring-boot-starter-parent</artifactId>
  89. <version>2.1.6.RELEASE</version>
  90. </parent>
  91. ....
  92. <dependency>
  93. <groupId>org.springframework.security</groupId>
  94. <artifactId>spring-security-config</artifactId>
  95. </dependency>
  96. <dependency>
  97. <groupId>org.springframework.security</groupId>
  98. <artifactId>spring-security-web</artifactId>
  99. </dependency>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement