你可以使用Spring Security并创建一个自定义的AuthenticationProvider。您可以使用JNDI查找直接从Container自身获取authservice。
例子:
@Component
public class CustomAuthenticationProvider implements AuthenticationProvider {
@Autowired
private AuthService authService;
public Authentication authenticate(Authentication authentication)
throws AuthenticationException {
String name = authentication.getName();
String password = authentication.getCredentials().toString();
// use the credentials to try to authenticate against the third party system
if (authService(name, password)) {
List<GrantedAuthority> grantedAuths = new ArrayList<>();
return new UsernamePasswordAuthenticationToken(name, password, grantedAuths);
} else {
throw new AuthenticationException("Unable to auth against third party systems");
}
}
@Override
public boolean supports(Class<?> authentication) {
return authentication.equals(UsernamePasswordAuthenticationToken.class);
}
而且,这里使用Spring阅读更多关于RESTful API中:
http://www.baeldung.com/rest-with-spring-series/
我约上我的现有应用程序的顶部添加春季安全主要关注的是兼容现有的身份验证系统......或需要进行大规模更改才能使其工作。 – rcheuk 2014-09-30 17:38:33
现有认证系统的体系结构是什么? – br1337 2014-09-30 17:42:17
习俗,据我所知。一对夫妇控制器处理用户的会话,根据需要调用后端来登录用户并确定用户的权限(这会影响用户看到的屏幕) – rcheuk 2014-09-30 17:51:01