From 697eaa4f3670ffcd17b64abccd9b5a4272982998 Mon Sep 17 00:00:00 2001 From: Andrei Arlou Date: Fri, 29 Nov 2019 22:29:17 +0300 Subject: [PATCH] KEYCLOAK-12309 Fix warnings with collections in packages: authentification, authorization, broker, email, events, exportimport from module "services" --- .../BasicAuthAuthenticatorFactory.java | 2 +- .../BasicAuthOTPAuthenticatorFactory.java | 2 +- ...oCookieFlowRedirectAuthenticatorFactory.java | 2 +- ...09ClientCertificateAuthenticatorFactory.java | 9 +++------ ...ientCertificateDirectGrantAuthenticator.java | 2 +- .../admin/PolicyEvaluationService.java | 17 ++++++----------- .../permission/PermissionTicketService.java | 2 +- .../saml/SAMLIdentityProviderFactory.java | 2 +- .../FreeMarkerEmailTemplateProvider.java | 14 +++++++------- .../EmailEventListenerProviderFactory.java | 4 ++-- .../exportimport/dir/DirImportProvider.java | 2 +- .../singlefile/SingleFileExportProvider.java | 2 +- .../keycloak/exportimport/util/ExportUtils.java | 14 +++++++------- 13 files changed, 33 insertions(+), 41 deletions(-) diff --git a/services/src/main/java/org/keycloak/authentication/authenticators/challenge/BasicAuthAuthenticatorFactory.java b/services/src/main/java/org/keycloak/authentication/authenticators/challenge/BasicAuthAuthenticatorFactory.java index db00134ad4..9c8853a082 100644 --- a/services/src/main/java/org/keycloak/authentication/authenticators/challenge/BasicAuthAuthenticatorFactory.java +++ b/services/src/main/java/org/keycloak/authentication/authenticators/challenge/BasicAuthAuthenticatorFactory.java @@ -89,7 +89,7 @@ public class BasicAuthAuthenticatorFactory implements AuthenticatorFactory { @Override public List getConfigProperties() { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } @Override diff --git a/services/src/main/java/org/keycloak/authentication/authenticators/challenge/BasicAuthOTPAuthenticatorFactory.java b/services/src/main/java/org/keycloak/authentication/authenticators/challenge/BasicAuthOTPAuthenticatorFactory.java index 95326724e0..a50ec9d7ed 100644 --- a/services/src/main/java/org/keycloak/authentication/authenticators/challenge/BasicAuthOTPAuthenticatorFactory.java +++ b/services/src/main/java/org/keycloak/authentication/authenticators/challenge/BasicAuthOTPAuthenticatorFactory.java @@ -89,7 +89,7 @@ public class BasicAuthOTPAuthenticatorFactory implements AuthenticatorFactory { @Override public List getConfigProperties() { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } @Override diff --git a/services/src/main/java/org/keycloak/authentication/authenticators/challenge/NoCookieFlowRedirectAuthenticatorFactory.java b/services/src/main/java/org/keycloak/authentication/authenticators/challenge/NoCookieFlowRedirectAuthenticatorFactory.java index 8738df3830..5e34a7b3c3 100644 --- a/services/src/main/java/org/keycloak/authentication/authenticators/challenge/NoCookieFlowRedirectAuthenticatorFactory.java +++ b/services/src/main/java/org/keycloak/authentication/authenticators/challenge/NoCookieFlowRedirectAuthenticatorFactory.java @@ -92,7 +92,7 @@ public class NoCookieFlowRedirectAuthenticatorFactory implements AuthenticatorFa @Override public List getConfigProperties() { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } @Override diff --git a/services/src/main/java/org/keycloak/authentication/authenticators/x509/AbstractX509ClientCertificateAuthenticatorFactory.java b/services/src/main/java/org/keycloak/authentication/authenticators/x509/AbstractX509ClientCertificateAuthenticatorFactory.java index e62d04b85a..4726e1b5bd 100644 --- a/services/src/main/java/org/keycloak/authentication/authenticators/x509/AbstractX509ClientCertificateAuthenticatorFactory.java +++ b/services/src/main/java/org/keycloak/authentication/authenticators/x509/AbstractX509ClientCertificateAuthenticatorFactory.java @@ -18,6 +18,7 @@ package org.keycloak.authentication.authenticators.x509; +import java.util.Collections; import java.util.LinkedList; import java.util.List; @@ -89,9 +90,7 @@ public abstract class AbstractX509ClientCertificateAuthenticatorFactory implemen protected static final List configProperties; static { List mappingSourceTypes = new LinkedList<>(); - for (String s : mappingSources) { - mappingSourceTypes.add(s); - } + Collections.addAll(mappingSourceTypes, mappingSources); ProviderConfigProperty mappingMethodList = new ProviderConfigProperty(); mappingMethodList.setType(ProviderConfigProperty.LIST_TYPE); mappingMethodList.setName(MAPPING_SOURCE_SELECTION); @@ -123,9 +122,7 @@ public abstract class AbstractX509ClientCertificateAuthenticatorFactory implemen regExp.setHelpText("The regular expression to extract a user identity. The expression must contain a single group. For example, 'uniqueId=(.*?)(?:,|$)' will match 'uniqueId=somebody@company.org, CN=somebody' and give somebody@company.org"); List mapperTypes = new LinkedList<>(); - for (String m : userModelMappers) { - mapperTypes.add(m); - } + Collections.addAll(mapperTypes, userModelMappers); ProviderConfigProperty userMapperList = new ProviderConfigProperty(); userMapperList.setType(ProviderConfigProperty.LIST_TYPE); diff --git a/services/src/main/java/org/keycloak/authentication/authenticators/x509/AbstractX509ClientCertificateDirectGrantAuthenticator.java b/services/src/main/java/org/keycloak/authentication/authenticators/x509/AbstractX509ClientCertificateDirectGrantAuthenticator.java index 15de72c1d8..f4123bac08 100644 --- a/services/src/main/java/org/keycloak/authentication/authenticators/x509/AbstractX509ClientCertificateDirectGrantAuthenticator.java +++ b/services/src/main/java/org/keycloak/authentication/authenticators/x509/AbstractX509ClientCertificateDirectGrantAuthenticator.java @@ -35,7 +35,7 @@ import java.util.Map; public abstract class AbstractX509ClientCertificateDirectGrantAuthenticator extends AbstractX509ClientCertificateAuthenticator { public Response errorResponse(int status, String error, String errorDescription) { - Map e = new HashMap(); + Map e = new HashMap<>(); e.put(OAuth2Constants.ERROR, error); if (errorDescription != null) { e.put(OAuth2Constants.ERROR_DESCRIPTION, errorDescription); diff --git a/services/src/main/java/org/keycloak/authorization/admin/PolicyEvaluationService.java b/services/src/main/java/org/keycloak/authorization/admin/PolicyEvaluationService.java index 46203d64e1..7d27ac8b65 100644 --- a/services/src/main/java/org/keycloak/authorization/admin/PolicyEvaluationService.java +++ b/services/src/main/java/org/keycloak/authorization/admin/PolicyEvaluationService.java @@ -21,6 +21,7 @@ package org.keycloak.authorization.admin; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -104,11 +105,8 @@ public class PolicyEvaluationService { if (givenAttributes != null) { givenAttributes.forEach((key, entryValue) -> { if (entryValue != null) { - List values = new ArrayList(); - - for (String value : entryValue.split(",")) { - values.add(value); - } + List values = new ArrayList<>(); + Collections.addAll(values, entryValue.split(",")); claims.put(key, values); } @@ -140,11 +138,8 @@ public class PolicyEvaluationService { if (givenAttributes != null) { givenAttributes.forEach((key, entryValue) -> { if (entryValue != null) { - List values = new ArrayList(); - - for (String value : entryValue.split(",")) { - values.add(value); - } + List values = new ArrayList<>(); + Collections.addAll(values, entryValue.split(",")); attributes.put(key, values); } @@ -166,7 +161,7 @@ public class PolicyEvaluationService { Set givenScopes = resource.getScopes(); if (givenScopes == null) { - givenScopes = new HashSet(); + givenScopes = new HashSet<>(); } ScopeStore scopeStore = storeFactory.getScopeStore(); diff --git a/services/src/main/java/org/keycloak/authorization/protection/permission/PermissionTicketService.java b/services/src/main/java/org/keycloak/authorization/protection/permission/PermissionTicketService.java index fafbd7142a..46389a1c0a 100644 --- a/services/src/main/java/org/keycloak/authorization/protection/permission/PermissionTicketService.java +++ b/services/src/main/java/org/keycloak/authorization/protection/permission/PermissionTicketService.java @@ -116,7 +116,7 @@ public class PermissionTicketService { if (!match) throw new ErrorResponseException("invalid_resource_id", "Resource set with id [" + representation.getResource() + "] does not have Scope [" + scope.getName() + "]", Response.Status.BAD_REQUEST); - Map attributes = new HashMap(); + Map attributes = new HashMap<>(); attributes.put(PermissionTicket.RESOURCE, resource.getId()); attributes.put(PermissionTicket.SCOPE, scope.getId()); attributes.put(PermissionTicket.REQUESTER, user.getId()); diff --git a/services/src/main/java/org/keycloak/broker/saml/SAMLIdentityProviderFactory.java b/services/src/main/java/org/keycloak/broker/saml/SAMLIdentityProviderFactory.java index a0eb47150f..f538cc5ab0 100755 --- a/services/src/main/java/org/keycloak/broker/saml/SAMLIdentityProviderFactory.java +++ b/services/src/main/java/org/keycloak/broker/saml/SAMLIdentityProviderFactory.java @@ -155,7 +155,7 @@ public class SAMLIdentityProviderFactory extends AbstractIdentityProviderFactory throw new RuntimeException("Could not parse IdP SAML Metadata", pe); } - return new HashMap(); + return new HashMap<>(); } @Override diff --git a/services/src/main/java/org/keycloak/email/freemarker/FreeMarkerEmailTemplateProvider.java b/services/src/main/java/org/keycloak/email/freemarker/FreeMarkerEmailTemplateProvider.java index 0f85f615be..d57036698c 100755 --- a/services/src/main/java/org/keycloak/email/freemarker/FreeMarkerEmailTemplateProvider.java +++ b/services/src/main/java/org/keycloak/email/freemarker/FreeMarkerEmailTemplateProvider.java @@ -104,7 +104,7 @@ public class FreeMarkerEmailTemplateProvider implements EmailTemplateProvider { @Override public void sendEvent(Event event) throws EmailException { - Map attributes = new HashMap(); + Map attributes = new HashMap<>(); attributes.put("user", new ProfileBean(user)); attributes.put("event", new EventBean(event)); @@ -113,7 +113,7 @@ public class FreeMarkerEmailTemplateProvider implements EmailTemplateProvider { @Override public void sendPasswordReset(String link, long expirationInMinutes) throws EmailException { - Map attributes = new HashMap(this.attributes); + Map attributes = new HashMap<>(this.attributes); attributes.put("user", new ProfileBean(user)); addLinkInfoIntoAttributes(link, expirationInMinutes, attributes); @@ -127,7 +127,7 @@ public class FreeMarkerEmailTemplateProvider implements EmailTemplateProvider { setRealm(session.getContext().getRealm()); setUser(user); - Map attributes = new HashMap(this.attributes); + Map attributes = new HashMap<>(this.attributes); attributes.put("user", new ProfileBean(user)); attributes.put("realmName", realm.getName()); @@ -137,7 +137,7 @@ public class FreeMarkerEmailTemplateProvider implements EmailTemplateProvider { @Override public void sendConfirmIdentityBrokerLink(String link, long expirationInMinutes) throws EmailException { - Map attributes = new HashMap(this.attributes); + Map attributes = new HashMap<>(this.attributes); attributes.put("user", new ProfileBean(user)); addLinkInfoIntoAttributes(link, expirationInMinutes, attributes); @@ -150,13 +150,13 @@ public class FreeMarkerEmailTemplateProvider implements EmailTemplateProvider { attributes.put("identityProviderContext", brokerContext); attributes.put("identityProviderAlias", idpAlias); - List subjectAttrs = Arrays. asList(idpAlias); + List subjectAttrs = Arrays.asList(idpAlias); send("identityProviderLinkSubject", subjectAttrs, "identity-provider-link.ftl", attributes); } @Override public void sendExecuteActions(String link, long expirationInMinutes) throws EmailException { - Map attributes = new HashMap(this.attributes); + Map attributes = new HashMap<>(this.attributes); attributes.put("user", new ProfileBean(user)); addLinkInfoIntoAttributes(link, expirationInMinutes, attributes); @@ -167,7 +167,7 @@ public class FreeMarkerEmailTemplateProvider implements EmailTemplateProvider { @Override public void sendVerifyEmail(String link, long expirationInMinutes) throws EmailException { - Map attributes = new HashMap(this.attributes); + Map attributes = new HashMap<>(this.attributes); attributes.put("user", new ProfileBean(user)); addLinkInfoIntoAttributes(link, expirationInMinutes, attributes); diff --git a/services/src/main/java/org/keycloak/events/email/EmailEventListenerProviderFactory.java b/services/src/main/java/org/keycloak/events/email/EmailEventListenerProviderFactory.java index 651b582688..f8cb7e3d47 100755 --- a/services/src/main/java/org/keycloak/events/email/EmailEventListenerProviderFactory.java +++ b/services/src/main/java/org/keycloak/events/email/EmailEventListenerProviderFactory.java @@ -34,12 +34,12 @@ import java.util.Set; */ public class EmailEventListenerProviderFactory implements EventListenerProviderFactory { - private static final Set SUPPORTED_EVENTS = new HashSet(); + private static final Set SUPPORTED_EVENTS = new HashSet<>(); static { Collections.addAll(SUPPORTED_EVENTS, EventType.LOGIN_ERROR, EventType.UPDATE_PASSWORD, EventType.REMOVE_TOTP, EventType.UPDATE_TOTP); } - private Set includedEvents = new HashSet(); + private Set includedEvents = new HashSet<>(); @Override public EventListenerProvider create(KeycloakSession session) { diff --git a/services/src/main/java/org/keycloak/exportimport/dir/DirImportProvider.java b/services/src/main/java/org/keycloak/exportimport/dir/DirImportProvider.java index a2a0699c72..ad0328e025 100755 --- a/services/src/main/java/org/keycloak/exportimport/dir/DirImportProvider.java +++ b/services/src/main/java/org/keycloak/exportimport/dir/DirImportProvider.java @@ -95,7 +95,7 @@ public class DirImportProvider implements ImportProvider { } }); - List realmNames = new ArrayList(); + List realmNames = new ArrayList<>(); for (File file : realmFiles) { String fileName = file.getName(); // Parse "foo" from "foo-realm.json" diff --git a/services/src/main/java/org/keycloak/exportimport/singlefile/SingleFileExportProvider.java b/services/src/main/java/org/keycloak/exportimport/singlefile/SingleFileExportProvider.java index a2a88520d2..9b3aebaff5 100755 --- a/services/src/main/java/org/keycloak/exportimport/singlefile/SingleFileExportProvider.java +++ b/services/src/main/java/org/keycloak/exportimport/singlefile/SingleFileExportProvider.java @@ -60,7 +60,7 @@ public class SingleFileExportProvider implements ExportProvider { @Override protected void runExportImportTask(KeycloakSession session) throws IOException { List realms = session.realms().getRealms(); - List reps = new ArrayList(); + List reps = new ArrayList<>(); for (RealmModel realm : realms) { reps.add(ExportUtils.exportRealm(session, realm, true, true)); } diff --git a/services/src/main/java/org/keycloak/exportimport/util/ExportUtils.java b/services/src/main/java/org/keycloak/exportimport/util/ExportUtils.java index 33f751c60d..45e22ba47b 100755 --- a/services/src/main/java/org/keycloak/exportimport/util/ExportUtils.java +++ b/services/src/main/java/org/keycloak/exportimport/util/ExportUtils.java @@ -410,7 +410,7 @@ public class ExportUtils { } public static List getRoleNames(Collection roles) { - List roleNames = new ArrayList(); + List roleNames = new ArrayList<>(); for (RoleModel role : roles) { roleNames.add(role.getName()); } @@ -479,7 +479,7 @@ public class ExportUtils { // Social links Set socialLinks = session.users().getFederatedIdentities(user, realm); - List socialLinkReps = new ArrayList(); + List socialLinkReps = new ArrayList<>(); for (FederatedIdentityModel socialLink : socialLinks) { FederatedIdentityRepresentation socialLinkRep = exportSocialLink(socialLink); socialLinkReps.add(socialLinkRep); @@ -517,7 +517,7 @@ public class ExportUtils { // Credentials List creds = session.userCredentialManager().getStoredCredentials(realm, user); - List credReps = new ArrayList(); + List credReps = new ArrayList<>(); for (CredentialModel cred : creds) { CredentialRepresentation credRep = exportCredential(cred); credReps.add(credRep); @@ -527,7 +527,7 @@ public class ExportUtils { // Grants List consents = session.users().getConsents(realm, user.getId()); - LinkedList consentReps = new LinkedList(); + LinkedList consentReps = new LinkedList<>(); for (UserConsentModel consent : consents) { UserConsentRepresentation consentRep = ModelToRepresentation.toRepresentation(consent); consentReps.add(consentRep); @@ -657,7 +657,7 @@ public class ExportUtils { // Social links Set socialLinks = session.userFederatedStorage().getFederatedIdentities(id, realm); - List socialLinkReps = new ArrayList(); + List socialLinkReps = new ArrayList<>(); for (FederatedIdentityModel socialLink : socialLinks) { FederatedIdentityRepresentation socialLinkRep = exportSocialLink(socialLink); socialLinkReps.add(socialLinkRep); @@ -697,7 +697,7 @@ public class ExportUtils { // Credentials List creds = session.userFederatedStorage().getStoredCredentials(realm, id); - List credReps = new ArrayList(); + List credReps = new ArrayList<>(); for (CredentialModel cred : creds) { CredentialRepresentation credRep = exportCredential(cred); credReps.add(credRep); @@ -706,7 +706,7 @@ public class ExportUtils { // Grants List consents = session.users().getConsents(realm, id); - LinkedList consentReps = new LinkedList(); + LinkedList consentReps = new LinkedList<>(); for (UserConsentModel consent : consents) { UserConsentRepresentation consentRep = ModelToRepresentation.toRepresentation(consent); consentReps.add(consentRep);