密码管理器增加uid设定

This commit is contained in:
yutou 2021-02-20 17:53:31 +08:00
parent 5aca836fef
commit ce5fcad1dd
8 changed files with 262 additions and 30 deletions

View File

@ -8,6 +8,7 @@ import com.yutou.tools.mybatis.model.ToolsPassword;
import com.yutou.tools.mybatis.model.ToolsPasswordExample;
import com.yutou.tools.mybatis.model.ToolsPasswordType;
import com.yutou.tools.mybatis.model.ToolsPasswordTypeExample;
import com.yutou.tools.other.tools;
import com.yutou.tools.utils.AESTools;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
@ -16,6 +17,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
@Controller
@ -26,13 +28,16 @@ public class PasswordManager {
ToolsPasswordDao passwordDao;
@Resource
ToolsPasswordTypeDao passwordTypeDao;
@Resource
tools tls;
@ResponseBody
@RequestMapping(value = "get/list.do",method = RequestMethod.GET)
public String getPasswordList(String type){
public String getPasswordList(HttpServletRequest request,String type){
JSONObject json=new JSONObject();
int id=tls.getUid(request);
ToolsPasswordExample example=new ToolsPasswordExample();
example.createCriteria().andTypeEqualTo(Integer.parseInt(type));
example.createCriteria().andTypeEqualTo(Integer.parseInt(type)).andUidEqualTo(id);
List<ToolsPassword> passwords=passwordDao.selectByExample(example);
for (ToolsPassword password : passwords) {
password.setPassword("*****");
@ -44,18 +49,47 @@ public class PasswordManager {
}
@ResponseBody
@RequestMapping(value = "get/password.do",method = RequestMethod.GET)
public String getPassword(String id){
public String getPassword(HttpServletRequest request,String id){
JSONObject json=new JSONObject();
ToolsPassword password=passwordDao.selectByPrimaryKey(Integer.parseInt(id));
int uid=tls.getUid(request);
ToolsPasswordExample example=new ToolsPasswordExample();
example.createCriteria().andIdEqualTo(Integer.parseInt(id)).andUidEqualTo(uid);
ToolsPassword password=passwordDao.selectByExample(example).get(0);
json.put("code",0);
json.put("data",AESTools.decrypt(password.getPassword()));
return json.toJSONString();
}
@ResponseBody
@RequestMapping(value = "type/get/list.do",method = RequestMethod.GET)
public String getPasswordType(){
@RequestMapping(value = "get/all.do",method = RequestMethod.GET)
public String getAllPassword(HttpServletRequest request){
JSONObject json=new JSONObject();
List<ToolsPasswordType> toolsPasswordTypes=passwordTypeDao.selectByExample(new ToolsPasswordTypeExample());
JSONArray array=new JSONArray();
int uid=tls.getUid(request);
if(uid==-1){
return "";
}
ToolsPasswordExample example=new ToolsPasswordExample();
example.createCriteria().andUidEqualTo(uid);
List<ToolsPassword> list=passwordDao.selectByExample(example);
for (ToolsPassword password : list) {
JSONObject item=new JSONObject();
item.put("account",password.getUsername());
item.put("title",password.getTitle());
item.put("password",AESTools.decrypt(password.getPassword()));
array.add(item);
}
json.put("code",0);
json.put("data",array);
return json.toJSONString();
}
@ResponseBody
@RequestMapping(value = "type/get/list.do",method = RequestMethod.GET)
public String getPasswordType(HttpServletRequest request){
JSONObject json=new JSONObject();
int uid=tls.getUid(request);
ToolsPasswordTypeExample example=new ToolsPasswordTypeExample();
example.createCriteria().andUidEqualTo(uid);
List<ToolsPasswordType> toolsPasswordTypes=passwordTypeDao.selectByExample(example);
json.put("code",0);
json.put("msg","ok");
json.put("data", JSONArray.toJSON(toolsPasswordTypes));
@ -63,11 +97,13 @@ public class PasswordManager {
}
@ResponseBody
@RequestMapping(value = "type/set/add.do",method = RequestMethod.POST)
public String addPasswordType(String type){
public String addPasswordType(HttpServletRequest request,String type){
JSONObject json=new JSONObject();
try{
int uid=tls.getUid(request);
ToolsPasswordType passwordType=new ToolsPasswordType();
passwordType.setTitle(type);
passwordType.setUid(uid);
int code=passwordTypeDao.insert(passwordType);
json.put("code",0);
json.put("msg","修改结果:"+code);
@ -80,7 +116,7 @@ public class PasswordManager {
}
@ResponseBody
@RequestMapping(value = "set/add.do",method = RequestMethod.POST)
public String addPassword(String title,String username,String password,String url,String info,String type){
public String addPassword(HttpServletRequest request,String title,String username,String password,String url,String info,String type){
JSONObject json=new JSONObject();
try{
if(StringUtils.isEmpty(title)||StringUtils.isEmpty(username)||StringUtils.isEmpty(password)||StringUtils.isEmpty(type)){
@ -88,11 +124,13 @@ public class PasswordManager {
json.put("msg","有参数为空");
return json.toJSONString();
}
int uid=tls.getUid(request);
ToolsPassword toolsPassword=new ToolsPassword();
toolsPassword.setTitle(title);
toolsPassword.setUsername(username);
toolsPassword.setPassword(AESTools.encrypt(password));
toolsPassword.setType(Integer.parseInt(type));
toolsPassword.setUid(uid);
if(url!=null){
toolsPassword.setUrl(url);
}
@ -111,10 +149,14 @@ public class PasswordManager {
}
@ResponseBody
@RequestMapping(value = "set/update.do",method = RequestMethod.POST)
public String updatePassword(String title,String username,String password,String url,String info,String id){
public String updatePassword(HttpServletRequest request,String title,String username,String password,String url,String info,String id){
JSONObject json=new JSONObject();
try{
ToolsPassword toolsPassword=passwordDao.selectByPrimaryKey(Integer.parseInt(id));
int uid=tls.getUid(request);
ToolsPasswordExample example=new ToolsPasswordExample();
example.createCriteria().andIdEqualTo(Integer.parseInt(id)).andUidEqualTo(uid);
ToolsPassword toolsPassword=passwordDao.selectByExample(example).get(0);
if(!StringUtils.isEmpty(title)){
toolsPassword.setTitle(title);
}
@ -142,10 +184,13 @@ public class PasswordManager {
}
@ResponseBody
@RequestMapping(value = "type/set/update.do",method = RequestMethod.POST)
public String updatePasswordType(String type,String id){
public String updatePasswordType(HttpServletRequest request,String type,String id){
JSONObject json=new JSONObject();
try {
ToolsPasswordType passwordType=passwordTypeDao.selectByPrimaryKey(Integer.parseInt(id));
int uid=tls.getUid(request);
ToolsPasswordTypeExample example=new ToolsPasswordTypeExample();
example.createCriteria().andUidEqualTo(uid).andIdEqualTo(Integer.parseInt(id));
ToolsPasswordType passwordType=passwordTypeDao.selectByExample(example).get(0);
if(!StringUtils.isEmpty(type)){
passwordType.setTitle(type);
}
@ -161,10 +206,13 @@ public class PasswordManager {
}
@ResponseBody
@RequestMapping(value = "set/remove.do",method = RequestMethod.POST)
public String removePassword(String id){
public String removePassword(HttpServletRequest request,String id){
JSONObject json=new JSONObject();
try {
int code=passwordDao.deleteByPrimaryKey(Integer.parseInt(id));
int uid=tls.getUid(request);
ToolsPasswordExample example=new ToolsPasswordExample();
example.createCriteria().andUidEqualTo(uid).andIdEqualTo(Integer.parseInt(id));
int code=passwordDao.deleteByExample(example);
json.put("code",0);
json.put("msg","删除结果:"+code);
}catch (Exception e){
@ -176,11 +224,12 @@ public class PasswordManager {
}
@ResponseBody
@RequestMapping(value = "type/set/remove.do",method = RequestMethod.POST)
public String removePasswordType(String id){
public String removePasswordType(HttpServletRequest request,String id){
JSONObject json=new JSONObject();
try {
int uid=tls.getUid(request);
ToolsPasswordExample example=new ToolsPasswordExample();
example.createCriteria().andTypeEqualTo(Integer.parseInt(id));
example.createCriteria().andTypeEqualTo(Integer.parseInt(id)).andUidEqualTo(uid);
int passwordCode=passwordDao.deleteByExample(example);
System.out.println("删除结果:"+passwordCode);
int code=passwordTypeDao.deleteByPrimaryKey(Integer.parseInt(id));

View File

@ -23,5 +23,7 @@ public class ToolsPassword implements Serializable {
private Integer type;
private Integer uid;
private static final long serialVersionUID = 1L;
}

View File

@ -573,6 +573,66 @@ public class ToolsPasswordExample {
addCriterion("`type` not between", value1, value2, "type");
return (Criteria) this;
}
public Criteria andUidIsNull() {
addCriterion("`uid` is null");
return (Criteria) this;
}
public Criteria andUidIsNotNull() {
addCriterion("`uid` is not null");
return (Criteria) this;
}
public Criteria andUidEqualTo(Integer value) {
addCriterion("`uid` =", value, "uid");
return (Criteria) this;
}
public Criteria andUidNotEqualTo(Integer value) {
addCriterion("`uid` <>", value, "uid");
return (Criteria) this;
}
public Criteria andUidGreaterThan(Integer value) {
addCriterion("`uid` >", value, "uid");
return (Criteria) this;
}
public Criteria andUidGreaterThanOrEqualTo(Integer value) {
addCriterion("`uid` >=", value, "uid");
return (Criteria) this;
}
public Criteria andUidLessThan(Integer value) {
addCriterion("`uid` <", value, "uid");
return (Criteria) this;
}
public Criteria andUidLessThanOrEqualTo(Integer value) {
addCriterion("`uid` <=", value, "uid");
return (Criteria) this;
}
public Criteria andUidIn(List<Integer> values) {
addCriterion("`uid` in", values, "uid");
return (Criteria) this;
}
public Criteria andUidNotIn(List<Integer> values) {
addCriterion("`uid` not in", values, "uid");
return (Criteria) this;
}
public Criteria andUidBetween(Integer value1, Integer value2) {
addCriterion("`uid` between", value1, value2, "uid");
return (Criteria) this;
}
public Criteria andUidNotBetween(Integer value1, Integer value2) {
addCriterion("`uid` not between", value1, value2, "uid");
return (Criteria) this;
}
}
/**

View File

@ -11,6 +11,8 @@ import lombok.Data;
public class ToolsPasswordType implements Serializable {
private Integer id;
private Integer uid;
private String title;
private static final long serialVersionUID = 1L;

View File

@ -164,6 +164,66 @@ public class ToolsPasswordTypeExample {
return (Criteria) this;
}
public Criteria andUidIsNull() {
addCriterion("`uid` is null");
return (Criteria) this;
}
public Criteria andUidIsNotNull() {
addCriterion("`uid` is not null");
return (Criteria) this;
}
public Criteria andUidEqualTo(Integer value) {
addCriterion("`uid` =", value, "uid");
return (Criteria) this;
}
public Criteria andUidNotEqualTo(Integer value) {
addCriterion("`uid` <>", value, "uid");
return (Criteria) this;
}
public Criteria andUidGreaterThan(Integer value) {
addCriterion("`uid` >", value, "uid");
return (Criteria) this;
}
public Criteria andUidGreaterThanOrEqualTo(Integer value) {
addCriterion("`uid` >=", value, "uid");
return (Criteria) this;
}
public Criteria andUidLessThan(Integer value) {
addCriterion("`uid` <", value, "uid");
return (Criteria) this;
}
public Criteria andUidLessThanOrEqualTo(Integer value) {
addCriterion("`uid` <=", value, "uid");
return (Criteria) this;
}
public Criteria andUidIn(List<Integer> values) {
addCriterion("`uid` in", values, "uid");
return (Criteria) this;
}
public Criteria andUidNotIn(List<Integer> values) {
addCriterion("`uid` not in", values, "uid");
return (Criteria) this;
}
public Criteria andUidBetween(Integer value1, Integer value2) {
addCriterion("`uid` between", value1, value2, "uid");
return (Criteria) this;
}
public Criteria andUidNotBetween(Integer value1, Integer value2) {
addCriterion("`uid` not between", value1, value2, "uid");
return (Criteria) this;
}
public Criteria andTitleIsNull() {
addCriterion("title is null");
return (Criteria) this;

View File

@ -3,22 +3,31 @@ package com.yutou.tools.other;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yutou.tools.ToolsApplication;
import com.yutou.tools.mybatis.dao.UKeyDao;
import com.yutou.tools.mybatis.model.UKey;
import com.yutou.tools.mybatis.model.UKeyExample;
import com.yutou.tools.utils.QQBotManager;
import com.yutou.tools.utils.RedisTools;
import com.yutou.tools.utils.Tools;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.Enumeration;
import java.util.List;
@Controller
public class tools {
@Resource
UKeyDao keyDao;
@ResponseBody
@RequestMapping(value = "tools/get.do")
public String getJs(HttpServletRequest request, HttpServletResponse response) throws Exception {
@ -115,4 +124,22 @@ public class tools {
}
return RedisTools.get("request");
}
public int getUid(HttpServletRequest request) {
String token = request.getParameter("token");
Cookie cookie = Tools.getCookie(request, "user");
if (StringUtils.isEmpty(token) && cookie != null) {
if ("ok".equals(RedisTools.get(cookie.getValue()))) {
return 1;
}
}
UKeyExample example = new UKeyExample();
example.createCriteria().andKeyEqualTo(token);
List<UKey> list = keyDao.selectByExample(example);
if (list != null && !list.isEmpty()) {
UKey key = list.get(0);
return key.getId();
}
return -1;
}
}

View File

@ -9,6 +9,7 @@
<result column="url" jdbcType="VARCHAR" property="url" />
<result column="info" jdbcType="VARCHAR" property="info" />
<result column="type" jdbcType="INTEGER" property="type" />
<result column="uid" jdbcType="INTEGER" property="uid" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
@ -69,7 +70,7 @@
</where>
</sql>
<sql id="Base_Column_List">
id, title, username, `password`, url, info, `type`
id, title, username, `password`, url, info, `type`, `uid`
</sql>
<select id="selectByExample" parameterType="com.yutou.tools.mybatis.model.ToolsPasswordExample" resultMap="BaseResultMap">
select
@ -103,9 +104,11 @@
</delete>
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yutou.tools.mybatis.model.ToolsPassword" useGeneratedKeys="true">
insert into tools_password (title, username, `password`,
url, info, `type`)
url, info, `type`, `uid`
)
values (#{title,jdbcType=VARCHAR}, #{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR},
#{url,jdbcType=VARCHAR}, #{info,jdbcType=VARCHAR}, #{type,jdbcType=INTEGER})
#{url,jdbcType=VARCHAR}, #{info,jdbcType=VARCHAR}, #{type,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER}
)
</insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.yutou.tools.mybatis.model.ToolsPassword" useGeneratedKeys="true">
insert into tools_password
@ -128,6 +131,9 @@
<if test="type != null">
`type`,
</if>
<if test="uid != null">
`uid`,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="title != null">
@ -148,6 +154,9 @@
<if test="type != null">
#{type,jdbcType=INTEGER},
</if>
<if test="uid != null">
#{uid,jdbcType=INTEGER},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="com.yutou.tools.mybatis.model.ToolsPasswordExample" resultType="java.lang.Long">
@ -180,6 +189,9 @@
<if test="record.type != null">
`type` = #{record.type,jdbcType=INTEGER},
</if>
<if test="record.uid != null">
`uid` = #{record.uid,jdbcType=INTEGER},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
@ -193,7 +205,8 @@
`password` = #{record.password,jdbcType=VARCHAR},
url = #{record.url,jdbcType=VARCHAR},
info = #{record.info,jdbcType=VARCHAR},
`type` = #{record.type,jdbcType=INTEGER}
`type` = #{record.type,jdbcType=INTEGER},
`uid` = #{record.uid,jdbcType=INTEGER}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
@ -219,6 +232,9 @@
<if test="type != null">
`type` = #{type,jdbcType=INTEGER},
</if>
<if test="uid != null">
`uid` = #{uid,jdbcType=INTEGER},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
@ -229,7 +245,8 @@
`password` = #{password,jdbcType=VARCHAR},
url = #{url,jdbcType=VARCHAR},
info = #{info,jdbcType=VARCHAR},
`type` = #{type,jdbcType=INTEGER}
`type` = #{type,jdbcType=INTEGER},
`uid` = #{uid,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>

View File

@ -3,6 +3,7 @@
<mapper namespace="com.yutou.tools.mybatis.dao.ToolsPasswordTypeDao">
<resultMap id="BaseResultMap" type="com.yutou.tools.mybatis.model.ToolsPasswordType">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="uid" jdbcType="INTEGER" property="uid" />
<result column="title" jdbcType="VARCHAR" property="title" />
</resultMap>
<sql id="Example_Where_Clause">
@ -64,7 +65,7 @@
</where>
</sql>
<sql id="Base_Column_List">
id, title
id, `uid`, title
</sql>
<select id="selectByExample" parameterType="com.yutou.tools.mybatis.model.ToolsPasswordTypeExample" resultMap="BaseResultMap">
select
@ -97,17 +98,23 @@
</if>
</delete>
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yutou.tools.mybatis.model.ToolsPasswordType" useGeneratedKeys="true">
insert into tools_password_type (title)
values (#{title,jdbcType=VARCHAR})
insert into tools_password_type (`uid`, title)
values (#{uid,jdbcType=INTEGER}, #{title,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.yutou.tools.mybatis.model.ToolsPasswordType" useGeneratedKeys="true">
insert into tools_password_type
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="uid != null">
`uid`,
</if>
<if test="title != null">
title,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="uid != null">
#{uid,jdbcType=INTEGER},
</if>
<if test="title != null">
#{title,jdbcType=VARCHAR},
</if>
@ -125,6 +132,9 @@
<if test="record.id != null">
id = #{record.id,jdbcType=INTEGER},
</if>
<if test="record.uid != null">
`uid` = #{record.uid,jdbcType=INTEGER},
</if>
<if test="record.title != null">
title = #{record.title,jdbcType=VARCHAR},
</if>
@ -136,6 +146,7 @@
<update id="updateByExample" parameterType="map">
update tools_password_type
set id = #{record.id,jdbcType=INTEGER},
`uid` = #{record.uid,jdbcType=INTEGER},
title = #{record.title,jdbcType=VARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
@ -144,6 +155,9 @@
<update id="updateByPrimaryKeySelective" parameterType="com.yutou.tools.mybatis.model.ToolsPasswordType">
update tools_password_type
<set>
<if test="uid != null">
`uid` = #{uid,jdbcType=INTEGER},
</if>
<if test="title != null">
title = #{title,jdbcType=VARCHAR},
</if>
@ -152,7 +166,8 @@
</update>
<update id="updateByPrimaryKey" parameterType="com.yutou.tools.mybatis.model.ToolsPasswordType">
update tools_password_type
set title = #{title,jdbcType=VARCHAR}
set `uid` = #{uid,jdbcType=INTEGER},
title = #{title,jdbcType=VARCHAR}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>