Skip to content

Commit c75f5c5

Browse files
committed
Reworked signer mechanism
1 parent 66ace70 commit c75f5c5

12 files changed

Lines changed: 1941 additions & 1954 deletions

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>com.xero</groupId>
55
<artifactId>xero-java-sdk</artifactId>
66
<packaging>jar</packaging>
7-
<version>0.4.7</version>
7+
<version>0.5.0-PLEO</version>
88
<name>Xero-Java SDK</name>
99
<url>http://maven.apache.org</url>
1010
<dependencies>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.xero.api;
2+
3+
import com.google.api.client.auth.oauth.OAuthSigner;
4+
5+
public class ConfigBasedSignerFactory implements SignerFactory {
6+
private static final String PUBLIC_APP = "PUBLIC";
7+
private Config config;
8+
9+
public ConfigBasedSignerFactory(Config config) {
10+
this.config = config;
11+
}
12+
13+
@Override
14+
public OAuthSigner createSigner(String tokenSharedSecret) {
15+
if (config.getAppType().equals(PUBLIC_APP)) {
16+
return new HmacSignerFactory(config.getConsumerSecret()).createSigner(tokenSharedSecret);
17+
} else {
18+
return new RsaSignerFactory(config.getPathToPrivateKey(), config.getPrivateKeyPassword()).createSigner(
19+
tokenSharedSecret);
20+
}
21+
}
22+
}

src/main/java/com/xero/api/HmacSigner.java

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.xero.api;
2+
3+
import com.google.api.client.auth.oauth.OAuthHmacSigner;
4+
5+
public class HmacSignerFactory implements SignerFactory {
6+
7+
private String consumerSecret;
8+
9+
public HmacSignerFactory(String consumerSecret) {
10+
this.consumerSecret = consumerSecret;
11+
}
12+
13+
@Override
14+
public OAuthHmacSigner createSigner(String tokenSecret) {
15+
OAuthHmacSigner signer = new OAuthHmacSigner();
16+
signer.tokenSharedSecret = tokenSecret;
17+
signer.clientSharedSecret = consumerSecret;
18+
return signer;
19+
}
20+
}

0 commit comments

Comments
 (0)