Search in sources :

Example 1 with DefaultProfile

use of com.aliyuncs.profile.DefaultProfile in project aliyun-oss-java-sdk by aliyun.

the class CredentialsProviderFactory method newSTSKeyPairSessionCredentialsProvider.

/**
 * Create an instance of InstanceProfileCredentialsProvider based on RSA key
 * pair.
 *
 * @param regionId
 *            RAM's available area, for more information about regionId, see
 *            <a href="https://help.aliyun.com/document_detail/40654.html">
 *            RegionIdList</a>.
 * @param publicKeyId
 *            Public Key ID.
 * @param privateKey
 *            Private Key.
 * @return A {@link StsKeyPairCredentialsProvider} instance.
 * @throws ClientException
 *             OSS Client side exception.
 */
public static STSKeyPairSessionCredentialsProvider newSTSKeyPairSessionCredentialsProvider(String regionId, String publicKeyId, String privateKey) throws ClientException {
    DefaultProfile profile = DefaultProfile.getProfile(regionId);
    KeyPairCredentials keyPairCredentials = new KeyPairCredentials(publicKeyId, privateKey);
    return new STSKeyPairSessionCredentialsProvider(keyPairCredentials, profile);
}
Also used : DefaultProfile(com.aliyuncs.profile.DefaultProfile) KeyPairCredentials(com.aliyuncs.auth.KeyPairCredentials)

Example 2 with DefaultProfile

use of com.aliyuncs.profile.DefaultProfile in project aliyun-oss-java-sdk by aliyun.

the class AuthUtils method deletePublicKey.

/**
 * Delete the uploaded public key.
 *
 * @param regionId
 *            RAM's available area.
 * @param accessKeyId
 *            Access Key ID of the root user.
 * @param accessKeySecret
 *            Secret Access Key of the root user.
 * @param publicKeyId
 *            Public Key Id.
 * @throws ClientException
 */
public static void deletePublicKey(String regionId, String accessKeyId, String accessKeySecret, String publicKeyId) throws ClientException {
    DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
    DefaultAcsClient client = new DefaultAcsClient(profile);
    DeletePublicKeyRequest deletePublicKeyRequest = new DeletePublicKeyRequest();
    deletePublicKeyRequest.setUserPublicKeyId(publicKeyId);
    client.getAcsResponse(deletePublicKeyRequest);
}
Also used : DefaultProfile(com.aliyuncs.profile.DefaultProfile) DefaultAcsClient(com.aliyuncs.DefaultAcsClient) DeletePublicKeyRequest(com.aliyuncs.ram.model.v20150501.DeletePublicKeyRequest)

Example 3 with DefaultProfile

use of com.aliyuncs.profile.DefaultProfile in project fc-java-sdk by aliyun.

the class PopClient method openFCService.

public OpenFunctionComputeResponse openFCService(Config config, OpenFunctionComputeRequest request) throws ClientException, ServerException {
    request.validate();
    try {
        String accessKeyId = config.getAccessKeyID();
        String accessSecret = config.getAccessKeySecret();
        DefaultProfile profile = null;
        if (StringUtils.isBlank(config.getSecurityToken())) {
            profile = DefaultProfile.getProfile(OPEN_FC_SERVICE_REGION, accessKeyId, accessSecret);
        } else {
            String sToken = config.getSecurityToken();
            profile = DefaultProfile.getProfile(OPEN_FC_SERVICE_REGION, accessKeyId, accessSecret, sToken);
        }
        OpenFcServiceRequest openFCServiceRequest = new OpenFcServiceRequest();
        IAcsClient client = new DefaultAcsClient(profile);
        openFCServiceRequest.setSysEndpoint(OPEN_FC_SERVICE_ENDPOINT);
        OpenFcServiceResponse openFCServiceResponse = client.getAcsResponse(openFCServiceRequest);
        OpenFunctionComputeResponse response = new OpenFunctionComputeResponse();
        response.setRequestId(openFCServiceResponse.getRequestId());
        response.setOrderId(openFCServiceResponse.getOrderId());
        return response;
    } catch (com.aliyuncs.exceptions.ClientException e) {
        if (StringUtils.contains(e.getErrMsg(), "已开通")) {
            OpenFunctionComputeResponse response = new OpenFunctionComputeResponse();
            response.setRequestId(e.getRequestId());
            response.setCode(ERROR_CODE_ORDER_OPENED);
            response.setMsg("You have subscribed FunctionCompute, please proceed to FC console and start using it.");
            return response;
        }
        throw new ClientException(e.getErrCode(), e.getErrMsg(), e.getRequestId());
    }
}
Also used : OpenFunctionComputeResponse(com.aliyuncs.fc.response.OpenFunctionComputeResponse) DefaultProfile(com.aliyuncs.profile.DefaultProfile) DefaultAcsClient(com.aliyuncs.DefaultAcsClient) OpenFcServiceResponse(com.aliyuncs.fc_open.model.v20200310.OpenFcServiceResponse) OpenFcServiceRequest(com.aliyuncs.fc_open.model.v20200310.OpenFcServiceRequest) IAcsClient(com.aliyuncs.IAcsClient) ClientException(com.aliyuncs.fc.exceptions.ClientException)

