KEYCLOAK-12309 Fix warnings with collections in packages:

authentification, authorization, broker, email, events, exportimport from module "services"
This commit is contained in:
Andrei Arlou 2019-11-29 22:29:17 +03:00 committed by Hynek Mlnařík
parent 1ac76fde59
commit 697eaa4f36
13 changed files with 33 additions and 41 deletions

View file

@ -89,7 +89,7 @@ public class BasicAuthAuthenticatorFactory implements AuthenticatorFactory {
@Override
public List<ProviderConfigProperty> getConfigProperties() {
return Collections.EMPTY_LIST;
return Collections.emptyList();
}
@Override

View file

@ -89,7 +89,7 @@ public class BasicAuthOTPAuthenticatorFactory implements AuthenticatorFactory {
@Override
public List<ProviderConfigProperty> getConfigProperties() {
return Collections.EMPTY_LIST;
return Collections.emptyList();
}
@Override

View file

@ -92,7 +92,7 @@ public class NoCookieFlowRedirectAuthenticatorFactory implements AuthenticatorFa
@Override
public List<ProviderConfigProperty> getConfigProperties() {
return Collections.EMPTY_LIST;
return Collections.emptyList();
}
@Override

View file

@ -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<ProviderConfigProperty> configProperties;
static {
List<String> 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<String> mapperTypes = new LinkedList<>();
for (String m : userModelMappers) {
mapperTypes.add(m);
}
Collections.addAll(mapperTypes, userModelMappers);
ProviderConfigProperty userMapperList = new ProviderConfigProperty();
userMapperList.setType(ProviderConfigProperty.LIST_TYPE);

View file

@ -35,7 +35,7 @@ import java.util.Map;
public abstract class AbstractX509ClientCertificateDirectGrantAuthenticator extends AbstractX509ClientCertificateAuthenticator {
public Response errorResponse(int status, String error, String errorDescription) {
Map<String, String> e = new HashMap<String, String>();
Map<String, String> e = new HashMap<>();
e.put(OAuth2Constants.ERROR, error);
if (errorDescription != null) {
e.put(OAuth2Constants.ERROR_DESCRIPTION, errorDescription);

View file

@ -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<String> values = new ArrayList();
for (String value : entryValue.split(",")) {
values.add(value);
}
List<String> 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<String> values = new ArrayList();
for (String value : entryValue.split(",")) {
values.add(value);
}
List<String> values = new ArrayList<>();
Collections.addAll(values, entryValue.split(","));
attributes.put(key, values);
}
@ -166,7 +161,7 @@ public class PolicyEvaluationService {
Set<ScopeRepresentation> givenScopes = resource.getScopes();
if (givenScopes == null) {
givenScopes = new HashSet();
givenScopes = new HashSet<>();
}
ScopeStore scopeStore = storeFactory.getScopeStore();

View file

@ -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<String, String> attributes = new HashMap<String, String>();
Map<String, String> attributes = new HashMap<>();
attributes.put(PermissionTicket.RESOURCE, resource.getId());
attributes.put(PermissionTicket.SCOPE, scope.getId());
attributes.put(PermissionTicket.REQUESTER, user.getId());

View file

@ -155,7 +155,7 @@ public class SAMLIdentityProviderFactory extends AbstractIdentityProviderFactory
throw new RuntimeException("Could not parse IdP SAML Metadata", pe);
}
return new HashMap<String, String>();
return new HashMap<>();
}
@Override

View file

@ -104,7 +104,7 @@ public class FreeMarkerEmailTemplateProvider implements EmailTemplateProvider {
@Override
public void sendEvent(Event event) throws EmailException {
Map<String, Object> attributes = new HashMap<String, Object>();
Map<String, Object> 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<String, Object> attributes = new HashMap<String, Object>(this.attributes);
Map<String, Object> 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<String, Object> attributes = new HashMap<String, Object>(this.attributes);
Map<String, Object> 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<String, Object> attributes = new HashMap<String, Object>(this.attributes);
Map<String, Object> 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<Object> subjectAttrs = Arrays.<Object> asList(idpAlias);
List<Object> subjectAttrs = Arrays.asList(idpAlias);
send("identityProviderLinkSubject", subjectAttrs, "identity-provider-link.ftl", attributes);
}
@Override
public void sendExecuteActions(String link, long expirationInMinutes) throws EmailException {
Map<String, Object> attributes = new HashMap<String, Object>(this.attributes);
Map<String, Object> 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<String, Object> attributes = new HashMap<String, Object>(this.attributes);
Map<String, Object> attributes = new HashMap<>(this.attributes);
attributes.put("user", new ProfileBean(user));
addLinkInfoIntoAttributes(link, expirationInMinutes, attributes);

View file

@ -34,12 +34,12 @@ import java.util.Set;
*/
public class EmailEventListenerProviderFactory implements EventListenerProviderFactory {
private static final Set<EventType> SUPPORTED_EVENTS = new HashSet<EventType>();
private static final Set<EventType> SUPPORTED_EVENTS = new HashSet<>();
static {
Collections.addAll(SUPPORTED_EVENTS, EventType.LOGIN_ERROR, EventType.UPDATE_PASSWORD, EventType.REMOVE_TOTP, EventType.UPDATE_TOTP);
}
private Set<EventType> includedEvents = new HashSet<EventType>();
private Set<EventType> includedEvents = new HashSet<>();
@Override
public EventListenerProvider create(KeycloakSession session) {

View file

@ -95,7 +95,7 @@ public class DirImportProvider implements ImportProvider {
}
});
List<String> realmNames = new ArrayList<String>();
List<String> realmNames = new ArrayList<>();
for (File file : realmFiles) {
String fileName = file.getName();
// Parse "foo" from "foo-realm.json"

View file

@ -60,7 +60,7 @@ public class SingleFileExportProvider implements ExportProvider {
@Override
protected void runExportImportTask(KeycloakSession session) throws IOException {
List<RealmModel> realms = session.realms().getRealms();
List<RealmRepresentation> reps = new ArrayList<RealmRepresentation>();
List<RealmRepresentation> reps = new ArrayList<>();
for (RealmModel realm : realms) {
reps.add(ExportUtils.exportRealm(session, realm, true, true));
}

View file

@ -410,7 +410,7 @@ public class ExportUtils {
}
public static List<String> getRoleNames(Collection<RoleModel> roles) {
List<String> roleNames = new ArrayList<String>();
List<String> roleNames = new ArrayList<>();
for (RoleModel role : roles) {
roleNames.add(role.getName());
}
@ -479,7 +479,7 @@ public class ExportUtils {
// Social links
Set<FederatedIdentityModel> socialLinks = session.users().getFederatedIdentities(user, realm);
List<FederatedIdentityRepresentation> socialLinkReps = new ArrayList<FederatedIdentityRepresentation>();
List<FederatedIdentityRepresentation> socialLinkReps = new ArrayList<>();
for (FederatedIdentityModel socialLink : socialLinks) {
FederatedIdentityRepresentation socialLinkRep = exportSocialLink(socialLink);
socialLinkReps.add(socialLinkRep);
@ -517,7 +517,7 @@ public class ExportUtils {
// Credentials
List<CredentialModel> creds = session.userCredentialManager().getStoredCredentials(realm, user);
List<CredentialRepresentation> credReps = new ArrayList<CredentialRepresentation>();
List<CredentialRepresentation> credReps = new ArrayList<>();
for (CredentialModel cred : creds) {
CredentialRepresentation credRep = exportCredential(cred);
credReps.add(credRep);
@ -527,7 +527,7 @@ public class ExportUtils {
// Grants
List<UserConsentModel> consents = session.users().getConsents(realm, user.getId());
LinkedList<UserConsentRepresentation> consentReps = new LinkedList<UserConsentRepresentation>();
LinkedList<UserConsentRepresentation> 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<FederatedIdentityModel> socialLinks = session.userFederatedStorage().getFederatedIdentities(id, realm);
List<FederatedIdentityRepresentation> socialLinkReps = new ArrayList<FederatedIdentityRepresentation>();
List<FederatedIdentityRepresentation> socialLinkReps = new ArrayList<>();
for (FederatedIdentityModel socialLink : socialLinks) {
FederatedIdentityRepresentation socialLinkRep = exportSocialLink(socialLink);
socialLinkReps.add(socialLinkRep);
@ -697,7 +697,7 @@ public class ExportUtils {
// Credentials
List<CredentialModel> creds = session.userFederatedStorage().getStoredCredentials(realm, id);
List<CredentialRepresentation> credReps = new ArrayList<CredentialRepresentation>();
List<CredentialRepresentation> credReps = new ArrayList<>();
for (CredentialModel cred : creds) {
CredentialRepresentation credRep = exportCredential(cred);
credReps.add(credRep);
@ -706,7 +706,7 @@ public class ExportUtils {
// Grants
List<UserConsentModel> consents = session.users().getConsents(realm, id);
LinkedList<UserConsentRepresentation> consentReps = new LinkedList<UserConsentRepresentation>();
LinkedList<UserConsentRepresentation> consentReps = new LinkedList<>();
for (UserConsentModel consent : consents) {
UserConsentRepresentation consentRep = ModelToRepresentation.toRepresentation(consent);
consentReps.add(consentRep);