All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.aliyun.datahub.client.auth.AliyunAuthSigner Maven / Gradle / Ivy

There is a newer version: 2.25.6
Show newest version
package com.aliyun.datahub.client.auth;

import com.aliyun.datahub.client.http.HttpRequest;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class AliyunAuthSigner implements AuthSigner {
    private String accessId;
    private String accessKey;

    public AliyunAuthSigner(String accessId, String accessKey) {
        this.accessId = accessId;
        this.accessKey = accessKey;
    }

    @Override
    public String genAuthSignature(HttpRequest request) {
        Authorization.Request authRequest = new Authorization.Request()
                .setAccessId(accessId)
                .setAccessKey(accessKey)
                .setMethod(request.getMethod().name().toUpperCase())
                .setUrlPath(request.getPath())
                .setHeaders(request.getHeaders())
                .setQueryStrings(getNormParams(request.getQueryParams()));
        return Authorization.getAkAuthorization(authRequest);
    }

    private Map getNormParams(Map> queryParams) {
        Map params = new HashMap();
        for (Map.Entry> entry : queryParams.entrySet()) {
            if (entry.getValue() != null && !entry.getValue().isEmpty()) {
                params.put(entry.getKey(), String.valueOf(entry.getValue().get(0)));
            }
        }
        return params;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy