Skip to content

Commit

Permalink
replace all Collections with Pages or PagedMaps
Browse files Browse the repository at this point in the history
  • Loading branch information
blevine committed Oct 16, 2024
1 parent 6992253 commit d51142b
Show file tree
Hide file tree
Showing 13 changed files with 170 additions and 63 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package net.brianlevine.keycloak.graphql.types;

import net.brianlevine.keycloak.graphql.util.PagedMap;

import java.util.Map;

public class AccessMap extends PagedMap<String, Boolean, AccessMap.Entry> {

public AccessMap(Map<String, Boolean> map, PagingOptions options) {
this(map, options != null ? options.start : PagingOptions.DEFAULT.start, options != null ? options.limit : PagingOptions.DEFAULT.limit);
}

public AccessMap(Map<String, Boolean> map, int start, int limit) {
super(map, start, limit, AccessMap.Entry.class);
}

public static class Entry extends DelegatingEntry<String, Boolean> {
public Entry(Map.Entry<String, Boolean> delegate) {
super(delegate);
}

public String getName() {
return delegate.getKey();
}

public Boolean getAccess() {
return delegate.getValue();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package net.brianlevine.keycloak.graphql.types;

import net.brianlevine.keycloak.graphql.util.PagedMap;

import java.util.Map;

public class AuthenticationFlowOverrideMap extends PagedMap<String, String, AuthenticationFlowOverrideMap.Entry> {

public AuthenticationFlowOverrideMap(Map<String, String> map, int start, int limit) {
super(map, start, limit, AuthenticationFlowOverrideMap.Entry.class);
}

public AuthenticationFlowOverrideMap(Map<String, String> map, PagingOptions options) {
super(map, options, AuthenticationFlowOverrideMap.Entry.class);
}

public static class Entry extends DelegatingEntry<String, String> implements Map.Entry<String, String> {
public Entry(Map.Entry<String, String> delegate) {
super(delegate);
}

public String getFlowType() {
return delegate.getKey();
}

public String getFlowName() {
return delegate.getValue();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ public void setBuiltIn(boolean builtIn) {
delegate.setBuiltIn(builtIn);
}

public List<AuthenticationExecutionExportRepresentation> getAuthenticationExecutions() {
return delegate.getAuthenticationExecutions();
}

public Page<AuthenticationExecutionExportType> getAuthenticationExecutions(PagingOptions options) {
return Page.toPagedType(
options,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,21 +290,21 @@ public void setProtocol(String protocol) {
delegate.setProtocol(protocol);
}

public Map<String, String> getAttributes() {
return delegate.getAttributes();
public AttributeMap getAttributes(PagingOptions options) {
return new AttributeMap(delegate.getAttributes(), options);
}

public void setAttributes(Map<String, String> attributes) {
delegate.setAttributes(attributes);
}
// public void setAttributes(Map<String, String> attributes) {
// delegate.setAttributes(attributes);
// }

public Map<String, String> getAuthenticationFlowBindingOverrides() {
return delegate.getAuthenticationFlowBindingOverrides();
public AuthenticationFlowOverrideMap getAuthenticationFlowBindingOverrides(PagingOptions options) {
return new AuthenticationFlowOverrideMap(delegate.getAuthenticationFlowBindingOverrides(), options);
}

public void setAuthenticationFlowBindingOverrides(Map<String, String> authenticationFlowBindingOverrides) {
delegate.setAuthenticationFlowBindingOverrides(authenticationFlowBindingOverrides);
}
// public void setAuthenticationFlowBindingOverrides(Map<String, String> authenticationFlowBindingOverrides) {
// delegate.setAuthenticationFlowBindingOverrides(authenticationFlowBindingOverrides);
// }

public Integer getNodeReRegistrationTimeout() {
return delegate.getNodeReRegistrationTimeout();
Expand All @@ -314,13 +314,13 @@ public void setNodeReRegistrationTimeout(Integer nodeReRegistrationTimeout) {
delegate.setNodeReRegistrationTimeout(nodeReRegistrationTimeout);
}

public Map<String, Integer> getRegisteredNodes() {
return delegate.getRegisteredNodes();
}
//public Map<String, Integer> getRegisteredNodes() {
// return delegate.getRegisteredNodes();
//}

public void setRegisteredNodes(Map<String, Integer> registeredNodes) {
delegate.setRegisteredNodes(registeredNodes);
}
//public void setRegisteredNodes(Map<String, Integer> registeredNodes) {
// delegate.setRegisteredNodes(registeredNodes);
//}

public Boolean isFrontchannelLogout() {
return delegate.isFrontchannelLogout();
Expand Down Expand Up @@ -382,13 +382,13 @@ public void setOptionalClientScopes(List<String> optionalClientScopes) {
// delegate.setAuthorizationSettings(authorizationSettings);
// }

public Map<String, Boolean> getAccess() {
return delegate.getAccess();
public AccessMap getAccess(PagingOptions options) {
return new AccessMap(delegate.getAccess(), options);
}

public void setAccess(Map<String, Boolean> access) {
delegate.setAccess(access);
}
// public void setAccess(Map<String, Boolean> access) {
// delegate.setAccess(access);
// }

/**
* Returns id of ClientStorageProvider that loaded this user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ public void setSubType(String subType) {
@GraphQLQuery
public MultiAttributeMap getConfig(PagingOptions options) {
MultivaluedMap<String, String> config = delegate.getConfig();
options = options == null ? new PagingOptions() : options;

return new MultiAttributeMap(config, options.start, options.limit);
return new MultiAttributeMap(config, options);
}

// public void setConfig(MultivaluedHashMap<String, String> config) {
Expand All @@ -80,7 +79,6 @@ public ComponentMap getSubComponents(PagingOptions options) {
Map<String, List<ComponentType>> subs = subComponents != null
? subComponents.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().stream().map(ComponentType::new).toList()))
: new MultivaluedHashMap<>();
options = options == null ? new PagingOptions() : options;
return new ComponentMap(subs, options);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ public void setParentId(String parentId) {
//}


public Map<String, List<String>> getAttributes() {
return delegate.getAttributes();
public MultiAttributeMap getAttributes(PagingOptions options) {
return new MultiAttributeMap(delegate.getAttributes(), options);
}

public void setAttributes(Map<String, List<String>> attributes) {
Expand Down Expand Up @@ -182,13 +182,13 @@ public Page<GroupType> getSubGroups(PagingOptions options, @GraphQLRootContext G
// delegate.setSubGroups(subGroups);
//}

public Map<String, Boolean> getAccess() {
return delegate.getAccess();
public AccessMap getAccess(PagingOptions options) {
return new AccessMap(delegate.getAccess(), options);
}

public void setAccess(Map<String, Boolean> access) {
delegate.setAccess(access);
}
// public void setAccess(Map<String, Boolean> access) {
// delegate.setAccess(access);
// }

//public void merge(GroupRepresentation g) {
// merge(delegate, g);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package net.brianlevine.keycloak.graphql.types;

import net.brianlevine.keycloak.graphql.util.PagedMap;

import java.util.Map;

public class HeaderMap extends PagedMap<String, String, HeaderMap.Entry> {

public HeaderMap(Map<String, String> map, int start, int limit) {
super(map, start, limit, HeaderMap.Entry.class);
}

public HeaderMap(Map<String, String> map, PagingOptions options) {
super(map, options, HeaderMap.Entry.class);
}

public static class Entry extends DelegatingEntry<String, String> implements Map.Entry<String, String> {
public Entry(Map.Entry<String, String> delegate) {
super(delegate);
}

public String getName() {
return delegate.getKey();
}

public String getValue() {
return delegate.getValue();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public void setProviderId(String providerId) {
delegate.setProviderId(providerId);
}

public Map<String, String> getConfig() {
return delegate.getConfig();
public AttributeMap getConfig(PagingOptions options) {
return new AttributeMap(delegate.getConfig(), options);
}

public void setConfig(Map<String, String> config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

public class MultiAttributeMap extends PagedMap<String, List<String>, MultiAttributeMap.Entry> {

public MultiAttributeMap(Map<String, List<String>> map, PagingOptions options) {
this(map, options != null ? options.start : PagingOptions.DEFAULT.start, options != null ? options.limit : PagingOptions.DEFAULT.limit);
}
public MultiAttributeMap(Map<String, List<String>> map, int start, int limit) {
super(map, start, limit, MultiAttributeMap.Entry.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -681,13 +681,12 @@ public Boolean isEditUsernameAllowed() {
}


public Map<String, String> getBrowserSecurityHeaders() {
return delegate.getBrowserSecurityHeaders();
public HeaderMap getBrowserSecurityHeaders(PagingOptions options) {
return new HeaderMap(delegate.getBrowserSecurityHeaders(), options);
}


public Map<String, String> getSmtpServer() {
return delegate.getSmtpServer();
public AttributeMap getSmtpServer(PagingOptions options) {
return new AttributeMap(delegate.getSmtpServer(), options);
}


Expand Down Expand Up @@ -850,7 +849,7 @@ public void setEventsExpiration(long eventsExpiration) {
delegate.setEventsExpiration(eventsExpiration);
}


// TODO: Paging
public List<String> getEventsListeners() {
return delegate.getEventsListeners();
}
Expand All @@ -861,6 +860,7 @@ public void setEventsListeners(List<String> eventsListeners) {
}


// TODO: Paging
public List<String> getEnabledEventTypes() {
return delegate.getEnabledEventTypes();
}
Expand Down Expand Up @@ -1141,14 +1141,14 @@ public void setOtpSupportedApplications(List<String> otpSupportedApplications) {


// TODO: Paging
public Map<String, Map<String, String>> getLocalizationTexts() {
return delegate.getLocalizationTexts();
}
//public Map<String, Map<String, String>> getLocalizationTexts() {
// return delegate.getLocalizationTexts();
//}


public void setLocalizationTexts(Map<String, Map<String, String>> localizationTexts) {
delegate.setLocalizationTexts(localizationTexts);
}
//public void setLocalizationTexts(Map<String, Map<String, String>> localizationTexts) {
// delegate.setLocalizationTexts(localizationTexts);
//}


public Boolean isOtpPolicyCodeReusable() {
Expand Down Expand Up @@ -1263,6 +1263,7 @@ public void setWebAuthnPolicyAcceptableAaguids(List<String> webAuthnPolicyAccept
}


// TODO: Paging
public List<String> getWebAuthnPolicyExtraOrigins() {
return delegate.getWebAuthnPolicyExtraOrigins();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ public void setContainerId(String containerId) {
delegate.setContainerId(containerId);
}

public Map<String, List<String>> getAttributes() {
return delegate.getAttributes();
public MultiAttributeMap getAttributes(PagingOptions options) {
return new MultiAttributeMap(delegate.getAttributes(), options);
}

public void setAttributes(Map<String, List<String>> attributes) {
delegate.setAttributes(attributes);
}
// public void setAttributes(Map<String, List<String>> attributes) {
// delegate.setAttributes(attributes);
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ public void setEnabled(boolean enabled) {



public Map<String, List<String>> getAttributes() {
return delegate.getAttributes();
public MultiAttributeMap getAttributes(PagingOptions options) {
return new MultiAttributeMap(delegate.getAttributes(), options);
}


Expand Down
Loading

0 comments on commit d51142b

Please sign in to comment.