Skip to content

Commit

Permalink
Correct link issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelMiquelino committed Oct 23, 2020
1 parent fb56a3d commit 48605bd
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/traccar/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public static void init(String configFile) throws Exception {
ldapProvider = new LdapProvider(config);
}

if (config.getBoolean(Keys.OidcAuthEnable)) {
if (config.getBoolean(Keys.OIDCAUTHENABLE)) {
oidcProvider = new OidcProvider(config);
}

Expand Down
30 changes: 15 additions & 15 deletions src/main/java/org/traccar/authorization/OidcProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,32 @@ public class OidcProvider {

private static final Logger LOGGER = LoggerFactory.getLogger(OidcProvider.class);

private String OidcAuthIss;
private String OidcAuthAud;
private String OidcJwksFormat;
private String oidcAuthIss;
private String oidcAuthAud;
private String oidcJwksFormat;
private SigningKeyResolver signingKeyResolver;
private int UsersDefaultDeviceLimit;
private int UsersDefaultExpirationDays;
private int usersDefaultDeviceLimit;
private int usersDefaultExpirationDays;

public OidcProvider(Config config) {
this.OidcAuthIss = config.getString(Keys.OidcAuthIss);
this.OidcAuthAud = config.getString(Keys.OidcAuthAud);
this.OidcJwksFormat = config.getString(Keys.OidcJwksFormat, "standard");
switch (OidcJwksFormat.toLowerCase()) {
this.oidcAuthIss = config.getString(Keys.OIDCAUTHISS);
this.oidcAuthAud = config.getString(Keys.OIDCAUTHAUD);
this.oidcJwksFormat = config.getString(Keys.OIDCJWKSFORMAT, "standard");
switch (oidcJwksFormat.toLowerCase()) {
case "x5cset":
this.signingKeyResolver = new X5cSetSigningKeyResolver(config);
default:
this.signingKeyResolver = new StdJwksSigningKeyResolver(config);
}
this.UsersDefaultDeviceLimit = config.getInteger(Keys.UsersDefaultDeviceLimit, -1);
this.UsersDefaultExpirationDays = config.getInteger(Keys.UsersDefaultExpirationDays);
this.usersDefaultDeviceLimit = config.getInteger(Keys.USERSDEFAULTDEVICELIMIT, -1);
this.usersDefaultExpirationDays = config.getInteger(Keys.USERSDEFAULTEXPIRATIONDAYS);
}

public Claims validateToken(String tokenString) {
try {
return Jwts.parserBuilder()
.requireIssuer(OidcAuthIss)
.requireAudience(OidcAuthAud)
.requireIssuer(oidcAuthIss)
.requireAudience(oidcAuthAud)
.setSigningKeyResolver(signingKeyResolver)
.build()
.parseClaimsJws(tokenString)
Expand All @@ -59,9 +59,9 @@ public User getUser(Claims claims) {
user.setName(claims.get("name", String.class));
user.setEmail(claims.get("email", String.class));
user.setAdministrator(false);
user.setDeviceLimit(UsersDefaultDeviceLimit);
user.setDeviceLimit(usersDefaultDeviceLimit);
user.setExpirationTime(
new Date(System.currentTimeMillis() + (long) UsersDefaultExpirationDays * 24 * 3600 * 1000)
new Date(System.currentTimeMillis() + (long) usersDefaultExpirationDays * 24 * 3600 * 1000)
);
return user;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ public class StdJwksSigningKeyResolver extends SigningKeyResolverAdapter {

private static final Logger LOGGER = LoggerFactory.getLogger(StdJwksSigningKeyResolver.class);

private String OidcJwksUri;
private String oidcJwksUri;

public StdJwksSigningKeyResolver(Config config) {
this.OidcJwksUri = config.getString(Keys.OidcJwksUri, null);
this.oidcJwksUri = config.getString(Keys.OIDCJWKSURI, null);
}

@Override
Expand All @@ -39,11 +39,10 @@ public Key resolveSigningKey(JwsHeader jwsHeader, Claims claims) {

private PublicKey getSigningKey(String kid) throws Exception {

JwkProvider provider = new JwkProviderBuilder(new URL(OidcJwksUri))
JwkProvider provider = new JwkProviderBuilder(new URL(oidcJwksUri))
.cached(10, 24, TimeUnit.HOURS)
.rateLimited(10, 1, TimeUnit.MINUTES)
.build();
;
Jwk jwk = provider.get(kid);

return jwk.getPublicKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ public class X5cSetSigningKeyResolver extends SigningKeyResolverAdapter {

private static final Logger LOGGER = LoggerFactory.getLogger(X5cSetSigningKeyResolver.class);

private String OidcJwksUri;
private String oidcJwksUri;

public X5cSetSigningKeyResolver(Config config) {
this.OidcJwksUri = config.getString(Keys.OidcJwksUri, null);
this.oidcJwksUri = config.getString(Keys.OIDCJWKSURI, null);
}

@Override
Expand All @@ -46,7 +46,7 @@ private PublicKey getSigningKey(String kid) throws CertificateException {

JsonObject jwks = Context
.getClient()
.target(OidcJwksUri)
.target(oidcJwksUri)
.request()
.get(JsonObject.class);

Expand Down
14 changes: 7 additions & 7 deletions src/main/java/org/traccar/config/Keys.java
Original file line number Diff line number Diff line change
Expand Up @@ -423,29 +423,29 @@ public final class Keys {
public static final ConfigKey WEB_REQUEST_LOG_RETAIN_DAYS = new ConfigKey(
"web.requestLog.retainDays", Integer.class);

public static final ConfigKey OidcAuthEnable = new ConfigKey(
public static final ConfigKey OIDCAUTHENABLE = new ConfigKey(
"oidc.enable", Boolean.class);

public static final ConfigKey OidcAuthAud = new ConfigKey(
public static final ConfigKey OIDCAUTHAUD = new ConfigKey(
"oidc.aud", String.class);

public static final ConfigKey OidcAuthIss = new ConfigKey(
public static final ConfigKey OIDCAUTHISS = new ConfigKey(
"oidc.iss", String.class);

public static final ConfigKey OidcJwksUri = new ConfigKey(
public static final ConfigKey OIDCJWKSURI = new ConfigKey(
"oidc.jwksUri", String.class);

/**
* JSON Web Key (JWK) set format. Used for jwt validation.
* If nothing is provided, format is according to rfc7517
*/
public static final ConfigKey OidcJwksFormat = new ConfigKey(
public static final ConfigKey OIDCJWKSFORMAT = new ConfigKey(
"oidc.jwksStd", String.class);

public static final ConfigKey UsersDefaultDeviceLimit = new ConfigKey(
public static final ConfigKey USERSDEFAULTDEVICELIMIT = new ConfigKey(
"users.defaultDeviceLimit", Integer.class);

public static final ConfigKey UsersDefaultExpirationDays = new ConfigKey(
public static final ConfigKey USERSDEFAULTEXPIRATIONDAYS = new ConfigKey(
"users.defaultExpirationDays", Integer.class);

private Keys() {
Expand Down

0 comments on commit 48605bd

Please sign in to comment.