本人初出茅庐菜鸟一枚,希望把自己在工作中遇到的问题,并如何解决的记录下来希望对大家都能有所帮助。
和公司有合作关系的另外一个公司和我们整合了,希望调用我们的接口可以无需注册直接访问(两家的用户数据已经同步)。但是登录对方账户时,密码已经进行了MD5编码,调用我们的接口传参数后会又再次对password进行编码。我接到的任务解决这个问题,提供一个不在进行MD5编码的方法。
公司之前对password转码时用的spring Security,的
spring-security.xml 配置如下
<!-- 指定一个自定义的authentication-manager :filterSecurityUser --> <authentication-manager alias="authenticationManager"> <authentication-provider user-service-ref="filterSecurityUser"> <password-encoder ref="passwordEncoder"> </password-encoder> </authentication-provider> </authentication-manager> 这时候我想要再在authentication-manager 取另外一个别名使得传过来的password不用MD5转码。 <!-- 指定一个自定义的authentication-manager :filterUser --> <authentication-manager alias="authenticationMushRoomManager"> <authentication-provider user-service-ref="filterSecurityUser"> <password-encoder ref="passwordMushRoomEncoder"> </password-encoder> </authentication-provider> </authentication-manager>applicationContext.xml
<!-- security对密码进行MD5编码 --> <bean id="passwordEncoder" class="org.springframework.security.authentication.encoding.Md5PasswordEncoder"/> <!-- 明文 --> <bean id="passwordMushRoomEncoder" class="org.springframework.security.authentication.encoding.PlaintextPasswordEncoder"/>运行后报错,错误如下:
GalaContext erro! Error creating bean with name 'userCenterServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.security.authentication.AuthenticationManager com.gala.service.impl.UserCenterServiceImpl.authenticationMushRoomManager; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.security.authentication.AuthenticationManager] is defined: expected single matching bean but found 3: org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0,org.springframework.security.authentication.ProviderManager#0,org.springframework.security.authenticationManager org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userCenterServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.security.authentication.AuthenticationManager com.gala.service.impl.UserCenterServiceImpl.authenticationMushRoomManager; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.security.authentication.AuthenticationManager] is defined: expected single matching bean but found 3: org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0,org.springframework.security.authentication.ProviderManager#0,org.springframework.security.authenticationManager at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(Abst
经过查询发现
<authentication-manager alias="authenticationManager"> 默认的只能是一个,如果想要加另外一个必须用id <!-- 指定一个自定义的authentication-manager :filterUser --> <authentication-manager id="authenticationMushRoomManager"> <authentication-provider user-service-ref="filterSecurityUser"> <password-encoder ref="passwordMushRoomEncoder"> </password-encoder> </authentication-provider> </authentication-manager>当然在接口注入的时候要修改
@Autowired @Qualifier("authenticationMushRoomManager") AuthenticationManager authenticationMushRoomManager; @Autowired AuthenticationManager authenticationManager;以上就是解决问题的方法了,中间调试的时候总有问题,得感谢大神涛哥的帮助。希望能够尽快成长。