Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

Commit

Permalink
fixes the sql statements for DBTokenStore.java
Browse files Browse the repository at this point in the history
  • Loading branch information
prb112 committed Nov 19, 2015
1 parent 116408a commit 39ce345
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
<property-name>forceTrustSSLCertificate</property-name>
<value>true</value>
</managed-property>

<!-- Application Key -->
<managed-property>
<property-name>appKey</property-name>
<value>app_123456789_1234560</value>
</managed-property>
</managed-bean>

<!-- SmartCloud OAuth 1.0 -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public class DBTokenStore implements TokenStore {
private String defaultJndiName = "jdbc/ibmsbt-dbtokenstore";
private TokenStoreEncryptor encryptorClass;

final static String TYPE = "DBTOKENSTORE";

public DBTokenStore() {
// setJdbcDriverClass("org.apache.derby.jdbc.EmbeddedDriver");
}
Expand Down Expand Up @@ -180,8 +182,10 @@ private AccessToken getConsumerToken(String appId, String serviceName, String us
try {
Connection connection = getConnectionUsingJNDI();
try {
//Issue 1478: Resolving issue with the Access Token
// Changed SELECT ACCESSTOKEN FROM USERTOKEN WHERE APPID = ? AND SERVICENAME = ? AND USERID = ? to the proper query
PreparedStatement stmt = connection
.prepareStatement("SELECT ACCESSTOKEN FROM USERTOKEN WHERE APPID = ? AND SERVICENAME = ? AND USERID = ?");
.prepareStatement("SELECT SBTKREP.CREDENTIALTOKEN FROM SBTKREP WHERE APPID = ? AND SERVICENAME = ? AND USERID = ?");
try {
stmt.setString(1, appId);
stmt.setString(2, serviceName);
Expand Down Expand Up @@ -216,20 +220,25 @@ private AccessToken getConsumerToken(String appId, String serviceName, String us
private void setConsumerToken(String appId, String serviceName, String consumerKey, String moduleId,
String tokenName, String userId, Object token) throws OAuthException {


try {
Connection connection = getConnectionUsingJNDI();
try {
//Issue 1478: Resolving issue with the Access Token
// Change INSERT INTO USERTOKEN VALUES (?, ?, ?, ?)
PreparedStatement ps = connection
.prepareStatement("INSERT INTO USERTOKEN VALUES (?, ?, ?, ?)");
.prepareStatement("INSERT INTO SBTKREP (APPID,SERVICENAME,TYPE,USERID,CREDENTIALTOKEN) VALUES (?, ?, ?, ?, ?)");
try {
ps.setString(1, appId);
ps.setString(2, serviceName);
ps.setString(3, userId);

ps.setString(3, TYPE); //added value for DBTokenStore
ps.setString(4, userId);

//Converts the AccessToken to a ByteStream and Encrypts it
byte[] data = convertToBytes(token);
data = getEncryptorClass().encrypt(data);

ps.setObject(4, data);
ps.setObject(5, data);
ps.executeUpdate();
} finally {
ps.close();
Expand All @@ -251,7 +260,7 @@ private void deleteConsumerToken(String appId, String serviceName, String userId
Connection connection = getConnectionUsingJNDI();
try {
PreparedStatement ps = connection
.prepareStatement("DELETE FROM USERTOKEN WHERE APPID = ? AND SERVICENAME = ? AND USERID = ?");
.prepareStatement("DELETE FROM SBTKREP WHERE APPID = ? AND SERVICENAME = ? AND USERID = ?");
try {
ps.setString(1, appId);
ps.setString(2, serviceName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1246,9 +1246,9 @@ protected void prepareRequest(HttpClient httpClient, HttpRequestBase httpRequest

//Sets the AppKey Header for the Given Request APPKEY
if(endpoint != null){
String appKey = endpoint.getAppKey();
String appKey = ((com.ibm.sbt.services.endpoints.AbstractEndpoint) endpoint).getAppKey();
if(appKey != null){
httpClient.addRequestHeader(APPKEY,appKey);
httpRequestBase.addHeader(APPKEY,appKey);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,12 +412,12 @@ public interface Endpoint {
/**
* gets the application key
*/
public String getAppKey();
//public String getAppKey();

/**
* gets the given appkey
*/
public void setAppKey(String appKey);
//public void setAppKey(String appKey);

/**
* Allows an endpoint to append query args to a proxied request.
Expand Down

0 comments on commit 39ce345

Please sign in to comment.