【问题标题】:authentication AWS method Rest DSL身份验证 AWS 方法 Rest DSL
【发布时间】:2018-03-14 17:21:12
【问题描述】:

我有一个关于Restful 服务

的问题

我需要将 CSV 文件上传到 AWS 服务器。我已注册帐户。 首先,我需要获取访问令牌并使用它来上传文件。我还没有编写任何代码,试图理解最好的方法,我希望使用 Camel-Rest-DSL。它需要与 JSON 通信。但是,身份验证部分让我卡住了,我很确定它使用 OAuth2 身份验证、RestFul Web 服务和 JSON,这应该只是一个客户端,我正在为 JAX-RS OAuth2 寻找 WSS4J 但我不知道。

我已经用邮递员完成了,这就是场景。用户名和密码是虚构的

    *Get Access Token  
                    uses POST verb
                    requires Token Request URL
    uses Basic Auth  requires Username = Client ID of tenant ( needs to be encoded base64 )
    HEADER parm Content-Type = x-www-form-urlencoded
    Content-Type': 'application/x-www-form-urlencoded',
                   'Authorization': 'Basic ' + encoded Client ID
    Access Token body - grant_type, username, password
    Body = username = 5c0642fe-a495-44db-93f7-67034556fa2c061_ingestor
                    password = 154f0252d166f27b5e21ef171b03212a79f41a0daf3
                    grant_type = password

    #returns the access_token as JSON

    POST or upload files
    uses POST verb
    requires Ingestion URL UploadURL

    UploadURL=https://apm-ts-query-svc-prd.app-api.aws-usw02-pr.something.io/v2/time_series/
    UploadFolder=upload
    headers = 
    key Authentication  "Bearer + access Token" (from request access token above)
    key Tenant = TenantUUID
    key X-GE-CsvFormat = ODB

    # Body
    form-data
    key file=file
    # POST DATA
    headers content-type application/json
                   authorization: "" + token
                   tenant: "" + tenant

我的环境

Jboss 保险丝 6.3-310

Karaf 版本 2.4.0.redhat-630310

JVM Java 虚拟机 Java HotSpot(TM) 64 位服务器 VM 版本 25.162-

b12 版本 1.8.0_162 供应商甲骨文公司

操作系统 命名Linux版本2.6.32-696.20.1.el6.x86_64

【问题讨论】:

  • 您能否尝试重新格式化您的问题,使其在代码与普通文本之间更具可读性和格式正确。
  • @ClausIbsen 我已经完成了编辑,但它在等待同行评审的队列中等待......如果您可以访问这样的队列,您可以查看一下(直到(如果)我的编辑被批准)
  • 谢谢Claus和Rushikumar,对不起,我下次会搞定的。
  • 我正在验证是否可以使用 AOuth2、SAML2 或 JWT 来管理 UAA 开发团队的令牌访问。我可能会走运。谢谢。

标签: json rest oauth-2.0 apache-camel jax-rs


【解决方案1】:

我不能使用 OAuth2/SAML 断言,所以我将简单地请求一个令牌并将其缓存并稍后使用它。这是我的测试代码

    @Override 
    public void configure() throws Exception { 

        //Configure the Rest Web Service Component transport to use a REST implementation
        restConfiguration() //Configures the REST DSL to use a specific REST implementation
            .component("jetty")         //Specifies the Camel component to use as the REST transport
            .host("localhost")          //The hostname to use for exposing the REST service
            .port("8282")           //The port number to use for exposing the REST service JMX tooling
            .scheme("https")            //The protocol to use for exposing the REST service
            .contextPath("/oauth/token")        //Sets a leading context path for the REST services
            .bindingMode(RestBindingMode.json)  //Enables binding mode for JSON 
            .jsonDataFormat("json-jackson")     //Specifies the component that Camel uses to implement the JSON data format
            .dataFormatProperty("prettyPrint", "true"); //set arbitrary properties on the underlying data format component

        //Configure the Rest Endpoint
        rest("/oauth")      //Defines a service using the REST DSL. Each of the verb clauses are terminated by a to() keyword,
                            //which forwards the incoming message to an endpoint 
            .post("/token")
            .produces("application/json")
            .consumes("application/json")
            .type(TokenEntities.class)
            .route()
            .routeId("Get Auth Token Route")
            .autoStartup(true)
            .id("Get Auth Token Service")
            .description("Get Authorization Token")
            .process(new UAARequestTokenProcessor())
            .to("https://d1e53858-2903-4c21-86c0-95edc7a5cef2.pager-uaa.run.aws-usw02-pr.ice.pager.io/oauth/token")
            .to("log:logger?showBody=true")
            .to("direct:accessToken")
            .endRest();

        //Define the Route - from() Defines a regular Camel route.
        from("direct:accessToken").to("log:logger?showBody=true"); }

public class UAARequestTokenProcessor implements Processor {

private static final Logger LOG = LoggerFactory.getLogger(UAARequestTokenProcessor.class);

private String clientId = "myClientID";
private String userName = "myUserName";
private String password = "myPassword";

@Override
public void process(Exchange exchange) throws Exception {

        LOG.info("Processing UAA token request for " + clientId + " and " + userName);

        Message msg = exchange.getOut(); //create outbound message exchange

        StringBuilder authHeader = new StringBuilder("Basic ");       
        authHeader.append(Base64.getEncoder().encodeToString((clientId + ":").getBytes("UTF_8")));

        String body = String.format("grant_type=password&username=%s&password=%s",
                  URLEncoder.encode(userName, "UTF-8"), //Translates a string into x-www-form-urlencoded format
                  URLEncoder.encode(password, "UTF-8"));

         msg.setHeader(Exchange.CONTENT_TYPE, "MediaType.APPLICATION_FORM_URLENCODE");
         msg.setHeader("Authorization", authHeader.toString());
         msg.setBody(body);
    }

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-18
    • 1970-01-01
    • 1970-01-01
    • 2016-05-24
    • 2011-07-15
    • 2021-12-21
    • 2012-03-06
    • 2016-10-22
    相关资源
    最近更新 更多