加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

java – 使用Azure Active Directory作为Spring-boot REST服务

发布时间:2020-12-15 01:42:58 所属栏目:大数据 来源:网络整理
导读:我正在尝试实现基于Spring-boot的REST服务,该服务应该使用Azure AD作为OAuth2服务器进行客户端身份验证. 我注册了两个应用程序: 用作我的服务客户端的移动本机应用程序 休息服务作为后端. 应通过Azure AD对所有对后端应用程序的请求进行身份验证 使用OAuth2

我正在尝试实现基于Spring-boot的REST服务,该服务应该使用Azure AD作为OAuth2服务器进行客户端身份验证.

我注册了两个应用程序:

>用作我的服务客户端的移动本机应用程序
>休息服务作为后端.

应通过Azure AD对所有对后端应用程序的请求进行身份验证
使用OAuth2流程.

作为移动应用程序的一个实现我使用curl:

为了获得承载令牌,我使用https://login.microsoftonline.com/TENANT_ID/oauth2/token

curl -s -X POST https://login.microsoftonline.com/

其中$USER_NAME和$PASSWORD是Azure AD用户的凭据,$RESOURCE_ID是我的REST服务的SID,$CLIENT_ID是我的移动客户端的REST服务的SID.

Azure使用令牌数据成功返回JSON.

我的Oauth2配置后端应用程序:

@Configuration
@EnableResourceServer
public class OAuth2Config extends ResourceServerConfigurerAdapter {
 @Bean
    ResourceServerTokenServices resourceTokenServices() {
        RemoteTokenServices tokenServices = new RemoteTokenServices();
        tokenServices.setClientId(resourceId);
        tokenServices.setClientSecret(/*I do not have it*/resourcePassword);
        tokenServices.setCheckTokenEndpointUrl(/*I do not have it*/checkToken);
        return tokenServices;
    }

@Override
    public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
        resources.tokenServices(resourceTokenServices());
        resources.resourceId("rest_api");
    }

@Override
    public void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests().antMatchers("/**").authenticated();
    }
}

我的REST控制器:

@RestController
@RequestMapping("/data")
public class CustomerRestController {

    @RequestMapping(method = RequestMethod.GET)
    public SomeData getMyData(Principal principal){
        System.out.println("RESOURCE WAS REQUESTED BY " + principal.getName());
        return new SomeData(principal.getName());
    }
}

但我没有在端点列表中找到我的REST服务可用于检查持票人令牌和从Azure AD获取用户数据的任何URL.
此外,据我所知,它应该为我的REST服务提供某种凭据以使用Azure AD

我怎样才能找到所需的值或者我走错了路?

最佳答案
最后我得到了答案.

Azure AD使用JWT令牌进行授权,因此我必须使用此类令牌实现工作,而不是检查服务器上的令牌.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读