63 lines
1.8 KiB
Java
63 lines
1.8 KiB
Java
package com.cm.serviceusercenter.authentication.dingding;
|
|
|
|
import org.springframework.security.authentication.AbstractAuthenticationToken;
|
|
import org.springframework.security.core.GrantedAuthority;
|
|
|
|
import java.util.Collection;
|
|
|
|
/**
|
|
* When you feel like quitting. Think about why you started
|
|
* 当你想要放弃的时候,想想当初你为何开始
|
|
*
|
|
* @ClassName: DingDingAuthenticationToken
|
|
* @Description: 钉钉认证Token
|
|
* @Author: WangGeng
|
|
* @Date: 2020/8/31 15:11
|
|
* @Version: 1.0
|
|
**/
|
|
public class DingDingAuthenticationToken extends AbstractAuthenticationToken {
|
|
|
|
private final Object principal;
|
|
private Object credentials;
|
|
|
|
public DingDingAuthenticationToken(Object principal, Object credentials) {
|
|
super(null);
|
|
this.principal = principal;
|
|
this.credentials = credentials;
|
|
setAuthenticated(false);
|
|
}
|
|
|
|
public DingDingAuthenticationToken(Object principal, Object credentials,
|
|
Collection<? extends GrantedAuthority> authorities) {
|
|
super(authorities);
|
|
this.principal = principal;
|
|
this.credentials = credentials;
|
|
super.setAuthenticated(true);
|
|
}
|
|
|
|
@Override
|
|
public Object getCredentials() {
|
|
return this.credentials;
|
|
}
|
|
|
|
@Override
|
|
public Object getPrincipal() {
|
|
return this.principal;
|
|
}
|
|
|
|
@Override
|
|
public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
|
|
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();
|
|
credentials = null;
|
|
}
|
|
}
|