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

com.healthy.common.security.userdetails.ClientPrincipal Maven / Gradle / Ivy

The newest version!
package com.healthy.common.security.userdetails;

import org.springframework.lang.NonNull;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.oauth2.core.OAuth2AuthenticatedPrincipal;

import java.io.Serializable;
import java.util.*;

/**
 * OAuth2 Client 实体封装对象
 *
 * @author xm.z
 */
public class ClientPrincipal implements OAuth2AuthenticatedPrincipal, Serializable {

	private final String clientId;

	private final Map attributes;

	private final Collection authorities;

	private Set scope = new HashSet<>();

	public ClientPrincipal(String clientId, Map attributes,
			Collection authorities) {
		this.clientId = clientId;
		this.attributes = attributes;
		this.authorities = (authorities != null) ? Collections.unmodifiableCollection(authorities)
				: AuthorityUtils.NO_AUTHORITIES;
	}

	@NonNull
	public Set getScope() {
		return scope;
	}

	public void setScope(Collection scope) {
		this.scope = Collections.unmodifiableSet(scope == null ? new LinkedHashSet<>() : new LinkedHashSet<>(scope));
	}

	@Override
	public Map getAttributes() {
		return attributes;
	}

	@Override
	public Collection getAuthorities() {
		return authorities;
	}

	@Override
	public String getName() {
		return clientId;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy