Skip to content

Commit a373bff

Browse files
Revert "JWT_change1"
This reverts commit 8ffe48e.
1 parent 8ffe48e commit a373bff

File tree

1 file changed

+4
-46
lines changed

1 file changed

+4
-46
lines changed

JMS/com/ibm/mq/samples/jms/JmsPut.java

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@
3232

3333
import com.ibm.mq.jms.MQDestination;
3434

35-
import java.net.URI;
36-
import java.net.http.HttpClient;
37-
import java.net.http.HttpRequest;
38-
import java.net.http.HttpRequest.BodyPublishers;
39-
import java.net.http.HttpResponse;
40-
4135
// Use these imports for building with Jakarta Messaging
4236
// import jakarta.jms.Destination;
4337
// import jakarta.jms.JMSConsumer;
@@ -87,8 +81,8 @@ public static void main(String[] args) {
8781
JmsConnectionFactory connectionFactory = createJMSConnectionFactory();
8882
setJMSProperties(connectionFactory);
8983
logger.info("created connection factory");
90-
String access_token = obtainToken();
91-
context = connectionFactory.createContext(null , access_token);
84+
85+
context = connectionFactory.createContext();
9286
logger.info("context created");
9387

9488
// Set targetClient to be non JMS, so no JMS headers are transmitted.
@@ -178,8 +172,8 @@ private static void setJMSProperties(JmsConnectionFactory cf) {
178172
cf.setStringProperty(WMQConstants.WMQ_APPLICATIONNAME, APP_NAME);
179173
if (null != APP_USER && !APP_USER.trim().isEmpty()) {
180174
cf.setBooleanProperty(WMQConstants.USER_AUTHENTICATION_MQCSP, true);
181-
// cf.setStringProperty(WMQConstants.USERID, APP_USER);
182-
// cf.setStringProperty(WMQConstants.PASSWORD, APP_PASSWORD);
175+
cf.setStringProperty(WMQConstants.USERID, APP_USER);
176+
cf.setStringProperty(WMQConstants.PASSWORD, APP_PASSWORD);
183177
}
184178
if (CIPHER_SUITE != null && !CIPHER_SUITE.isEmpty()) {
185179
cf.setStringProperty(WMQConstants.WMQ_SSL_CIPHER_SUITE, CIPHER_SUITE);
@@ -219,40 +213,4 @@ private static void initialiseLogging() {
219213
logger.finest("Logging initialised");
220214
}
221215

222-
public static String obtainToken() {
223-
String access_token = "";
224-
String tokenEndpoint = System.getenv("JWT_TOKEN_ENDPOINT");
225-
String tokenUsername = System.getenv("JWT_TOKEN_USERNAME");
226-
String tokenPassword = System.getenv("JWT_TOKEN_PWD");
227-
String tokenClientId = System.getenv("JWT_TOKEN_CLIENTID");
228-
229-
//build the string with parameters provided as environment variables, to include in the POST request to the token issuer
230-
String postBuild = String.format("client_id=%s&username=%s&password=%s&grant_type=password",tokenClientId, tokenUsername, tokenPassword);
231-
logger.info("parameter string: " + postBuild);
232-
HttpClient client = HttpClient.newHttpClient();
233-
234-
HttpRequest request = HttpRequest.newBuilder()
235-
.uri(URI.create(
236-
// "<keycloak URL>/realms/master/protocol/openid-connect/token"
237-
tokenEndpoint
238-
))
239-
.POST(
240-
BodyPublishers.ofString(postBuild))
241-
.setHeader("Content-Type", "application/x-www-form-urlencoded")
242-
.build();
243-
logger.info("obtaining token from:" + tokenEndpoint);
244-
try {
245-
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
246-
logger.fine(String.valueOf(response.statusCode()));
247-
logger.fine(response.body());
248-
249-
JSONObject myJsonObject = new JSONObject(response.body());
250-
access_token = myJsonObject.getString("access_token");
251-
logger.info("Using token:" + access_token);
252-
} catch (Exception e) {
253-
logger.info("Using token:" + access_token);
254-
e.printStackTrace();
255-
}
256-
return access_token;
257-
}
258216
}

0 commit comments

Comments
 (0)