小编Ser*_*erg的帖子

解析自定义控制器中的实体URI(Spring HATEOAS)

我有一个基于spring-data-rest的项目,它也有一些自定义端点.

为了发送POST数据,我正在使用json

{
 "action": "REMOVE",
 "customer": "http://localhost:8080/api/rest/customers/7"
}
Run Code Online (Sandbox Code Playgroud)

这对于s​​pring-data-rest来说很好,但不适用于自定义控制器.

例如:

public class Action {
    public ActionType action;
    public Customer customer;
}

@RestController
public class ActionController(){
  @Autowired
  private ActionService actionService;

  @RestController
  public class ActionController {
  @Autowired
  private ActionService actionService;

  @RequestMapping(value = "/customer/action", method = RequestMethod.POST)
  public ResponseEntity<ActionResult> doAction(@RequestBody Action action){
    ActionType actionType = action.action;
    Customer customer = action.customer;//<------There is a problem
    ActionResult result = actionService.doCustomerAction(actionType, customer);
    return ResponseEntity.ok(result);
  }
}
Run Code Online (Sandbox Code Playgroud)

我打电话的时候

curl -v -X POST -H "Content-Type: application/json" -d '{"action": "REMOVE","customer": …
Run Code Online (Sandbox Code Playgroud)

java rest spring spring-data-rest spring-hateoas

18
推荐指数
2
解决办法
3967
查看次数

使用Azure Active Directory作为Spring-boot REST服务的OAUTH2身份验证服务

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

我注册了两个应用程序:

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

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

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

要获得Bearer令牌,请使用https://login.microsoftonline.com/TENANT_ID/oauth2/token

curl -s -X POST https://login.microsoftonline.com/<TENANT_ID>/oauth2/token -d grant_type=password -d username=$USER_NAME -d password=$PASSWORD -d resource=$RESOURCE_ID -d client_id=$CLIENT_ID
Run Code Online (Sandbox Code Playgroud)

其中$ 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) …
Run Code Online (Sandbox Code Playgroud)

java rest spring azure

5
推荐指数
1
解决办法
3311
查看次数

标签 统计

java ×2

rest ×2

spring ×2

azure ×1

spring-data-rest ×1

spring-hateoas ×1