Commits - Yash-777/MyWorld GitHub Wiki
Cipher encoder/decoder - using KeyGenerator with AES algorithm
correct the code which leads to duplicate bean
can we restrict bean to singletone, spring on every call of @Bean mean creates new object.
ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'customAuthenticationProvider' defined in class path resource [com/vorwerk/dspro/config/security/SecurityConfig.class]: Cannot register bean definition [Root bean: class [null]; scope=; abstract=false; lazyInit=null; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=securityConfig; factoryMethodName=customAuthenticationProvider; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [com/vorwerk/dspro/config/security/SecurityConfig.class]] for bean 'customAuthenticationProvider': There is already [Generic bean: class [com.vorwerk.dspro.config.security.CustomAuthenticationProvider]; scope=singleton; abstract=false; lazyInit=null; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [com\vorwerk\dspro\config\security\CustomAuthenticationProvider.class]] bound.
Description:
The bean 'customAuthenticationProvider', defined in class path resource [com/vorwerk/dspro/config/security/SecurityConfig.class], could not be registered. A bean with that name has already been defined in file [D:\Vorwork_DSPRO\VCE-25474\code_VCE_25474\dspro-api\target\classes\com\vorwerk\dspro\config\security\CustomAuthenticationProvider.class] and overriding is disabled.
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
@EnableWebSecurity @Order(3)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
AuthenticationHandler authenticationHandler;
@Bean(name = "customAuthenticationProvider")
@Order(1)
public AuthenticationProvider customAuthenticationProvider() {
return new CustomAuthenticationProvider();
}
@Override
@Bean
public AuthenticationManager authenticationManager() {
return new ProviderManager(Arrays.asList(customAuthenticationProvider()));
}
@Bean
public AuthenticationTokenFilter authenticationTokenFilter() {
AuthenticationTokenFilter filter = new AuthenticationTokenFilter();
filter.setAuthenticationManager(authenticationManager());
filter.setAuthenticationSuccessHandler(authenticationHandler);
filter.setAuthenticationFailureHandler(authenticationHandler);
filter.setAllowSessionCreation(true);
return filter;
}
@Bean
public BasicAuthenticationFilter basicAuthenticationFilter() {
return (BasicAuthenticationFilter) new DSProBasicAuthenticationFilter(authenticationManager());
}
}