diff --git a/core/src/main/java/org/keycloak/AbstractOAuthClient.java b/core/src/main/java/org/keycloak/AbstractOAuthClient.java index 9f082e9f24..3d16875408 100755 --- a/core/src/main/java/org/keycloak/AbstractOAuthClient.java +++ b/core/src/main/java/org/keycloak/AbstractOAuthClient.java @@ -2,7 +2,6 @@ package org.keycloak; import org.keycloak.util.KeycloakUriBuilder; -import java.security.KeyStore; import java.util.Map; import java.util.UUID; import java.util.concurrent.atomic.AtomicLong; @@ -12,7 +11,9 @@ import java.util.concurrent.atomic.AtomicLong; * @version $Revision: 1 $ */ public class AbstractOAuthClient { - public static final String OAUTH_TOKEN_REQUEST_STATE = "OAuth_Token_Request_State"; + private static final String OAUTH_TOKEN_REQUEST_STATE = "OAuth_Token_Request_State"; + private final AtomicLong counter = new AtomicLong(); + protected String clientId; protected Map credentials; protected String authUrl; @@ -23,8 +24,6 @@ public class AbstractOAuthClient { protected String stateCookiePath; protected boolean isSecure; protected boolean publicClient; - protected final AtomicLong counter = new AtomicLong(); - protected String getStateCode() { return counter.getAndIncrement() + "/" + UUID.randomUUID().toString(); } diff --git a/core/src/main/java/org/keycloak/KeycloakPrincipal.java b/core/src/main/java/org/keycloak/KeycloakPrincipal.java index e4aab9c71f..00848a2bc2 100755 --- a/core/src/main/java/org/keycloak/KeycloakPrincipal.java +++ b/core/src/main/java/org/keycloak/KeycloakPrincipal.java @@ -8,8 +8,8 @@ import java.security.Principal; * @version $Revision: 1 $ */ public class KeycloakPrincipal implements Principal, Serializable { - protected String name; - protected String surrogate; + protected final String name; + protected final String surrogate; public KeycloakPrincipal(String name, String surrogate) { this.name = name; diff --git a/core/src/main/java/org/keycloak/RSATokenVerifier.java b/core/src/main/java/org/keycloak/RSATokenVerifier.java index 9530442a7a..b4cb1cf390 100755 --- a/core/src/main/java/org/keycloak/RSATokenVerifier.java +++ b/core/src/main/java/org/keycloak/RSATokenVerifier.java @@ -27,7 +27,7 @@ public class RSATokenVerifier { } if (!verified) throw new VerificationException("Token signature not validated"); - AccessToken token = null; + AccessToken token; try { token = input.readJsonContent(AccessToken.class); } catch (IOException e) { diff --git a/core/src/main/java/org/keycloak/jose/jws/JWSHeader.java b/core/src/main/java/org/keycloak/jose/jws/JWSHeader.java index 105ef04ad3..30fcb5d609 100755 --- a/core/src/main/java/org/keycloak/jose/jws/JWSHeader.java +++ b/core/src/main/java/org/keycloak/jose/jws/JWSHeader.java @@ -1,6 +1,5 @@ package org.keycloak.jose.jws; -import org.codehaus.jackson.annotate.JsonIgnore; import org.codehaus.jackson.annotate.JsonProperty; import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.map.annotate.JsonSerialize; diff --git a/core/src/main/java/org/keycloak/jose/jws/crypto/HMACProvider.java b/core/src/main/java/org/keycloak/jose/jws/crypto/HMACProvider.java index 00c6a308ef..f73f14e9da 100755 --- a/core/src/main/java/org/keycloak/jose/jws/crypto/HMACProvider.java +++ b/core/src/main/java/org/keycloak/jose/jws/crypto/HMACProvider.java @@ -15,7 +15,7 @@ import java.security.NoSuchAlgorithmException; * @version $Revision: 1 $ */ public class HMACProvider { - public static String getJavaAlgorithm(Algorithm alg) { + private static String getJavaAlgorithm(Algorithm alg) { switch (alg) { case HS256: return "HMACSHA256"; @@ -28,7 +28,7 @@ public class HMACProvider { } } - public static Mac getMAC(final Algorithm alg) { + private static Mac getMAC(final Algorithm alg) { try { return Mac.getInstance(getJavaAlgorithm(alg)); diff --git a/core/src/main/java/org/keycloak/provider/ProviderFactoryLoader.java b/core/src/main/java/org/keycloak/provider/ProviderFactoryLoader.java index 798a88cc7c..8c3f62a262 100644 --- a/core/src/main/java/org/keycloak/provider/ProviderFactoryLoader.java +++ b/core/src/main/java/org/keycloak/provider/ProviderFactoryLoader.java @@ -11,7 +11,7 @@ import java.util.Set; */ public class ProviderFactoryLoader implements Iterable> { - private Map> factories = new HashMap>(); + private final Map> factories = new HashMap>(); private ProviderFactoryLoader(ServiceLoader serviceLoader) { for (ProviderFactory p : serviceLoader) { @@ -59,9 +59,9 @@ public class ProviderFactoryLoader implements Iterable implements ProviderFactory { - private volatile boolean initialized = false; + private final ProviderFactory factory; - private ProviderFactory factory; + private volatile boolean initialized = false; private LazyProviderFactory(ProviderFactory factory) { this.factory = factory; diff --git a/core/src/main/java/org/keycloak/representations/adapters/action/LogoutAction.java b/core/src/main/java/org/keycloak/representations/adapters/action/LogoutAction.java index 35576bdc16..6b73234b38 100755 --- a/core/src/main/java/org/keycloak/representations/adapters/action/LogoutAction.java +++ b/core/src/main/java/org/keycloak/representations/adapters/action/LogoutAction.java @@ -15,6 +15,7 @@ public class LogoutAction extends AdminAction { public LogoutAction(String id, int expiration, String resource, String user, int notBefore) { super(id, expiration, resource, LOGOUT); this.user = user; + this.notBefore = notBefore; } public String getUser() { diff --git a/core/src/main/java/org/keycloak/representations/adapters/action/SessionStats.java b/core/src/main/java/org/keycloak/representations/adapters/action/SessionStats.java index 84d08c1837..f6644335c6 100755 --- a/core/src/main/java/org/keycloak/representations/adapters/action/SessionStats.java +++ b/core/src/main/java/org/keycloak/representations/adapters/action/SessionStats.java @@ -1,8 +1,6 @@ package org.keycloak.representations.adapters.action; -import java.util.List; import java.util.Map; -import java.util.Set; /** * @author Bill Burke diff --git a/core/src/main/java/org/keycloak/representations/idm/ApplicationRepresentation.java b/core/src/main/java/org/keycloak/representations/idm/ApplicationRepresentation.java index a22f305323..509f00b4d7 100755 --- a/core/src/main/java/org/keycloak/representations/idm/ApplicationRepresentation.java +++ b/core/src/main/java/org/keycloak/representations/idm/ApplicationRepresentation.java @@ -1,6 +1,5 @@ package org.keycloak.representations.idm; -import java.util.ArrayList; import java.util.List; /** diff --git a/core/src/main/java/org/keycloak/representations/idm/ErrorRepresentation.java b/core/src/main/java/org/keycloak/representations/idm/ErrorRepresentation.java index 3b0aac1b17..1bfd9a0521 100644 --- a/core/src/main/java/org/keycloak/representations/idm/ErrorRepresentation.java +++ b/core/src/main/java/org/keycloak/representations/idm/ErrorRepresentation.java @@ -4,7 +4,7 @@ package org.keycloak.representations.idm; * @author Stian Thorgersen */ public class ErrorRepresentation { - public String errorMessage; + private String errorMessage; public ErrorRepresentation() { } diff --git a/core/src/main/java/org/keycloak/representations/idm/RealmRepresentation.java b/core/src/main/java/org/keycloak/representations/idm/RealmRepresentation.java index 2812fc41d2..d19495d439 100755 --- a/core/src/main/java/org/keycloak/representations/idm/RealmRepresentation.java +++ b/core/src/main/java/org/keycloak/representations/idm/RealmRepresentation.java @@ -1,7 +1,6 @@ package org.keycloak.representations.idm; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; diff --git a/core/src/main/java/org/keycloak/util/Encode.java b/core/src/main/java/org/keycloak/util/Encode.java index 341f0dfc0c..0f3c496a36 100755 --- a/core/src/main/java/org/keycloak/util/Encode.java +++ b/core/src/main/java/org/keycloak/util/Encode.java @@ -221,7 +221,6 @@ public class Encode private static String decodeBytes(String enc, CharsetDecoder decoder) { Matcher matcher = encodedChars.matcher(enc); - StringBuffer buf = new StringBuffer(); ByteBuffer bytes = ByteBuffer.allocate(enc.length() / 3); while (matcher.find()) { @@ -268,7 +267,7 @@ public class Encode return buf.toString(); } - public static boolean savePathParams(String segment, StringBuffer newSegment, List params) + private static boolean savePathParams(String segment, StringBuffer newSegment, List params) { boolean foundParam = false; // Regular expressions can have '{' and '}' characters. Replace them to do match @@ -293,7 +292,7 @@ public class Encode * @param encoding * @return */ - public static String encodeValue(String segment, String[] encoding) + private static String encodeValue(String segment, String[] encoding) { ArrayList params = new ArrayList(); boolean foundParam = false; @@ -395,7 +394,7 @@ public class Encode return encodeFromArray(nameOrValue, queryNameValueEncoding, true); } - protected static String encodeFromArray(String segment, String[] encodingMap, boolean encodePercent) + private static String encodeFromArray(String segment, String[] encodingMap, boolean encodePercent) { StringBuffer result = new StringBuffer(); for (int i = 0; i < segment.length(); i++) @@ -445,7 +444,7 @@ public class Encode return encoded; } - public static String pathParamReplacement(String segment, List params) + private static String pathParamReplacement(String segment, List params) { StringBuffer newSegment = new StringBuffer(); Matcher matcher = PARAM_REPLACEMENT.matcher(segment); diff --git a/core/src/main/java/org/keycloak/util/KeycloakUriBuilder.java b/core/src/main/java/org/keycloak/util/KeycloakUriBuilder.java index 1e05af473f..2742a4eac7 100755 --- a/core/src/main/java/org/keycloak/util/KeycloakUriBuilder.java +++ b/core/src/main/java/org/keycloak/util/KeycloakUriBuilder.java @@ -55,8 +55,8 @@ public class KeycloakUriBuilder { return impl; } - public static final Pattern opaqueUri = Pattern.compile("^([^:/?#]+):([^/].*)"); - public static final Pattern hierarchicalUri = Pattern.compile("^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?"); + private static final Pattern opaqueUri = Pattern.compile("^([^:/?#]+):([^/].*)"); + private static final Pattern hierarchicalUri = Pattern.compile("^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?"); private static final Pattern hostPortPattern = Pattern.compile("([^/:]+):(\\d+)"); public static boolean compare(String s1, String s2) { @@ -149,7 +149,6 @@ public class KeycloakUriBuilder { Matcher hostPortMatch = hostPortPattern.matcher(host); if (hostPortMatch.matches()) { this.host = hostPortMatch.group(1); - int val = 0; try { this.port = Integer.parseInt(hostPortMatch.group(2)); } catch (NumberFormatException e) { @@ -359,12 +358,12 @@ public class KeycloakUriBuilder { return this; } - public URI buildFromMap(Map values) throws IllegalArgumentException { + public URI buildFromMap(Map values) throws IllegalArgumentException { if (values == null) throw new IllegalArgumentException("values parameter is null"); return buildUriFromMap(values, false, true); } - public URI buildFromEncodedMap(Map values) throws IllegalArgumentException { + public URI buildFromEncodedMap(Map values) throws IllegalArgumentException { if (values == null) throw new IllegalArgumentException("values parameter is null"); return buildUriFromMap(values, true, false); } @@ -374,7 +373,7 @@ public class KeycloakUriBuilder { return buildUriFromMap(values, false, encodeSlashInPath); } - protected URI buildUriFromMap(Map paramMap, boolean fromEncodedMap, boolean encodeSlash) throws IllegalArgumentException { + protected URI buildUriFromMap(Map paramMap, boolean fromEncodedMap, boolean encodeSlash) throws IllegalArgumentException { String buf = buildString(paramMap, fromEncodedMap, false, encodeSlash); try { return URI.create(buf); @@ -383,7 +382,7 @@ public class KeycloakUriBuilder { } } - private String buildString(Map paramMap, boolean fromEncodedMap, boolean isTemplate, boolean encodeSlash) { + private String buildString(Map paramMap, boolean fromEncodedMap, boolean isTemplate, boolean encodeSlash) { for (Map.Entry entry : paramMap.entrySet()) { if (entry.getKey() == null) throw new IllegalArgumentException("map key is null"); if (entry.getValue() == null) throw new IllegalArgumentException("map value is null"); @@ -448,11 +447,10 @@ public class KeycloakUriBuilder { } public static Matcher createUriParamMatcher(String string) { - Matcher matcher = PathHelper.URI_PARAM_PATTERN.matcher(PathHelper.replaceEnclosedCurlyBraces(string)); - return matcher; + return PathHelper.URI_PARAM_PATTERN.matcher(PathHelper.replaceEnclosedCurlyBraces(string)); } - protected StringBuffer replaceParameter(Map paramMap, boolean fromEncodedMap, boolean isTemplate, String string, StringBuffer buffer, boolean encodeSlash) { + protected StringBuffer replaceParameter(Map paramMap, boolean fromEncodedMap, boolean isTemplate, String string, StringBuffer buffer, boolean encodeSlash) { Matcher matcher = createUriParamMatcher(string); while (matcher.find()) { String param = matcher.group(1); @@ -481,7 +479,7 @@ public class KeycloakUriBuilder { return buffer; } - protected StringBuffer replaceQueryStringParameter(Map paramMap, boolean fromEncodedMap, boolean isTemplate, String string, StringBuffer buffer) { + protected StringBuffer replaceQueryStringParameter(Map paramMap, boolean fromEncodedMap, boolean isTemplate, String string, StringBuffer buffer) { Matcher matcher = createUriParamMatcher(string); while (matcher.find()) { String param = matcher.group(1); diff --git a/core/src/main/java/org/keycloak/util/MultivaluedHashMap.java b/core/src/main/java/org/keycloak/util/MultivaluedHashMap.java index bf0a66cb5a..bdfb77fd95 100755 --- a/core/src/main/java/org/keycloak/util/MultivaluedHashMap.java +++ b/core/src/main/java/org/keycloak/util/MultivaluedHashMap.java @@ -42,7 +42,6 @@ public class MultivaluedHashMap extends HashMap> if (list == null) { add(key, value); - return; } else { diff --git a/core/src/main/java/org/keycloak/util/PemUtils.java b/core/src/main/java/org/keycloak/util/PemUtils.java index 11b74e3829..4ba1133a46 100755 --- a/core/src/main/java/org/keycloak/util/PemUtils.java +++ b/core/src/main/java/org/keycloak/util/PemUtils.java @@ -76,8 +76,7 @@ public final class PemUtils { */ public static byte[] pemToDer(InputStream is) throws IOException { String pem = pemFromStream(is); - byte[] der = pemToDer(pem); - return der; + return pemToDer(pem); } /** diff --git a/core/src/main/java/org/keycloak/util/ProviderLoader.java b/core/src/main/java/org/keycloak/util/ProviderLoader.java index 3685b4f89f..bed3304154 100644 --- a/core/src/main/java/org/keycloak/util/ProviderLoader.java +++ b/core/src/main/java/org/keycloak/util/ProviderLoader.java @@ -8,7 +8,7 @@ import java.util.ServiceLoader; */ public class ProviderLoader implements Iterable { - private ServiceLoader serviceLoader; + private final ServiceLoader serviceLoader; public static Iterable load(Class service) { ServiceLoader providers = ServiceLoader.load(service); @@ -26,7 +26,7 @@ public class ProviderLoader implements Iterable { private static class ProviderIterator implements Iterator { - private Iterator itr; + private final Iterator itr; private T next; diff --git a/core/src/main/java/org/keycloak/util/StreamUtil.java b/core/src/main/java/org/keycloak/util/StreamUtil.java index 67cd8d71a8..4d382df562 100755 --- a/core/src/main/java/org/keycloak/util/StreamUtil.java +++ b/core/src/main/java/org/keycloak/util/StreamUtil.java @@ -19,7 +19,7 @@ public final class StreamUtil { char[] buffer = new char[1024]; StringBuilder builder = new StringBuilder(); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); - int wasRead = 0; + int wasRead; do { wasRead = reader.read(buffer, 0, 1024); diff --git a/services/src/main/java/org/keycloak/services/managers/ResourceAdminManager.java b/services/src/main/java/org/keycloak/services/managers/ResourceAdminManager.java index 942def012a..48600fd990 100755 --- a/services/src/main/java/org/keycloak/services/managers/ResourceAdminManager.java +++ b/services/src/main/java/org/keycloak/services/managers/ResourceAdminManager.java @@ -195,7 +195,7 @@ public class ResourceAdminManager { String token = new TokenManager().encodeToken(realm, adminAction); logger.infov("logout user: {0} resource: {1} url: {2}", user, resource.getName(), managementUrl); ClientRequest request = client.createRequest(UriBuilder.fromUri(managementUrl).path(AdapterConstants.K_LOGOUT).build().toString()); - ClientResponse response = null; + ClientResponse response; try { response = request.body(MediaType.TEXT_PLAIN_TYPE, token).post(UserStats.class); } catch (Exception e) {