Skip to content

Commit

Permalink
7569: Improve the implementation of Twitter plugin
Browse files Browse the repository at this point in the history
Reviewed-by: hirt
  • Loading branch information
Suchita Chaturvedi committed Mar 7, 2022
1 parent 559f902 commit cc2d381
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -123,12 +123,19 @@ public String getRequestToken(String consumerKey, String consumerKeySecret) {
}

public void authorization(String oauth_token) {

String url_open = OAUTH_AUTHORIZE_URL + "?oauth_token=" + oauth_token;
try {
java.awt.Desktop.getDesktop().browse(java.net.URI.create(url_open));
} catch (IOException e) {
LOGGER.log(Level.SEVERE, Messages.TriggerActionTwitterAuthorization_Exception, e);
if (oauth_token != null) {
try {
byte[] data = Base64.getUrlDecoder().decode(oauth_token);
oauth_token = Base64.getUrlEncoder().withoutPadding().encodeToString(data);
String url_open = OAUTH_AUTHORIZE_URL + "?oauth_token=" + oauth_token;
java.awt.Desktop.getDesktop().browse(new URI(url_open));
} catch (IOException e) {
LOGGER.log(Level.SEVERE, Messages.TriggerActionTwitterAuthorization_Exception, e);
} catch (URISyntaxException e) {
LOGGER.log(Level.SEVERE, Messages.TriggerActionTwitterAuthorization_Exception, e);
} catch (IllegalArgumentException e) {
LOGGER.log(Level.SEVERE, Messages.TriggerActionTwitterInvalidToken_Exception, e);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -41,7 +41,7 @@
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Random;
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
Expand All @@ -60,7 +60,6 @@ class TwitterOAuthHeaderGenerator {
private String tokenSecret;
private String version;

final static Random RANDOM = new Random();
final static Logger LOGGER = Logger.getLogger("TwitterOAuthHeaderGenerator");

public TwitterOAuthHeaderGenerator(String consumerKey, String consumerSecret, String token, String tokenSecret) {
Expand Down Expand Up @@ -181,15 +180,7 @@ private void append(StringBuilder builder, String key, String value) {
}

private String getNonce() {
int leftLimit = 48; // numeral '0'
int rightLimit = 122; // letter 'z'
int targetStringLength = 10;

synchronized (RANDOM) {
return RANDOM.ints(leftLimit, rightLimit + 1).filter(i -> (i <= 57 || i >= 65) && (i <= 90 || i >= 97))
.limit(targetStringLength)
.collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append).toString();
}
return UUID.randomUUID().toString().replaceAll("-", "");
}

private String getTimestamp() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -54,6 +54,7 @@ public class Messages extends NLS {
public static String TriggerActionTwitterInvalidUser_Title;
public static String TriggerActionTwitterInvalidUser_ErrorMessage;
public static String TriggerActionTwitterAuthorization_Exception;
public static String TriggerActionTwitterInvalidToken_Exception;
public static String TriggerActionTwitterAuthentication_Exception;
public static String TriggerActionTwitterRequestToken_Exception;
public static String TriggerActionTwitterURIParsing_Exception;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
Expand Down Expand Up @@ -46,6 +46,7 @@ TriggerActionTwitterUnauthorizedUser_Title=Unauthorized Twitter User
TriggerActionTwitterUnauthorizedUser_ErrorMessage=User {0} has not been authorized in Preferences
TriggerActionTwitterInvalidUser_Title=Invalid User
TriggerActionTwitterInvalidUser_ErrorMessage=The authorized user is invalid.
TriggerActionTwitterInvalidToken_Exception=Invalid token.
TriggerActionTwitterAuthorization_Exception=Unable to authorize.
TriggerActionTwitterAuthentication_Exception=Unable to authenticate.
TriggerActionTwitterRequestToken_Exception=Unable to get request token.
Expand Down

0 comments on commit cc2d381

Please sign in to comment.