【发布时间】:2013-07-02 23:54:42
【问题描述】:
我已经在我的 struts2 应用程序上实现了 Spring 安全性,它运行良好,但它在第 3 行遇到错误 java.lang.NullPointerException。
虽然 passwordEncoder 配置似乎是通过添加那些我无法再使用纯文本密码登录的配置来工作的。
<authentication-manager>
<authentication-provider>
<password-encoder ref="passwordEncoder"/>
<jdbc-user-service data-source-ref="dataSource"
users-by-username-query="
select username,password,enabled
from Users where username=?"
authorities-by-username-query="
select username,authority
from Users where username = ?"
/>
</authentication-provider>
</authentication-manager>
<beans:bean id="passwordEncoder"
xmlns="http://www.springframework.org/schema/beans"
class="org.springframework.security.authentication.encoding.ShaPasswordEncoder">
<constructor-arg value="256"/>
</beans:bean>
</beans:beans>
MyClass.java
import org.springframework.security.authentication.encoding.ShaPasswordEncoder;;
....
private ShaPasswordEncoder passwordEncoder;
public ShaPasswordEncoder getPasswordEncoder() {
return passwordEncoder;
}
@Autowired
public void setPasswordEncoder(ShaPasswordEncoder passwordEncoder) {
this.passwordEncoder = passwordEncoder;
}
public void encode(String username)
{
1 System.err.println("encode password");
2 String encodedPassword = "";
3 encodedPassword = passwordEncoder.encodePassword("Jack",username);
4 System.err.println("encoded password " + encodedPassword);
}
pom.xml
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
【问题讨论】:
标签: jakarta-ee struts2 spring-security password-encryption