use of com.aliyun.oss.common.auth.Credentials in project aliyun-oss-java-sdk by aliyun.
the class EnvironmentVariableCredentialsProviderTest method testGetEnvironmentVariableCredentials.
@Test
public void testGetEnvironmentVariableCredentials() {
try {
// unset evn
List<String> envSet = new ArrayList<String>();
envSet.add(AuthUtils.ACCESS_KEY_ENV_VAR);
envSet.add(AuthUtils.SECRET_KEY_ENV_VAR);
envSet.add(AuthUtils.SESSION_TOKEN_ENV_VAR);
unsetEnv(envSet);
// set env
Map<String, String> envMap = new HashMap<String, String>(System.getenv());
envMap.put(AuthUtils.ACCESS_KEY_ENV_VAR, TestConfig.ROOT_ACCESS_KEY_ID);
envMap.put(AuthUtils.SECRET_KEY_ENV_VAR, TestConfig.ROOT_ACCESS_KEY_SECRET);
setEnv(envMap);
// env provider
EnvironmentVariableCredentialsProvider credentialsProvider = new EnvironmentVariableCredentialsProvider();
Credentials credentials = credentialsProvider.getCredentials();
Assert.assertEquals(credentials.getAccessKeyId(), TestConfig.ROOT_ACCESS_KEY_ID);
Assert.assertEquals(credentials.getSecretAccessKey(), TestConfig.ROOT_ACCESS_KEY_SECRET);
Assert.assertFalse(credentials.useSecurityToken());
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.common.auth.Credentials in project aliyun-oss-java-sdk by aliyun.
the class SystemPropertiesCredentialsProviderTest method testSystemPropertiesCredentialsProvider.
@Test
public void testSystemPropertiesCredentialsProvider() {
try {
System.setProperty(AuthUtils.ACCESS_KEY_SYSTEM_PROPERTY, TestConfig.ROOT_ACCESS_KEY_ID);
System.setProperty(AuthUtils.SECRET_KEY_SYSTEM_PROPERTY, TestConfig.ROOT_ACCESS_KEY_SECRET);
SystemPropertiesCredentialsProvider credentialsProvider = new SystemPropertiesCredentialsProvider();
Credentials credentials = credentialsProvider.getCredentials();
Assert.assertEquals(credentials.getAccessKeyId(), TestConfig.ROOT_ACCESS_KEY_ID);
Assert.assertEquals(credentials.getSecretAccessKey(), TestConfig.ROOT_ACCESS_KEY_SECRET);
Assert.assertFalse(credentials.useSecurityToken());
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.common.auth.Credentials in project aliyun-oss-java-sdk by aliyun.
the class CustomSessionCredentialsProviderTest method testGetCredentialsNegative.
@Test
public void testGetCredentialsNegative() {
try {
CustomSessionCredentialsProvider credentialsProvider = new CustomSessionCredentialsProvider(TestConfig.OSS_AUTH_SERVER_HOST + "/noteixst");
Credentials credentials = credentialsProvider.getCredentials();
Assert.assertNull(credentials);
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.common.auth.Credentials in project aliyun-oss-java-sdk by aliyun.
the class CustomSessionCredentialsProviderTest method testGetCredentialsServerHalt.
@Test
public void testGetCredentialsServerHalt() {
try {
CustomSessionCredentialsFetcher credentialsFetcher = new CustomSessionCredentialsFetcherMock(TestConfig.OSS_AUTH_SERVER_HOST).withResponseCategory(ResponseCategory.ServerHalt);
CustomSessionCredentialsProvider credentialsProvider = new CustomSessionCredentialsProvider(TestConfig.OSS_AUTH_SERVER_HOST).withCredentialsFetcher(credentialsFetcher);
Credentials credentials = credentialsProvider.getCredentials();
Assert.assertNull(credentials);
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.common.auth.Credentials in project aliyun-oss-java-sdk by aliyun.
the class LiveChannelOperation method generateRtmpUri.
public String generateRtmpUri(GenerateRtmpUriRequest request) throws OSSException, ClientException {
assertParameterNotNull(request, "request");
String bucketName = request.getBucketName();
String liveChannelName = request.getLiveChannelName();
String playlistName = request.getPlaylistName();
Long expires = request.getExpires();
assertParameterNotNull(bucketName, "bucketName");
ensureBucketNameValid(bucketName);
assertParameterNotNull(liveChannelName, "liveChannelName");
ensureLiveChannelNameValid(liveChannelName);
assertParameterNotNull(playlistName, "playlistName");
assertParameterNotNull(expires, "expires");
Credentials currentCreds = this.credsProvider.getCredentials();
String accessId = currentCreds.getAccessKeyId();
String accessKey = currentCreds.getSecretAccessKey();
boolean useSecurityToken = currentCreds.useSecurityToken();
// Endpoint
RequestMessage requestMessage = new RequestMessage(bucketName, liveChannelName);
ClientConfiguration config = this.client.getClientConfiguration();
requestMessage.setEndpoint(OSSUtils.determineFinalEndpoint(this.endpoint, bucketName, config));
// Headers
requestMessage.addHeader(HttpHeaders.DATE, expires.toString());
// Parameters
requestMessage.addParameter(RequestParameters.PLAYLIST_NAME, playlistName);
if (useSecurityToken) {
requestMessage.addParameter(SECURITY_TOKEN, currentCreds.getSecurityToken());
}
// Signature
String canonicalResource = "/" + bucketName + "/" + liveChannelName;
String canonicalString = SignUtils.buildRtmpCanonicalString(canonicalResource, requestMessage, expires.toString());
String signature = ServiceSignature.create().computeSignature(accessKey, canonicalString);
// Build query string
Map<String, String> params = new LinkedHashMap<String, String>();
params.put(HttpHeaders.EXPIRES, expires.toString());
params.put(OSS_ACCESS_KEY_ID, accessId);
params.put(SIGNATURE, signature);
params.putAll(requestMessage.getParameters());
String queryString = HttpUtil.paramToQueryString(params, DEFAULT_CHARSET_NAME);
// Compose rtmp request uri
String uri = requestMessage.getEndpoint().toString();
String livChan = RequestParameters.SUBRESOURCE_LIVE + "/" + liveChannelName;
if (uri.startsWith(OSSConstants.PROTOCOL_HTTP)) {
uri = uri.replaceFirst(OSSConstants.PROTOCOL_HTTP, OSSConstants.PROTOCOL_RTMP);
} else if (uri.startsWith(OSSConstants.PROTOCOL_HTTPS)) {
uri = uri.replaceFirst(OSSConstants.PROTOCOL_HTTPS, OSSConstants.PROTOCOL_RTMP);
} else if (!uri.startsWith(OSSConstants.PROTOCOL_RTMP)) {
uri = OSSConstants.PROTOCOL_RTMP + uri;
}
if (!uri.endsWith("/")) {
uri += "/";
}
uri += livChan + "?" + queryString;
return uri;
}
Aggregations