Example 4 with DefaultProfile

use of com.aliyuncs.profile.DefaultProfile in project aliyun-oss-java-sdk by aliyun.

the class AuthUtils method uploadPublicKey.

/**
 * Upload the public key of RSA key pair.
 *
 * @param regionId
 *            RAM's available area.
 * @param accessKeyId
 *            Access Key ID of the root user.
 * @param accessKeySecret
 *            Secret Access Key of the root user.
 * @param publicKey
 *            Public key content.
 * @return Public key description, include public key id etc.
 * @throws ClientException
 */
public static PublicKey uploadPublicKey(String regionId, String accessKeyId, String accessKeySecret, String publicKey) throws ClientException {
    DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
    DefaultAcsClient client = new DefaultAcsClient(profile);
    UploadPublicKeyRequest uploadPublicKeyRequest = new UploadPublicKeyRequest();
    uploadPublicKeyRequest.setPublicKeySpec(publicKey);
    UploadPublicKeyResponse uploadPublicKeyResponse = client.getAcsResponse(uploadPublicKeyRequest);
    com.aliyuncs.ram.model.v20150501.UploadPublicKeyResponse.PublicKey pubKey = uploadPublicKeyResponse.getPublicKey();
    return new PublicKey(pubKey);
}
Also used : DefaultProfile(com.aliyuncs.profile.DefaultProfile) DefaultAcsClient(com.aliyuncs.DefaultAcsClient) PublicKey(com.aliyun.oss.common.auth.PublicKey) UploadPublicKeyRequest(com.aliyuncs.ram.model.v20150501.UploadPublicKeyRequest) UploadPublicKeyResponse(com.aliyuncs.ram.model.v20150501.UploadPublicKeyResponse)

Example 5 with DefaultProfile

use of com.aliyuncs.profile.DefaultProfile in project aliyun-oss-java-sdk by aliyun.

the class AuthUtils method listPublicKeys.

/**
 * List the public keys that has been uploaded.
 *
 * @param regionId
 *            RAM's available area.
 * @param accessKeyId
 *            Access Key ID of the root user.
 * @param accessKeySecret
 *            Secret Access Key of the root user.
 * @return Public keys.
 * @throws ClientException
 */
public static List<PublicKey> listPublicKeys(String regionId, String accessKeyId, String accessKeySecret) throws ClientException {
    DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
    DefaultAcsClient client = new DefaultAcsClient(profile);
    ListPublicKeysRequest listPublicKeysRequest = new ListPublicKeysRequest();
    ListPublicKeysResponse listPublicKeysResponse = client.getAcsResponse(listPublicKeysRequest);
    List<PublicKey> publicKeys = new ArrayList<PublicKey>();
    for (com.aliyuncs.ram.model.v20150501.ListPublicKeysResponse.PublicKey publicKey : listPublicKeysResponse.getPublicKeys()) {
        publicKeys.add(new PublicKey(publicKey));
    }
    return publicKeys;
}
Also used : DefaultProfile(com.aliyuncs.profile.DefaultProfile) DefaultAcsClient(com.aliyuncs.DefaultAcsClient) PublicKey(com.aliyun.oss.common.auth.PublicKey) ArrayList(java.util.ArrayList) ListPublicKeysRequest(com.aliyuncs.ram.model.v20150501.ListPublicKeysRequest) ListPublicKeysResponse(com.aliyuncs.ram.model.v20150501.ListPublicKeysResponse)

Aggregations

DefaultProfile (com.aliyuncs.profile.DefaultProfile)6 DefaultAcsClient (com.aliyuncs.DefaultAcsClient)4 PublicKey (com.aliyun.oss.common.auth.PublicKey)2 IAcsClient (com.aliyuncs.IAcsClient)1 KeyPairCredentials (com.aliyuncs.auth.KeyPairCredentials)1 ClientException (com.aliyuncs.fc.exceptions.ClientException)1 OpenFunctionComputeResponse (com.aliyuncs.fc.response.OpenFunctionComputeResponse)1 OpenFcServiceRequest (com.aliyuncs.fc_open.model.v20200310.OpenFcServiceRequest)1 OpenFcServiceResponse (com.aliyuncs.fc_open.model.v20200310.OpenFcServiceResponse)1 DeletePublicKeyRequest (com.aliyuncs.ram.model.v20150501.DeletePublicKeyRequest)1 ListPublicKeysRequest (com.aliyuncs.ram.model.v20150501.ListPublicKeysRequest)1 ListPublicKeysResponse (com.aliyuncs.ram.model.v20150501.ListPublicKeysResponse)1 UploadPublicKeyRequest (com.aliyuncs.ram.model.v20150501.UploadPublicKeyRequest)1 UploadPublicKeyResponse (com.aliyuncs.ram.model.v20150501.UploadPublicKeyResponse)1 ArrayList (java.util.ArrayList)1