All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.springframework.security.oauth2.provider.client.BaseClientDetails Maven / Gradle / Ivy

There is a newer version: 2.5.2.RELEASE
Show newest version
package org.springframework.security.oauth2.provider.client;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.oauth2.provider.ClientDetails;
import org.springframework.util.StringUtils;

/**
 * Base implementation of
 * {@link org.springframework.security.oauth2.provider.ClientDetails}.
 *
 * 

* @deprecated See the OAuth 2.0 Migration Guide for Spring Security 5. * * @author Ryan Heaton * @author Dave Syer */ @SuppressWarnings("serial") @com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_DEFAULT) @com.fasterxml.jackson.annotation.JsonIgnoreProperties(ignoreUnknown = true) @Deprecated public class BaseClientDetails implements ClientDetails { @com.fasterxml.jackson.annotation.JsonProperty("client_id") private String clientId; @com.fasterxml.jackson.annotation.JsonProperty("client_secret") private String clientSecret; @com.fasterxml.jackson.databind.annotation.JsonDeserialize(using = Jackson2ArrayOrStringDeserializer.class) private Set scope = Collections.emptySet(); @com.fasterxml.jackson.annotation.JsonProperty("resource_ids") @com.fasterxml.jackson.databind.annotation.JsonDeserialize(using = Jackson2ArrayOrStringDeserializer.class) private Set resourceIds = Collections.emptySet(); @com.fasterxml.jackson.annotation.JsonProperty("authorized_grant_types") @com.fasterxml.jackson.databind.annotation.JsonDeserialize(using = Jackson2ArrayOrStringDeserializer.class) private Set authorizedGrantTypes = Collections.emptySet(); @com.fasterxml.jackson.annotation.JsonProperty("redirect_uri") @com.fasterxml.jackson.databind.annotation.JsonDeserialize(using = Jackson2ArrayOrStringDeserializer.class) private Set registeredRedirectUris; @com.fasterxml.jackson.annotation.JsonProperty("autoapprove") @com.fasterxml.jackson.databind.annotation.JsonDeserialize(using = Jackson2ArrayOrStringDeserializer.class) private Set autoApproveScopes; private List authorities = Collections.emptyList(); @com.fasterxml.jackson.annotation.JsonProperty("access_token_validity") private Integer accessTokenValiditySeconds; @com.fasterxml.jackson.annotation.JsonProperty("refresh_token_validity") private Integer refreshTokenValiditySeconds; @com.fasterxml.jackson.annotation.JsonIgnore private Map additionalInformation = new LinkedHashMap(); public BaseClientDetails() { } public BaseClientDetails(ClientDetails prototype) { this(); setAccessTokenValiditySeconds(prototype.getAccessTokenValiditySeconds()); setRefreshTokenValiditySeconds(prototype .getRefreshTokenValiditySeconds()); setAuthorities(prototype.getAuthorities()); setAuthorizedGrantTypes(prototype.getAuthorizedGrantTypes()); setClientId(prototype.getClientId()); setClientSecret(prototype.getClientSecret()); setRegisteredRedirectUri(prototype.getRegisteredRedirectUri()); setScope(prototype.getScope()); setResourceIds(prototype.getResourceIds()); } public BaseClientDetails(String clientId, String resourceIds, String scopes, String grantTypes, String authorities) { this(clientId, resourceIds, scopes, grantTypes, authorities, null); } public BaseClientDetails(String clientId, String resourceIds, String scopes, String grantTypes, String authorities, String redirectUris) { this.clientId = clientId; if (StringUtils.hasText(resourceIds)) { Set resources = StringUtils .commaDelimitedListToSet(resourceIds); if (!resources.isEmpty()) { this.resourceIds = resources; } } if (StringUtils.hasText(scopes)) { Set scopeList = StringUtils.commaDelimitedListToSet(scopes); if (!scopeList.isEmpty()) { this.scope = scopeList; } } if (StringUtils.hasText(grantTypes)) { this.authorizedGrantTypes = StringUtils .commaDelimitedListToSet(grantTypes); } else { this.authorizedGrantTypes = new HashSet(Arrays.asList( "authorization_code", "refresh_token")); } if (StringUtils.hasText(authorities)) { this.authorities = AuthorityUtils .commaSeparatedStringToAuthorityList(authorities); } if (StringUtils.hasText(redirectUris)) { this.registeredRedirectUris = StringUtils .commaDelimitedListToSet(redirectUris); } } @com.fasterxml.jackson.annotation.JsonIgnore public String getClientId() { return clientId; } public void setClientId(String clientId) { this.clientId = clientId; } public void setAutoApproveScopes(Collection autoApproveScopes) { this.autoApproveScopes = new HashSet(autoApproveScopes); } @Override public boolean isAutoApprove(String scope) { if (autoApproveScopes == null) { return false; } for (String auto : autoApproveScopes) { if (auto.equals("true") || scope.matches(auto)) { return true; } } return false; } @com.fasterxml.jackson.annotation.JsonIgnore public Set getAutoApproveScopes() { return autoApproveScopes; } @com.fasterxml.jackson.annotation.JsonIgnore public boolean isSecretRequired() { return this.clientSecret != null; } @com.fasterxml.jackson.annotation.JsonIgnore public String getClientSecret() { return clientSecret; } public void setClientSecret(String clientSecret) { this.clientSecret = clientSecret; } @com.fasterxml.jackson.annotation.JsonIgnore public boolean isScoped() { return this.scope != null && !this.scope.isEmpty(); } public Set getScope() { return scope; } public void setScope(Collection scope) { this.scope = scope == null ? Collections. emptySet() : new LinkedHashSet(scope); } @com.fasterxml.jackson.annotation.JsonIgnore public Set getResourceIds() { return resourceIds; } public void setResourceIds(Collection resourceIds) { this.resourceIds = resourceIds == null ? Collections . emptySet() : new LinkedHashSet(resourceIds); } @com.fasterxml.jackson.annotation.JsonIgnore public Set getAuthorizedGrantTypes() { return authorizedGrantTypes; } public void setAuthorizedGrantTypes(Collection authorizedGrantTypes) { this.authorizedGrantTypes = new LinkedHashSet( authorizedGrantTypes); } @com.fasterxml.jackson.annotation.JsonIgnore public Set getRegisteredRedirectUri() { return registeredRedirectUris; } public void setRegisteredRedirectUri(Set registeredRedirectUris) { this.registeredRedirectUris = registeredRedirectUris == null ? null : new LinkedHashSet(registeredRedirectUris); } @com.fasterxml.jackson.annotation.JsonProperty("authorities") private List getAuthoritiesAsStrings() { return new ArrayList( AuthorityUtils.authorityListToSet(authorities)); } @com.fasterxml.jackson.annotation.JsonProperty("authorities") @com.fasterxml.jackson.databind.annotation.JsonDeserialize(using = Jackson2ArrayOrStringDeserializer.class) private void setAuthoritiesAsStrings(Set values) { setAuthorities(AuthorityUtils.createAuthorityList(values .toArray(new String[values.size()]))); } @com.fasterxml.jackson.annotation.JsonIgnore public Collection getAuthorities() { return authorities; } @com.fasterxml.jackson.annotation.JsonIgnore public void setAuthorities( Collection authorities) { this.authorities = new ArrayList(authorities); } @com.fasterxml.jackson.annotation.JsonIgnore public Integer getAccessTokenValiditySeconds() { return accessTokenValiditySeconds; } public void setAccessTokenValiditySeconds(Integer accessTokenValiditySeconds) { this.accessTokenValiditySeconds = accessTokenValiditySeconds; } @com.fasterxml.jackson.annotation.JsonIgnore public Integer getRefreshTokenValiditySeconds() { return refreshTokenValiditySeconds; } public void setRefreshTokenValiditySeconds( Integer refreshTokenValiditySeconds) { this.refreshTokenValiditySeconds = refreshTokenValiditySeconds; } public void setAdditionalInformation(Map additionalInformation) { this.additionalInformation = new LinkedHashMap( additionalInformation); } @com.fasterxml.jackson.annotation.JsonAnyGetter public Map getAdditionalInformation() { return Collections.unmodifiableMap(this.additionalInformation); } @com.fasterxml.jackson.annotation.JsonAnySetter public void addAdditionalInformation(String key, Object value) { this.additionalInformation.put(key, value); } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((accessTokenValiditySeconds == null) ? 0 : accessTokenValiditySeconds); result = prime * result + ((refreshTokenValiditySeconds == null) ? 0 : refreshTokenValiditySeconds); result = prime * result + ((authorities == null) ? 0 : authorities.hashCode()); result = prime * result + ((authorizedGrantTypes == null) ? 0 : authorizedGrantTypes .hashCode()); result = prime * result + ((clientId == null) ? 0 : clientId.hashCode()); result = prime * result + ((clientSecret == null) ? 0 : clientSecret.hashCode()); result = prime * result + ((registeredRedirectUris == null) ? 0 : registeredRedirectUris.hashCode()); result = prime * result + ((resourceIds == null) ? 0 : resourceIds.hashCode()); result = prime * result + ((scope == null) ? 0 : scope.hashCode()); result = prime * result + ((additionalInformation == null) ? 0 : additionalInformation.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; BaseClientDetails other = (BaseClientDetails) obj; if (accessTokenValiditySeconds == null) { if (other.accessTokenValiditySeconds != null) return false; } else if (!accessTokenValiditySeconds.equals(other.accessTokenValiditySeconds)) return false; if (refreshTokenValiditySeconds == null) { if (other.refreshTokenValiditySeconds != null) return false; } else if (!refreshTokenValiditySeconds.equals(other.refreshTokenValiditySeconds)) return false; if (authorities == null) { if (other.authorities != null) return false; } else if (!authorities.equals(other.authorities)) return false; if (authorizedGrantTypes == null) { if (other.authorizedGrantTypes != null) return false; } else if (!authorizedGrantTypes.equals(other.authorizedGrantTypes)) return false; if (clientId == null) { if (other.clientId != null) return false; } else if (!clientId.equals(other.clientId)) return false; if (clientSecret == null) { if (other.clientSecret != null) return false; } else if (!clientSecret.equals(other.clientSecret)) return false; if (registeredRedirectUris == null) { if (other.registeredRedirectUris != null) return false; } else if (!registeredRedirectUris.equals(other.registeredRedirectUris)) return false; if (resourceIds == null) { if (other.resourceIds != null) return false; } else if (!resourceIds.equals(other.resourceIds)) return false; if (scope == null) { if (other.scope != null) return false; } else if (!scope.equals(other.scope)) return false; if (additionalInformation == null) { if (other.additionalInformation != null) return false; } else if (!additionalInformation.equals(other.additionalInformation)) return false; return true; } @Override public String toString() { return "BaseClientDetails [clientId=" + clientId + ", clientSecret=" + clientSecret + ", scope=" + scope + ", resourceIds=" + resourceIds + ", authorizedGrantTypes=" + authorizedGrantTypes + ", registeredRedirectUris=" + registeredRedirectUris + ", authorities=" + authorities + ", accessTokenValiditySeconds=" + accessTokenValiditySeconds + ", refreshTokenValiditySeconds=" + refreshTokenValiditySeconds + ", additionalInformation=" + additionalInformation + "]"; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy