集成权限项目

parent b16ddcbd
......@@ -176,6 +176,11 @@
<version>2.4.2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
......
......@@ -17,7 +17,7 @@ public class FilterConfig extends WebMvcConfigurerAdapter {
//
registry.addInterceptor(InterceptorConfig).
addPathPatterns("/**").
excludePathPatterns("/","/toLogin","/noLogin","/doLogin","/static/**","/refreshCodeCache");
excludePathPatterns("/","/toLogin","/noLogin","/doLogin","/static*//**","/refreshCodeCache","/qxdoLogin");
}
......
......@@ -33,6 +33,7 @@ public class InterceptorConfig implements HandlerInterceptor {
}
}
//协调办案User 信息
System.out.println("拦截seesionid======="+httpServletRequest.getSession().getId());
User systemuser=(User)httpServletRequest.getSession().getAttribute("User");
if(systemuser!=null){
userFlag=true;
......
......@@ -4,27 +4,37 @@ import com.founder.login.service.LoginService;
import com.founder.model.AutoTbStRy;
import com.founder.model.User;
import com.founder.service.AutoTbXwRycjService;
import com.founder.util.HttpClientUtil;
import com.founder.utils.Base64PasswordEncrypter;
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.cookie.Cookie;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import sun.misc.BASE64Encoder;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
......@@ -38,9 +48,13 @@ public class LoginController {
private AutoTbXwRycjService rycjService;
@Autowired
private LoginService loginService;
@Value("${zhyyPath}")
private String zhyyPath;
@Value("${qxUrl}")
private String qxUrl;
@RequestMapping(value="/toHome",method = {RequestMethod.POST,RequestMethod.GET})
public String toHome(HttpServletRequest request, HttpServletResponse response,Model model,String asjxgrybh,String username){
System.out.println("toHome的seesionid======="+request.getSession().getId());
String userId=request.getParameter("userId");
String rybh="";
String returnStr="";
......@@ -131,29 +145,104 @@ public class LoginController {
@RequestMapping("/doLogin")
@ResponseBody
public Map<String,Object> doLogin(HttpServletRequest request){
public Map<String,Object> doLogin(String perurl, HttpServletRequest request,HttpServletResponse response){
String userName=request.getParameter("userId");
String psw=request.getParameter("psw");
String perurl = request.getParameter("perurl");
Map<String,Object> returnMap=new HashMap<>();
User user=null;
try{
user=loginService.getUserByName(userName,psw);
request.getSession().setAttribute("User",user);//登录成功生成session
request.getSession().setAttribute("perurl",perurl);//登录成功生成session
String qxurl=qxUrl+"/xzxt_shiro/admin/pagejump/index";//权限调转页面
request.getSession().setAttribute("qxurl",qxurl);
request.getSession().setAttribute("xtflag",zhyyPath);//系统标志
System.out.println("doLogin的seesionid======="+request.getSession().getId());
if(user!=null){
returnMap.put("state","success");
returnMap.put("msg","登陆成功!");
returnMap.put("user",user);
}else{
returnMap.put("state","failed");
returnMap.put("msg","用户名或密码错误!");
}
}catch (Exception e){
e.printStackTrace();
returnMap.put("state","error");
returnMap.put("msg","登录异常!");
return returnMap;
}
if(user!=null){
request.getSession().setAttribute("User",user);//登录成功生成session
request.getSession().setAttribute("perurl",perurl);//权限url 放入session中
returnMap.put("state","success");
returnMap.put("msg","登陆成功!");
}else{
returnMap.put("state","failed");
returnMap.put("msg","用户名或密码错误!");
return returnMap;
}
//权限登陆
@RequestMapping("/qxdoLogin")
@ResponseBody
public Map<String,Object> qxdoLogin(String username,String password,HttpServletRequest request, HttpServletResponse Response){
Map<String,Object> returnMap=new HashMap<>();
System.out.println("权限seesionid======="+request.getSession().getId());
String url=qxUrl+"/xzxt_shiro/access/xzxtlogin";
String res="";
// 设置默认时间
RequestConfig defaultRequestConfig = RequestConfig.custom()
.setSocketTimeout(5000000)//表示数据传输处理时间
.setConnectTimeout(5000000)//建立连接的timeout时间
.setConnectionRequestTimeout(5000000)
.build();
//创建一个HttpClient
//先建立一个客户端实例,将模拟一个浏览器
CloseableHttpClient httpclient = null;
//创建cookieStore
BasicCookieStore cookieStore = new BasicCookieStore();
//post请求
HttpPost post = null;
httpclient = HttpClients.custom()
.setDefaultCookieStore(cookieStore)//cookieStore是初始化空的
.setDefaultRequestConfig(defaultRequestConfig)
.build();
//建立一个NameValuePair数组,用于存储欲传送的参数
List<NameValuePair> formparams = new ArrayList<NameValuePair>();
/* if(user!=null){
formparams.add(new BasicNameValuePair("username",user.getUsername()));
formparams.add(new BasicNameValuePair("password",new Base64PasswordEncrypter().decryptPassword(user.getPassword())));
}*/
formparams.add(new BasicNameValuePair("username",username));
formparams.add(new BasicNameValuePair("password",password));
//response返回的相应实体
HttpEntity reqEntity = null;
try {
reqEntity = new UrlEncodedFormEntity((List<? extends org.apache.http.NameValuePair>) formparams, "utf-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
post = new HttpPost(url);
//注入post数据
post.setEntity(reqEntity);
//先登陆"http://www.xzxt.nm/login" 拿到cookie
try {
res = HttpClientUtil.doRequest(httpclient, post, cookieStore);
} catch (IOException e) {
e.printStackTrace();
}
//获取Cookies
List<Cookie> cookies = cookieStore.getCookies();
String JSESSIONID="";
for (int i = 0; i < cookies.size(); i++) {
Cookie cookie=cookies.get(i);
if(("JSESSIONID").equals(cookie.getName())){
JSESSIONID=cookie.getValue();
System.out.println("JSESSIONID++++************"+JSESSIONID);
javax.servlet.http.Cookie clientKey_cookie = new javax.servlet.http.Cookie("JSESSIONID", JSESSIONID);
//默认值是-1,表示关闭浏览器,cookie就会消失。
// 如果是正数,表示从现在开始,即将过期的seconds。
clientKey_cookie.setMaxAge(-1);
//放在同一台机子webapp下
clientKey_cookie.setPath("/xzxt_shiro");
//clientKey_cookie.setDomain(domain);
Response.addCookie(clientKey_cookie); //响应返回cookie
}
}
returnMap.put("perurl",res);
return returnMap;
}
@PostMapping("/getLoginUser")
......@@ -162,7 +251,6 @@ public class LoginController {
User user=(User)request.getSession().getAttribute("User");
return user;
}
public static String GetImageStrs(String imgFilePath) {// 将图片文件转化为字节数组字符串,并对其进行Base64编码处理
byte[] data = null;
// 读取图片字节数组
......
......@@ -3,6 +3,7 @@ package com.founder.login.service.impl;
import com.founder.login.dao.LoginDao;
import com.founder.login.service.LoginService;
import com.founder.model.User;
import com.founder.utils.Base64PasswordEncrypter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -42,7 +43,9 @@ public class LoginServiceImpl implements LoginService {
if(userName==null||"".equals(userName)||psw==null||"".equals(psw)){
return user;
}
psw= Base64.getEncoder().encodeToString(psw.getBytes());
//psw= Base64.getEncoder().encodeToString(psw.getBytes());
Base64PasswordEncrypter base = new Base64PasswordEncrypter();
psw = base.encryptPassword(psw);
param.put("userName",userName);
param.put("password",psw);
user=loginDao.queryUserByName(param);
......
package com.founder.util;
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class HttpClientUtil {
public static String doGet(String url, Map<String, String> param) {
// 创建Httpclient对象
CloseableHttpClient httpclient = HttpClients.createDefault();
String resultString = "";
CloseableHttpResponse response = null;
try {
// 创建uri
URIBuilder builder = new URIBuilder(url);
if (param != null) {
for (String key : param.keySet()) {
builder.addParameter(key, param.get(key));
}
}
URI uri = builder.build();
// 创建http GET请求
HttpGet httpGet = new HttpGet(uri);
// 执行请求
response = httpclient.execute(httpGet);
// 判断返回状态是否为200
if (response.getStatusLine().getStatusCode() == 200) {
resultString = EntityUtils.toString(response.getEntity(), "UTF-8");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (response != null) {
response.close();
}
httpclient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return resultString;
}
public static String doGet(String url) {
return doGet(url, null);
}
public static String doPost(String url, Map<String, String> param) {
// 创建Httpclient对象
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response = null;
String resultString = "";
try {
// 创建Http Post请求
HttpPost httpPost = new HttpPost(url);
// 创建参数列表
if (param != null) {
List<NameValuePair> paramList = new ArrayList<>();
for (String key : param.keySet()) {
paramList.add(new BasicNameValuePair(key, param.get(key)));
}
// 模拟表单
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(paramList);
httpPost.setEntity(entity);
}
// 执行http请求
response = httpClient.execute(httpPost);
resultString = EntityUtils.toString(response.getEntity(), "utf-8");
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
response.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return resultString;
}
public static String doPost(String url) {
return doPost(url, null);
}
public static String doPostJson(String url, String json) {
// 创建Httpclient对象
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response = null;
String resultString = "";
try {
// 创建Http Post请求
HttpPost httpPost = new HttpPost(url);
// 创建请求内容
StringEntity entity = new StringEntity(json, ContentType.APPLICATION_JSON);
httpPost.setEntity(entity);
// 执行http请求
response = httpClient.execute(httpPost);
resultString = EntityUtils.toString(response.getEntity(), "utf-8");
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
response.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return resultString;
}
public static String doRequest(CloseableHttpClient httpclient, HttpUriRequest httpUriRequest, BasicCookieStore cookieStore) throws IOException {
//返回相应
CloseableHttpResponse response = httpclient.execute(httpUriRequest);
//获取response返回的相应实体
HttpEntity entity = response.getEntity();
entity.getContent();
//转码
String res= EntityUtils.toString(response.getEntity(), HTTP.UTF_8);
return res;
}
}
package com.founder.util;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;
/**
* Created by changc on 2017/9/13.
*/
public class propertiesUtil {
public static Properties propertiesUtil(String file){
Properties properties = new Properties();
InputStream inStream = propertiesUtil.class.getClassLoader().getResourceAsStream(file);
try {
properties.load(inStream);
} catch (IOException e) {
e.printStackTrace();
}
return properties;
}
public static String getConfig(String file,String key){
Properties pros = new Properties();
String value="";
try {
pros.load(new InputStreamReader(Object.class.getResourceAsStream(file),"UTF-8"));
value=pros.get(key).toString();
} catch (IOException e) {
e.printStackTrace();
}
return value;
}
}
/*File: Base64PasswordEncrypter.java
* date 2013-8-22
*/
package com.founder.utils;
import org.apache.commons.codec.binary.Base64;
import sun.misc.BASE64Encoder;
/**
* <p>Title: Base64PasswordEncrypter.java</p>
* <p>Description: Base64�����㷨</p>
* <p>Copyright: HIGHLAND'S Copyright (c) 2013</p>
* <p>Company: HIGHLAND</p>
* @author highland_team_Luojx
* @date 2013-8-22
* @version 1.0
*/
public class Base64PasswordEncrypter implements IPasswordEncrypter {
public String encryptPassword(String password) {
String encodeTxt = "";
if ((password != null) && (password.length() > 0)) {
encodeTxt = new BASE64Encoder().encode(password.getBytes());
}
return encodeTxt;
}
public boolean isPasswordValid(String password, String encryptedPassword) {
if (encryptedPassword == null) {
throw new IllegalArgumentException(
"encryptedPassword cannot be null");
}
if (password == null) {
password = "";
}
return encryptedPassword.equals(encryptPassword(password));
}
public String encryptPassword(String userName, String password) {
return null;
}
public String decryptPassword(String encodeTxt) {
String password=null;
try{
password =new String(Base64.decodeBase64(encodeTxt.getBytes("UTF-8")),"UTF-8");
}catch(Exception e){
e.printStackTrace();
}
return password;
}
public String grpDecrypt(String s, String s1) {
return null;
}
}
/*File: IPasswordEncrypter.java
* date 2013-8-22
*/
package com.founder.utils;
/**
* <p>Title: IPasswordEncrypter.java</p>
* <p>Description: 系统加密标准接口,需要加密的业务都实现此接口</p>
* <p>Copyright: HIGHLAND'S Copyright (c) 2013</p>
* <p>Company: HIGHLAND</p>
* @author highland_team_Luojx
* @date 2013-8-22
* @version 1.0
*/
public abstract interface IPasswordEncrypter {
public abstract String encryptPassword(String paramString);
public abstract String encryptPassword(String paramString1, String paramString2);
public abstract boolean isPasswordValid(String paramString1, String paramString2);
public abstract String grpDecrypt(String paramString1, String paramString2);
public abstract String decryptPassword(String encodeTxt);
}
......@@ -48,4 +48,5 @@ ThreadPool.queueCapacity=10
zhyyPath=/toLogin
#2、刑专子模块
#zhyyPath=http://zhyy.xzxt.nm:7001
qxUrl=http://127.0.0.1:9044
......@@ -43,4 +43,5 @@ redis.pass=
#1、独立系统
zhyyPath=/toLogin
#2、刑专子模块
#zhyyPath=http://zhyy.xzxt.nm:7001
\ No newline at end of file
#zhyyPath=http://zhyy.xzxt.nm:7001
qxUrl=http://127.0.0.1:9044
\ No newline at end of file
......@@ -125,9 +125,11 @@
<img src="static/xtba/login/images/gzzm_xtgl.png">
<div class="ypgj_con">
<ul>
<li id="X12">
<a onclick="">用户管理</a>
<span th:if="${session.xtflag=='/toLogin'}">
<li id="H">
<a href="" onclick="qxopen()">用户管理</a>
</li>
</span>
<li id="X13">
<a onclick="">日志管理</a>
</li>
......@@ -210,6 +212,7 @@
</div>-->
<!-- 功能菜单 -->
</div>
<div style="" id="qxurl" th:text="${session.qxurl}"></div>
<!--footer-->
<div class="footer">技术支持:方正国际软件有限公司</div>
<script type="text/javascript" src="static/xtba/login/js/jquery-1.11.3.js"></script>
......@@ -296,9 +299,13 @@
function ryxxgl(){
window.open("/toRyxxList?isfirst=1",'_blank');
}
function qxopen(){
var qxurl=$("#qxurl").html();
window.open(qxurl,'_blank');
}
</script>
<!-- 权限机制-->
<div style="display: none" id="perurl" th:text="${session.perurl}"></div>
<div style="" id="perurl" th:text="${session.perurl}"></div>
<script id="scripturlid" src="/common/js/checkurl.js" type="text/javascript"></script>
</body>
</html>
\ No newline at end of file
......@@ -141,23 +141,36 @@
$("#loadgif").show();
var username=$("#username").val();
var password=$("#password").val();
var perurl="admin";
var perurl="admin";//默认权限
var user;
$.ajax({
url:"doLogin",
data:{"userId":username,"psw":password,"perurl":perurl},
url:"qxdoLogin",//权限登陆
data:{"username":username,"password":password},
type:"post",
async: false,
dataType:"json",
success:function(data){
var state=data.state;
var msg=data.msg;
if(state&&state=="success"){
window.location.href="toHome";
}else{
alert(msg);
}
success:function(mgs){
setTimeout("hide()",5000);
perurl=mgs.perurl;
$.ajax({
url:"doLogin",
data:{"userId":username,"psw":password,"perurl":perurl},
type:"post",
dataType:"json",
async: false,
success:function(data){
var state=data.state;
var msg=data.msg;
user=data.user;
if(state&&state=="success"){
window.location.href="toHome";
}else{
alert(msg);
}
}
});
}
});
setTimeout("hide()",5000);
}
function hide(){
$("#loadgif").hide();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment