java - 使用 rest web 服务的 spring security 登录

标签 java rest spring-security single-sign-on

我的公司有一个特定的身份验证提供程序,它是一个内部 REST 网络服务。 事实上,您向 Web 服务提供了一个登录名/密码,它会返回一个 token (有效期为几个小时),该 token 必须在每个下一个对 Web 服务的业务请求的 header 中提供。

我需要创建一个 Web 应用程序,并且需要将其插入到此身份验证提供程序中。 将其与 Spring Security 集成的最佳方式是什么?

如何在不要求用户重新登录的情况下管理我的网络应用程序中的 token 过期?

最佳答案

如果要使用 spring security 并将身份验证委托(delegate)给 web 服务,则需要实现 spring security 框架提供的 AuthenticationProvider 接口(interface)。你可以做这样的事情

 public class AuthProviderImpl implements AuthenticationProvider 
 {
      @Override
   public Authentication authenticate(Authentication authentication)
     throws AuthenticationException 
        {
          WebServiceAuthClient client = //get an handle to your web service
          //get user name, password from authenticate object
          client.autheticat(username, pwd);
        }

 }

配置您的 Web 应用程序以使用 Spring Security http://static.springsource.org/spring-security/site/petclinic-tutorial.html

关于java - 使用 rest web 服务的 spring security 登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6828344/

相关文章:

grails - 在grails中的Ajax调用期间, Spring 安全性中的 session 超时

grails - 使用 BCrypt 密码哈希与 Spring Security Grails 插件

grails - Grails 3 InterceptUrlMap,它可以工作吗?

java - 如何下载图像并将其放入 Android 的 View 中

java - WebLogic 的 JAAS 配置

java - Heroku 无法找到 XML 配置文件

java - Apache 速度 : org. apache.velocity.exception.ResourceNotFoundException

java - 创建 json Rest api,无需编写或集成任何代码

java - Jersey 如何迭代参数?

java - (Java) 在运行时动态创建新的 REST Web 服务