Guest User

Untitled

a guest
Jan 1st, 2019
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.23 KB | None | 0 0
  1. Error:
  2. ***************************
  3. APPLICATION FAILED TO START
  4. ***************************
  5.  
  6. Description:
  7.  
  8. The bean 'dataSource', defined in BeanDefinition defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class], could not be registered. A bean with that name has already been defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class] and overriding is disabled.
  9.  
  10. Action:
  11.  
  12. Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
  13.  
  14. spring:
  15. datasource:
  16. # type: com.zaxxer.hikari.HikariDataSource
  17. driver-class-name: com.mysql.jdbc.Driver
  18. url: jdbc:mysql://localhost:3306/test
  19. username: root
  20. password: root
  21.  
  22. jpa:
  23. hibernate:
  24. ddl-auto: update
  25. show-sql: true
  26.  
  27. security:
  28. oauth2:
  29. resource:
  30. filter-order: 3
  31.  
  32. @Data
  33. @Builder
  34. @NoArgsConstructor
  35. @AllArgsConstructor
  36. @Entity
  37. public class User {
  38. @Id
  39. @GeneratedValue(strategy = GenerationType.AUTO)
  40. private long id;
  41.  
  42. @Column
  43. private String username;
  44.  
  45. @Column(length = 60)
  46. @JsonIgnore
  47. private String password;
  48.  
  49. @Column
  50. private long salary;
  51.  
  52. @Column
  53. private int age;
  54. }
  55.  
  56. @Configuration
  57. @EnableWebSecurity
  58. @EnableGlobalMethodSecurity(prePostEnabled = true)
  59. public class SecurityConfig extends WebSecurityConfigurerAdapter {
  60.  
  61. @Resource(name = "userService")
  62. private UserDetailsService userDetailsService;
  63.  
  64. @Override
  65. @Bean
  66. public AuthenticationManager authenticationManagerBean() throws Exception {
  67. return super.authenticationManagerBean();
  68. }
  69.  
  70. @Autowired
  71. public void globalUserDetails(AuthenticationManagerBuilder auth) throws Exception {
  72. auth.userDetailsService(userDetailsService).passwordEncoder(encoder());
  73. }
  74.  
  75. @Override
  76. protected void configure(HttpSecurity http) throws Exception {
  77. http.csrf().disable().anonymous().disable().authorizeRequests().antMatchers("/api-docs/**").permitAll();
  78. }
  79.  
  80. @Bean
  81. public TokenStore tokenStore() {
  82. return new InMemoryTokenStore();
  83. }
  84.  
  85. @Bean
  86. public BCryptPasswordEncoder encoder() {
  87. return new BCryptPasswordEncoder();
  88. }
  89.  
  90. @Bean
  91. public FilterRegistrationBean corsFilter() {
  92. UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
  93. CorsConfiguration config = new CorsConfiguration();
  94. config.setAllowCredentials(true);
  95. config.addAllowedOrigin("*");
  96. config.addAllowedHeader("*");
  97. config.addAllowedMethod("*");
  98. source.registerCorsConfiguration("/**", config);
  99.  
  100. FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));
  101. bean.setOrder(0);
  102. return bean;
  103. }
  104. }
  105.  
  106. @Configuration
  107. @EnableResourceServer
  108. public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
  109.  
  110. private static final String RESOURCE_ID = "resource_id";
  111.  
  112. @Override
  113. public void configure(ResourceServerSecurityConfigurer resources) {
  114. resources.resourceId(RESOURCE_ID).stateless(false);
  115. }
  116.  
  117. @Override
  118. public void configure(HttpSecurity http) throws Exception {
  119. http.anonymous().disable()
  120. .authorizeRequests().antMatchers("/users/**").access("hasRole('ADMIN')")
  121. .and()
  122. .exceptionHandling().accessDeniedHandler(new OAuth2AccessDeniedHandler());
  123. }
  124. }
  125.  
  126. @Configuration
  127. @EnableAuthorizationServer
  128. public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {
  129.  
  130. static final String CLIEN_ID = "devglan-client";
  131. static final String CLIENT_SECRET = "devglan-secret";
  132. static final String GRANT_TYPE_PASSWORD = "password";
  133. static final String AUTHORIZATION_CODE = "authorization_code";
  134. static final String REFRESH_TOKEN = "refresh_token";
  135. static final String IMPLICIT = "implicit";
  136. static final String SCOPE_READ = "read";
  137. static final String SCOPE_WRITE = "write";
  138. static final String TRUST = "trust";
  139. static final int ACCESS_TOKEN_VALIDITY_SECONDS = 1 * 60 * 60;
  140. static final int FREFRESH_TOKEN_VALIDITY_SECONDS = 6 * 60 * 60;
  141.  
  142. @Autowired
  143. private TokenStore tokenStore;
  144.  
  145. @Autowired
  146. private AuthenticationManager authenticationManager;
  147.  
  148. @Override
  149. public void configure(ClientDetailsServiceConfigurer configurer) throws Exception {
  150.  
  151. configurer.inMemory().withClient(CLIEN_ID).secret(CLIENT_SECRET)
  152. .authorizedGrantTypes(GRANT_TYPE_PASSWORD, AUTHORIZATION_CODE, REFRESH_TOKEN, IMPLICIT)
  153. .scopes(SCOPE_READ, SCOPE_WRITE, TRUST)
  154. .accessTokenValiditySeconds(ACCESS_TOKEN_VALIDITY_SECONDS)
  155. .refreshTokenValiditySeconds(FREFRESH_TOKEN_VALIDITY_SECONDS);
  156. }
  157.  
  158. @Override
  159. public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
  160. endpoints.tokenStore(tokenStore).authenticationManager(authenticationManager);
  161. }
  162. }
  163.  
  164. <dependency>
  165. <groupId>org.springframework.boot</groupId>
  166. <artifactId>spring-boot-starter-data-jpa</artifactId>
  167. <exclusions>
  168. <exclusion>
  169. <groupId>com.zaxxer</groupId>
  170. <artifactId>HikariCP</artifactId>
  171. </exclusion>
  172. </exclusions>
  173. </dependency>
Add Comment
Please, Sign In to add comment