增加了新版本的认证服务接口
This commit is contained in:
@ -7,10 +7,9 @@ import lombok.Data;
|
||||
@Data
|
||||
public class AuthorityEntity {
|
||||
|
||||
private String roleId;
|
||||
private String roleName;
|
||||
private String roleCode;
|
||||
private String roleScope;
|
||||
private String roleId;
|
||||
private List<String> authorities;
|
||||
|
||||
|
||||
}
|
||||
|
@ -11,6 +11,9 @@ import org.apache.commons.lang3.RegExUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.Authentication;
|
||||
@ -19,7 +22,7 @@ import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.filter.OncePerRequestFilter;
|
||||
|
||||
import com.chinaunicom.mall.ebtp.cloud.security.starter.common.Constants;
|
||||
import com.chinaunicom.mall.ebtp.cloud.security.starter.entity.SecurityEntity;
|
||||
import com.chinaunicom.mall.ebtp.cloud.security.starter.entity.SecurityUser;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@ -32,7 +35,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
public class TokenAuthenticationFilter extends OncePerRequestFilter {
|
||||
|
||||
private @Autowired RestTemplate restTemplate;
|
||||
private @Value("${user.auth.resource.token-info-uri}") String token_uri;
|
||||
private @Value("${user.auth.resource.userinfo}") String token_uri;
|
||||
|
||||
/**
|
||||
* @param request
|
||||
@ -71,20 +74,14 @@ public class TokenAuthenticationFilter extends OncePerRequestFilter {
|
||||
* @return
|
||||
*/
|
||||
private Authentication getAuthentication(String token) {
|
||||
ResponseEntity<SecurityEntity> entity = restTemplate.getForEntity(createRequestUri(token),
|
||||
SecurityEntity.class);
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
// 设置安全头
|
||||
headers.add(HttpHeaders.AUTHORIZATION, String.format("Bearer %s", token));
|
||||
|
||||
ResponseEntity<SecurityUser> entity = restTemplate.exchange(token_uri, HttpMethod.GET,
|
||||
new HttpEntity<String>(headers), SecurityUser.class);
|
||||
|
||||
return new UsernamePasswordAuthenticationToken(entity.getBody(), token);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成山分认证中心请求接口地址
|
||||
*
|
||||
* @param token
|
||||
* @return
|
||||
*/
|
||||
private String createRequestUri(String token) {
|
||||
return new StringBuilder(token_uri).append("?token=").append(token).toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,2 +1,2 @@
|
||||
user.auth.resource.token-info-uri=http://10.242.31.158:8100/mall-auth/oauth/check_token
|
||||
user.auth.resource.token-info-uri=http://10.242.31.158:8100/core-service-ebtp-userinfo/v1/userinfo/get
|
||||
user.auth.csrf.disable=true
|
Reference in New Issue
Block a user