token移去common包中
This commit is contained in:
+84
-84
@@ -1,84 +1,84 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package com.central.oauth.mobile;
|
package com.central.oauth2.common.token;
|
||||||
|
|
||||||
import org.springframework.security.authentication.AbstractAuthenticationToken;
|
import org.springframework.security.authentication.AbstractAuthenticationToken;
|
||||||
import org.springframework.security.core.GrantedAuthority;
|
import org.springframework.security.core.GrantedAuthority;
|
||||||
import org.springframework.security.core.SpringSecurityCoreVersion;
|
import org.springframework.security.core.SpringSecurityCoreVersion;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author zlt
|
* @author zlt
|
||||||
*/
|
*/
|
||||||
public class MobileAuthenticationToken extends AbstractAuthenticationToken {
|
public class MobileAuthenticationToken extends AbstractAuthenticationToken {
|
||||||
|
|
||||||
private static final long serialVersionUID = SpringSecurityCoreVersion.SERIAL_VERSION_UID;
|
private static final long serialVersionUID = SpringSecurityCoreVersion.SERIAL_VERSION_UID;
|
||||||
|
|
||||||
// ~ Instance fields
|
// ~ Instance fields
|
||||||
// ================================================================================================
|
// ================================================================================================
|
||||||
|
|
||||||
private final Object principal;
|
private final Object principal;
|
||||||
private Object credentials;
|
private Object credentials;
|
||||||
|
|
||||||
// ~ Constructors
|
// ~ Constructors
|
||||||
// ===================================================================================================
|
// ===================================================================================================
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This constructor can be safely used by any code that wishes to create a
|
* This constructor can be safely used by any code that wishes to create a
|
||||||
* <code>UsernamePasswordAuthenticationToken</code>, as the {@link #isAuthenticated()}
|
* <code>UsernamePasswordAuthenticationToken</code>, as the {@link #isAuthenticated()}
|
||||||
* will return <code>false</code>.
|
* will return <code>false</code>.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public MobileAuthenticationToken(String mobile, String password) {
|
public MobileAuthenticationToken(String mobile, String password) {
|
||||||
super(null);
|
super(null);
|
||||||
this.principal = mobile;
|
this.principal = mobile;
|
||||||
this.credentials = password;
|
this.credentials = password;
|
||||||
setAuthenticated(false);
|
setAuthenticated(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This constructor should only be used by <code>AuthenticationManager</code> or
|
* This constructor should only be used by <code>AuthenticationManager</code> or
|
||||||
* <code>AuthenticationProvider</code> implementations that are satisfied with
|
* <code>AuthenticationProvider</code> implementations that are satisfied with
|
||||||
* producing a trusted (i.e. {@link #isAuthenticated()} = <code>true</code>)
|
* producing a trusted (i.e. {@link #isAuthenticated()} = <code>true</code>)
|
||||||
* authentication token.
|
* authentication token.
|
||||||
*
|
*
|
||||||
* @param principal
|
* @param principal
|
||||||
* @param authorities
|
* @param authorities
|
||||||
*/
|
*/
|
||||||
public MobileAuthenticationToken(Object principal, Object credentials,
|
public MobileAuthenticationToken(Object principal, Object credentials,
|
||||||
Collection<? extends GrantedAuthority> authorities) {
|
Collection<? extends GrantedAuthority> authorities) {
|
||||||
super(authorities);
|
super(authorities);
|
||||||
this.principal = principal;
|
this.principal = principal;
|
||||||
this.credentials = credentials;
|
this.credentials = credentials;
|
||||||
super.setAuthenticated(true);
|
super.setAuthenticated(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ~ Methods
|
// ~ Methods
|
||||||
// ========================================================================================================
|
// ========================================================================================================
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getCredentials() {
|
public Object getCredentials() {
|
||||||
return this.credentials;
|
return this.credentials;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getPrincipal() {
|
public Object getPrincipal() {
|
||||||
return this.principal;
|
return this.principal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setAuthenticated(boolean isAuthenticated) {
|
public void setAuthenticated(boolean isAuthenticated) {
|
||||||
if (isAuthenticated) {
|
if (isAuthenticated) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Cannot set this token to trusted - use constructor which takes a GrantedAuthority list instead");
|
"Cannot set this token to trusted - use constructor which takes a GrantedAuthority list instead");
|
||||||
}
|
}
|
||||||
super.setAuthenticated(false);
|
super.setAuthenticated(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void eraseCredentials() {
|
public void eraseCredentials() {
|
||||||
super.eraseCredentials();
|
super.eraseCredentials();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+78
-78
@@ -1,78 +1,78 @@
|
|||||||
package com.central.oauth.openid;
|
package com.central.oauth2.common.token;
|
||||||
|
|
||||||
import org.springframework.security.authentication.AbstractAuthenticationToken;
|
import org.springframework.security.authentication.AbstractAuthenticationToken;
|
||||||
import org.springframework.security.core.GrantedAuthority;
|
import org.springframework.security.core.GrantedAuthority;
|
||||||
import org.springframework.security.core.SpringSecurityCoreVersion;
|
import org.springframework.security.core.SpringSecurityCoreVersion;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author zlt
|
* @author zlt
|
||||||
*/
|
*/
|
||||||
public class OpenIdAuthenticationToken extends AbstractAuthenticationToken {
|
public class OpenIdAuthenticationToken extends AbstractAuthenticationToken {
|
||||||
|
|
||||||
private static final long serialVersionUID = SpringSecurityCoreVersion.SERIAL_VERSION_UID;
|
private static final long serialVersionUID = SpringSecurityCoreVersion.SERIAL_VERSION_UID;
|
||||||
|
|
||||||
// ~ Instance fields
|
// ~ Instance fields
|
||||||
// ================================================================================================
|
// ================================================================================================
|
||||||
|
|
||||||
private final Object principal;
|
private final Object principal;
|
||||||
|
|
||||||
// ~ Constructors
|
// ~ Constructors
|
||||||
// ===================================================================================================
|
// ===================================================================================================
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This constructor can be safely used by any code that wishes to create a
|
* This constructor can be safely used by any code that wishes to create a
|
||||||
* <code>UsernamePasswordAuthenticationToken</code>, as the {@link #isAuthenticated()}
|
* <code>UsernamePasswordAuthenticationToken</code>, as the {@link #isAuthenticated()}
|
||||||
* will return <code>false</code>.
|
* will return <code>false</code>.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public OpenIdAuthenticationToken(String openId) {
|
public OpenIdAuthenticationToken(String openId) {
|
||||||
super(null);
|
super(null);
|
||||||
this.principal = openId;
|
this.principal = openId;
|
||||||
setAuthenticated(false);
|
setAuthenticated(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This constructor should only be used by <code>AuthenticationManager</code> or
|
* This constructor should only be used by <code>AuthenticationManager</code> or
|
||||||
* <code>AuthenticationProvider</code> implementations that are satisfied with
|
* <code>AuthenticationProvider</code> implementations that are satisfied with
|
||||||
* producing a trusted (i.e. {@link #isAuthenticated()} = <code>true</code>)
|
* producing a trusted (i.e. {@link #isAuthenticated()} = <code>true</code>)
|
||||||
* authentication token.
|
* authentication token.
|
||||||
*
|
*
|
||||||
* @param principal
|
* @param principal
|
||||||
* @param authorities
|
* @param authorities
|
||||||
*/
|
*/
|
||||||
public OpenIdAuthenticationToken(Object principal,
|
public OpenIdAuthenticationToken(Object principal,
|
||||||
Collection<? extends GrantedAuthority> authorities) {
|
Collection<? extends GrantedAuthority> authorities) {
|
||||||
super(authorities);
|
super(authorities);
|
||||||
this.principal = principal;
|
this.principal = principal;
|
||||||
super.setAuthenticated(true);
|
super.setAuthenticated(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ~ Methods
|
// ~ Methods
|
||||||
// ========================================================================================================
|
// ========================================================================================================
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getCredentials() {
|
public Object getCredentials() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getPrincipal() {
|
public Object getPrincipal() {
|
||||||
return this.principal;
|
return this.principal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setAuthenticated(boolean isAuthenticated) {
|
public void setAuthenticated(boolean isAuthenticated) {
|
||||||
if (isAuthenticated) {
|
if (isAuthenticated) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Cannot set this token to trusted - use constructor which takes a GrantedAuthority list instead");
|
"Cannot set this token to trusted - use constructor which takes a GrantedAuthority list instead");
|
||||||
}
|
}
|
||||||
super.setAuthenticated(false);
|
super.setAuthenticated(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void eraseCredentials() {
|
public void eraseCredentials() {
|
||||||
super.eraseCredentials();
|
super.eraseCredentials();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,8 +2,8 @@ package com.central.oauth.controller;
|
|||||||
|
|
||||||
import com.central.common.constant.SecurityConstants;
|
import com.central.common.constant.SecurityConstants;
|
||||||
import com.central.common.model.Result;
|
import com.central.common.model.Result;
|
||||||
import com.central.oauth.mobile.MobileAuthenticationToken;
|
import com.central.oauth2.common.token.MobileAuthenticationToken;
|
||||||
import com.central.oauth.openid.OpenIdAuthenticationToken;
|
import com.central.oauth2.common.token.OpenIdAuthenticationToken;
|
||||||
import com.central.oauth2.common.util.AuthUtils;
|
import com.central.oauth2.common.util.AuthUtils;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.central.oauth.mobile;
|
package com.central.oauth.mobile;
|
||||||
|
|
||||||
import com.central.oauth.service.ZltUserDetailsService;
|
import com.central.oauth.service.ZltUserDetailsService;
|
||||||
|
import com.central.oauth2.common.token.MobileAuthenticationToken;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import org.springframework.security.authentication.AuthenticationProvider;
|
import org.springframework.security.authentication.AuthenticationProvider;
|
||||||
import org.springframework.security.authentication.BadCredentialsException;
|
import org.springframework.security.authentication.BadCredentialsException;
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package com.central.oauth.openid;
|
package com.central.oauth.openid;
|
||||||
|
|
||||||
|
import com.central.oauth2.common.token.OpenIdAuthenticationToken;
|
||||||
import org.springframework.security.authentication.AuthenticationProvider;
|
import org.springframework.security.authentication.AuthenticationProvider;
|
||||||
import org.springframework.security.authentication.InternalAuthenticationServiceException;
|
import org.springframework.security.authentication.InternalAuthenticationServiceException;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.security.core.AuthenticationException;
|
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
import org.springframework.social.security.SocialUserDetailsService;
|
import org.springframework.social.security.SocialUserDetailsService;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user