簡體   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