Java tutorial
/* * Copyright (C) 2013 tarent AG * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package org.osiam.security.authentication; import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.HashSet; import java.util.Map; import java.util.Set; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.oauth2.provider.ClientDetails; /** * OSIAM {@link ClientDetails} implementation. */ public class OsiamClientDetails implements ClientDetails { private static final long serialVersionUID = 4649122233093279685L; private String id; private String clientSecret; private Set<String> scope; private Set<String> grants; private String redirectUri; private Integer accessTokenValiditySeconds; private Integer refreshTokenValiditySeconds; private Date expiry; private boolean implicit; private long validityInSeconds; @Override public String getClientId() { return id; } /** * Get a set of resource id's. * * @return always empty */ @Override public Set<String> getResourceIds() { return Collections.emptySet(); } @Override public boolean isSecretRequired() { return true; } @Override public String getClientSecret() { return clientSecret; } @Override public boolean isScoped() { return true; } @Override public Set<String> getScope() { return scope; } @Override public Set<String> getAuthorizedGrantTypes() { return grants; } @Override public Set<String> getRegisteredRedirectUri() { Set<String> result = new HashSet<>(); result.add(redirectUri); return result; } @Override public Collection<GrantedAuthority> getAuthorities() { return Collections.emptySet(); } /** * Get the access token validity seconds. * * @return the accessTokenValiditySeconds */ @Override public Integer getAccessTokenValiditySeconds() { return accessTokenValiditySeconds; } /** * Get the refresh token validity seconds. * * @return always returns the accessTokenValiditySeconds */ @Override public Integer getRefreshTokenValiditySeconds() { return refreshTokenValiditySeconds; } @Override public Map<String, Object> getAdditionalInformation() { return Collections.emptyMap(); } public String getId() { return id; } public void setId(String id) { this.id = id; } public void setClientSecret(String clientSecret) { this.clientSecret = clientSecret; } public void setScope(Set<String> scope) { this.scope = scope; } public Set<String> getGrants() { return grants; } public void setGrants(Set<String> grants) { this.grants = grants; } public String getRedirectUri() { return redirectUri; } public void setRedirectUri(String redirectUri) { this.redirectUri = redirectUri; } public void setAccessTokenValiditySeconds(Integer accessTokenValiditySeconds) { this.accessTokenValiditySeconds = accessTokenValiditySeconds; } public void setRefreshTokenValiditySeconds(Integer refreshTokenValiditySeconds) { this.refreshTokenValiditySeconds = refreshTokenValiditySeconds; } public Date getExpiry() { return expiry != null ? (Date) expiry.clone() : null; } public void setExpiry(Date expiry) { this.expiry = expiry != null ? (Date) expiry.clone() : null; } public boolean isImplicit() { return implicit; } public void setImplicit(boolean implicit) { this.implicit = implicit; } public long getValidityInSeconds() { return validityInSeconds; } public void setValidityInSeconds(long validity) { validityInSeconds = validity; } }