61 lines
1.5 KiB
Java
61 lines
1.5 KiB
Java
package com.newyetai.security.cas;
|
|
|
|
import java.util.Collection;
|
|
|
|
import org.springframework.security.authentication.AbstractAuthenticationToken;
|
|
import org.springframework.security.core.GrantedAuthority;
|
|
|
|
/**
|
|
* cas认证信息
|
|
*
|
|
* @author sr on 2020-06-04
|
|
*/
|
|
public class CasAuthenticationToken extends AbstractAuthenticationToken {
|
|
|
|
/** **/
|
|
private static final long serialVersionUID = 4078096826251434490L;
|
|
|
|
private final Object principal;
|
|
private String credentials;
|
|
|
|
public CasAuthenticationToken(Object principal, String credentials) {
|
|
super(null);
|
|
this.principal = principal;
|
|
this.credentials = credentials;
|
|
setAuthenticated(false);
|
|
}
|
|
|
|
public CasAuthenticationToken(Object principal,
|
|
Collection<? extends GrantedAuthority> authorities) {
|
|
super(authorities);
|
|
this.principal = principal;
|
|
this.credentials = null;
|
|
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;
|
|
}
|
|
}
|