繁体   English   中英

通过REST服务API调用以编程方式通过Active Directory验证用户

[英]Authenticating users via Active Directory programmatically on REST service API call

我有一个带有API的spring mvc网络应用,看起来像这样

/api/createUser?name=Tom

同时,存在一个由同一Web应用程序支持的网站,该网站具有受限制的页面,只有在用户使用登录表单+ Active Directory授权后,才能访问该网站。 我已经成功设置了AD,并且效果很好,但是我对API有点迷。

我也想对API调用进行身份验证。 即,我想在每个API调用中引入usernamepassword字段,以便当相关控制器接收到此API调用时,它首先以编程方式对用户进行身份验证并成功,然后进一步处理请求。

所以问题是,如何在Spring中从MVC控制器中以编程方式直接验证用户? 有什么魔豆可以注入并利用它的力量吗?

我认为您可以使用春季安全性

<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.2.xsd">

<http auto-config="true">
    <intercept-url pattern="/api**" access="ROLE_USER" />
</http>

<authentication-manager>
  <authentication-provider>
    <user-service>
    <user name="username" password="password" authorities="ROLE_USER" />
    </user-service>
  </authentication-provider>
</authentication-manager>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM