修改了版本号和天梯仓库路径
This commit is contained in:
@ -8,13 +8,13 @@
|
||||
<parent>
|
||||
<groupId>com.chinaunicom.ebtp</groupId>
|
||||
<artifactId>mall-ebtp-cloud-parent</artifactId>
|
||||
<version>0.0.1</version>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../mall-ebtp-cloud-parent</relativePath>
|
||||
</parent>
|
||||
|
||||
<groupId>com.chinaunicom.ebtp</groupId>
|
||||
<artifactId>mall-ebtp-cloud-security-starter</artifactId>
|
||||
<version>0.0.1</version>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>mall-ebtp-cloud-security-starter</name>
|
||||
|
||||
<dependencies>
|
||||
|
@ -0,0 +1,14 @@
|
||||
package com.chinaunicom.mall.ebtp.cloud.security.starter.entity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class AuthorityEntity {
|
||||
|
||||
private String roleName;
|
||||
private String roleCode;
|
||||
private List<String> authorities;
|
||||
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.chinaunicom.mall.ebtp.cloud.security.starter.entity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class SecurityEntity {
|
||||
|
||||
private String city;
|
||||
private String ou;
|
||||
private String staffType;
|
||||
private List<AuthorityEntity> authorityList;
|
||||
private String userid;
|
||||
private List<String> authorities;
|
||||
private String orgId;
|
||||
private String ouName;
|
||||
private String province;
|
||||
private String staffOrgId;
|
||||
private String staffName;
|
||||
private String tenantId;
|
||||
private String staffId;
|
||||
private String username;
|
||||
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package com.chinaunicom.mall.ebtp.cloud.security.starter.filter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
||||
@ -20,12 +19,16 @@ 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 lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 请求Token拦截
|
||||
*
|
||||
* @author Ajaxfan
|
||||
*/
|
||||
@Slf4j
|
||||
public class TokenAuthenticationFilter extends OncePerRequestFilter {
|
||||
|
||||
private @Autowired RestTemplate restTemplate;
|
||||
@ -41,31 +44,42 @@ public class TokenAuthenticationFilter extends OncePerRequestFilter {
|
||||
@Override
|
||||
protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response,
|
||||
final FilterChain filterChain) throws ServletException, IOException {
|
||||
// 清空上下文中的缓存信息, 防止二次请求时数据异常 (如此, 每次有新的请求进入,都会进行token的验证)
|
||||
SecurityContextHolder.getContext().setAuthentication(null);
|
||||
|
||||
// 提取request头信息
|
||||
final String header = request.getHeader(Constants.AUTHORIZATION_HEADER);
|
||||
|
||||
// 检查请求头是否包含 Bearer 前缀
|
||||
if (StringUtils.startsWith(header, Constants.TOKEN_PREFIX)) {
|
||||
// 提取 token 信息
|
||||
// 移除header的前缀,提取出token字串
|
||||
String authToken = RegExUtils.replaceAll(header, Constants.TOKEN_PREFIX, "");
|
||||
|
||||
// 通过token读取用户信息
|
||||
SecurityContextHolder.getContext().setAuthentication(getAuthentication(authToken));
|
||||
try {// 通过token读取用户信息
|
||||
SecurityContextHolder.getContext().setAuthentication(getAuthentication(authToken));
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
filterChain.doFilter(request, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用山分的认证中心接口,获取该token的绑定信息
|
||||
*
|
||||
* @param token
|
||||
* @return
|
||||
*/
|
||||
private Authentication getAuthentication(String token) {
|
||||
ResponseEntity<Map> entity = restTemplate.getForEntity(createRequestUri(token), Map.class);
|
||||
|
||||
ResponseEntity<SecurityEntity> entity = restTemplate.getForEntity(createRequestUri(token),
|
||||
SecurityEntity.class);
|
||||
|
||||
return new UsernamePasswordAuthenticationToken(entity.getBody(), token);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成山分认证中心请求接口地址
|
||||
*
|
||||
* @param token
|
||||
* @return
|
||||
*/
|
||||
|
@ -1 +1 @@
|
||||
user.auth.resource.token-info-uri=http://125.32.114.204:18091/oauth/check_token
|
||||
user.auth.resource.token-info-uri=http://10.242.31.158:8100/mall-auth/oauth/check_token
|
Reference in New Issue
Block a user