package com.kidgrow.authclient.token;
|
|
import org.springframework.security.authentication.AbstractAuthenticationToken;
|
import org.springframework.security.core.GrantedAuthority;
|
import org.springframework.security.core.SpringSecurityCoreVersion;
|
|
import java.util.Collection;
|
|
/**
|
* 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br>
|
*
|
* @Description: <br>
|
* @Project: <br>
|
* @CreateDate: Created in 2020/2/13 11:42 <br>
|
* @Author: <a href="4345453@kidgrow.com">liuke</a>
|
*/
|
public class OpenIdAuthenticationToken extends AbstractAuthenticationToken {
|
|
private static final long serialVersionUID = SpringSecurityCoreVersion.SERIAL_VERSION_UID;
|
|
// ~ Instance fields
|
// ================================================================================================
|
|
private final Object principal;
|
|
// ~ Constructors
|
// ===================================================================================================
|
|
/**
|
* This constructor can be safely used by any code that wishes to create a
|
* <code>UsernamePasswordAuthenticationToken</code>, as the {@link #isAuthenticated()}
|
* will return <code>false</code>.
|
*
|
*/
|
public OpenIdAuthenticationToken(String openId) {
|
super(null);
|
this.principal = openId;
|
setAuthenticated(false);
|
}
|
|
/**
|
* This constructor should only be used by <code>AuthenticationManager</code> or
|
* <code>AuthenticationProvider</code> implementations that are satisfied with
|
* producing a trusted (i.e. {@link #isAuthenticated()} = <code>true</code>)
|
* authentication token.
|
*
|
* @param principal
|
* @param authorities
|
*/
|
public OpenIdAuthenticationToken(Object principal,
|
Collection<? extends GrantedAuthority> authorities) {
|
super(authorities);
|
this.principal = principal;
|
super.setAuthenticated(true);
|
}
|
|
// ~ Methods
|
// ========================================================================================================
|
|
@Override
|
public Object getCredentials() {
|
return null;
|
}
|
|
@Override
|
public Object getPrincipal() {
|
return this.principal;
|
}
|
|
@Override
|
public void setAuthenticated(boolean isAuthenticated) {
|
if (isAuthenticated) {
|
throw new IllegalArgumentException(
|
"Cannot set this token to trusted - use constructor which takes a GrantedAuthority list instead");
|
}
|
super.setAuthenticated(false);
|
}
|
|
@Override
|
public void eraseCredentials() {
|
super.eraseCredentials();
|
}
|
}
|