简体   繁体   English

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

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

I have a spring mvc web app that has an API, that looks like this 我有一个带有API的spring mvc网络应用,看起来像这样

/api/createUser?name=Tom . /api/createUser?name=Tom

At the same time there is a web site backed by the same web app, that has restricted pages, which can only be accessed once the a user authorizes using login form + Active Directory. 同时,存在一个由同一Web应用程序支持的网站,该网站具有受限制的页面,只有在用户使用登录表单+ Active Directory授权后,才能访问该网站。 I have managed to set up AD and it works well, but I am kinda lost with the API. 我已经成功设置了AD,并且效果很好,但是我对API有点迷。

I want to make an authentication for API calls too. 我也想对API调用进行身份验证。 Namely, I want to introduce username and password fields to every API call, so that when the relevant controller receives this API call, it first authenticates the user programmatically and it succeeded, then proceeds further with the request. 即,我想在每个API调用中引入usernamepassword字段,以便当相关控制器接收到此API调用时,它首先以编程方式对用户进行身份验证并成功,然后进一步处理请求。

So the question is, how can I authenticate a user programmatically outright from MVC controller in Spring? 所以问题是,如何在Spring中从MVC控制器中以编程方式直接验证用户? Is there any magic bean that I can inject and harness its power? 有什么魔豆可以注入并利用它的力量吗?

I think you could use spring sercurity 我认为您可以使用春季安全性

<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