File tree 4 files changed +19
-28
lines changed
main/java/com/aliyuncs/utils
4 files changed +19
-28
lines changed Original file line number Diff line number Diff line change @@ -10,38 +10,31 @@ public class AuthUtils {
10
10
private static volatile String environmentAccesskeySecret ;
11
11
private static volatile String environmentECSMetaData ;
12
12
private static volatile String environmentCredentialsFile ;
13
- private static volatile String privateKey ;
14
13
15
14
public static String getPrivateKey (String filePath ) {
16
- if (null == privateKey ) {
17
- synchronized (AuthUtils .class ) {
18
- if (null == privateKey ) {
19
- FileInputStream in = null ;
20
- byte [] buffer ;
21
- try {
22
- in = new FileInputStream (filePath );
23
- buffer = new byte [in .available ()];
24
- in .read (buffer );
25
- privateKey = new String (buffer , "UTF-8" );
26
- } catch (IOException e ) {
27
- e .printStackTrace ();
28
- } finally {
29
- if (in != null ) {
30
- try {
31
- in .close ();
32
- } catch (IOException e ) {
33
- e .printStackTrace ();
34
- }
35
- }
36
- }
15
+ FileInputStream in = null ;
16
+ byte [] buffer ;
17
+ try {
18
+ in = new FileInputStream (filePath );
19
+ buffer = new byte [in .available ()];
20
+ in .read (buffer );
21
+ return new String (buffer , "UTF-8" );
22
+ } catch (IOException e ) {
23
+ e .printStackTrace ();
24
+ return null ;
25
+ } finally {
26
+ if (in != null ) {
27
+ try {
28
+ in .close ();
29
+ } catch (IOException e ) {
30
+ e .printStackTrace ();
37
31
}
38
32
}
39
33
}
40
- return privateKey ;
41
34
}
42
35
36
+ @ Deprecated
43
37
public static void setPrivateKey (String key ) {
44
- privateKey = key ;
45
38
}
46
39
47
40
public static String getClientType () {
Original file line number Diff line number Diff line change @@ -174,15 +174,13 @@ public void createCredentialsProviderTest() throws
174
174
client .put (AuthConstant .INI_TYPE , AuthConstant .INI_TYPE_KEY_PAIR );
175
175
client .put (AuthConstant .INI_PUBLIC_KEY_ID , AuthConstant .INI_TYPE_KEY_PAIR );
176
176
client .put (AuthConstant .INI_PRIVATE_KEY , AuthConstant .INI_TYPE_KEY_PAIR );
177
- client .put (AuthConstant .INI_PRIVATE_KEY_FILE , AuthConstant .INI_TYPE_KEY_PAIR );
178
- AuthUtils .setPrivateKey ("test" );
177
+ client .put (AuthConstant .INI_PRIVATE_KEY_FILE , ProfileCredentialsProviderTest .class .getClassLoader ().getResource ("test" ).getPath ());
179
178
STSGetSessionAccessKeyCredentialsProvider stsGetSessionAccessKeyCredentialsProvider =
180
179
Mockito .mock (STSGetSessionAccessKeyCredentialsProvider .class );
181
180
Mockito .when (stsGetSessionAccessKeyCredentialsProvider .getCredentials ()).thenReturn (null );
182
181
Mockito .when (factory .createCredentialsProvider (Mockito .any (STSGetSessionAccessKeyCredentialsProvider .class ))).
183
182
thenReturn (stsGetSessionAccessKeyCredentialsProvider );
184
183
Assert .assertNull (createCredential .invoke (profileCredentialsProvider , client , factory ));
185
- AuthUtils .setPrivateKey (null );
186
184
187
185
client .clear ();
188
186
client .put (AuthConstant .INI_TYPE , AuthConstant .INI_TYPE_RAM );
Original file line number Diff line number Diff line change @@ -8,7 +8,6 @@ public class AuthUtilsTest {
8
8
@ Test
9
9
public void getPrivateKeyTest (){
10
10
new AuthUtils ();
11
- AuthUtils .setPrivateKey (null );
12
11
String path = AuthUtils .class .getClassLoader ().getResource ("project.properties" ).getPath ();
13
12
String privateKey = AuthUtils .getPrivateKey (path );
14
13
Assert .assertNotNull (privateKey );
Original file line number Diff line number Diff line change
1
+ private key content
You can’t perform that action at this time.
0 commit comments