1.SG-UAP3.0开发平台微服务架构路线
2.SG-UAP3.0开发平台微服务架构
3.SG-UAP3.0开发平台微服务与isc集成方案
项目组所开发的系统在部署阶段,若没有使用分布式服务总线,前端web工程(IDE生成)需集成isc(通过isc_sso完成前端鉴权),前端登录后请求后端并将用户信息传递过去,后端每个微服务需进行登录会话校验(在后端服务添加过滤器,获取用户信息及资源信息,通过调用isc相应接口进行判断此用户是否授权),后端微服务暴露出的restful请求在isc中进行用户权限配置 ,同样,在服务调用服务的时候,调用方需将用户信息传递给被调用方进行鉴权操作
4.SG-UAP3.0开发平台微服务与isc集成方案具体实现
Ø 前端工程添加所需jar包
Ø 在web.xml中加入统一认证过虑器、获取用户信息GetCurrentUser、系统注销IscLogoutServlet、系统注销监听(红框为原有基础上新增内容,表示具备代理能力)。
Ø 微服务端添加jar包
Ø 注意:isc_sm_agent.jar中的iscservicesadapter.properties文件需要配置isc服务地址及isc_appid
Ø 微服务添加过滤器
@Order(1)
@WebFilter(filterName = "MicAuthorizeFilter", urlPatterns = "/*")
public class MicAuthorizeFilter extends HttpServlet implements Filter{
@Value("${spring.isc_appId}")
private String isc_appId;
//isc资源服务接口
private IResourceService ress = (IResourceService) AdapterFactory.getResourceService();
@Override
public void destroy() {
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletResponse httpResponse = (HttpServletResponse) response;
String url = httpRequest.getRequestURI().substring(httpRequest.getContextPath().length());
if (url.startsWith("/") && url.length() > 1) {
url = url.substring(1).split("/")[0];
}
String iscUserId = httpRequest.getParameter("cl_u_id");
boolean isPer=false;
if(null==httpRequest.getSession(false)){
if(true==httpRequest.getSession(true).isNew()){
System.out.println("session没有过期");
}else{
System.out.println("session已经过期");
String authorizeState = "timeout";
PrintWriter pw = null;
try {
pw = response.getWriter();
pw.write(authorizeState);
} catch (IOException e) {
e.printStackTrace();
}finally{
pw.flush();
pw.close();
}
return;
}
}
if(null==iscUserId||("").equals(iscUserId)){
System.out.println("没有登录,请联系管理员");
//如果没有登录,将跳转到登录界面
return;
}
try {//校验此用户是否有访问url的权限
isPer= ress.hasPermitURLObj(iscUserId, isc_appId, url);
} catch (Exception e) {
e.printStackTrace();
}
if (isPer==true){
chain.doFilter(httpRequest, httpResponse);
return;
}else{
System.out.println("没有权限访问,请联系管理员");
//如果没有权限,将跳转到提示界面
String authorizeState = "authorizeFail";
PrintWriter pw = null;
try {
pw = response.getWriter();
pw.write(authorizeState);
} catch (IOException e) {
e.printStackTrace();
}finally{
pw.flush();
pw.close();
}
return;
}
}
@Override
public void init(FilterConfig arg0) throws ServletException {
}
}
在application.properties进行配置
spring.isc_appId=402894675c5c3ef8015d3f2bc5aa0684//业务系统id
所有评论(0)