Commit ac20a400 authored by 刘晓滨's avatar 刘晓滨

Merge branch 'master_zcc_adminfix' into 'master'

fix(xxl-job):登录用户名密码由数据库查询认证 See merge request !10
parents 150c9c7d de411ea1
...@@ -2,7 +2,9 @@ package com.xxl.job.admin.controller.interceptor; ...@@ -2,7 +2,9 @@ package com.xxl.job.admin.controller.interceptor;
import com.xxl.job.admin.controller.annotation.PermessionLimit; import com.xxl.job.admin.controller.annotation.PermessionLimit;
import com.xxl.job.admin.core.conf.XxlJobAdminConfig; import com.xxl.job.admin.core.conf.XxlJobAdminConfig;
import com.xxl.job.admin.core.model.XxlJobAdmin;
import com.xxl.job.admin.core.util.CookieUtil; import com.xxl.job.admin.core.util.CookieUtil;
import com.xxl.job.admin.dao.XxlJobAdminDao;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.DigestUtils; import org.springframework.util.DigestUtils;
import org.springframework.web.method.HandlerMethod; import org.springframework.web.method.HandlerMethod;
...@@ -23,22 +25,24 @@ public class PermissionInterceptor extends HandlerInterceptorAdapter { ...@@ -23,22 +25,24 @@ public class PermissionInterceptor extends HandlerInterceptorAdapter {
public static final String LOGIN_IDENTITY_KEY = "XXL_JOB_LOGIN_IDENTITY"; public static final String LOGIN_IDENTITY_KEY = "XXL_JOB_LOGIN_IDENTITY";
private static String LOGIN_IDENTITY_TOKEN; private static String LOGIN_IDENTITY_TOKEN;
public static String getLoginIdentityToken() { public static String getLoginIdentityToken() {
if (LOGIN_IDENTITY_TOKEN == null) { XxlJobAdminDao xxlJobAdminDao = XxlJobAdminConfig.getAdminConfig().getXxlJobAdminDao();
String username = XxlJobAdminConfig.getAdminConfig().getLoginUsername(); XxlJobAdmin admin = xxlJobAdminDao.findOne();
String password = XxlJobAdminConfig.getAdminConfig().getLoginPassword(); if (admin == null) {
return LOGIN_IDENTITY_TOKEN;
}
String username = admin.getUsername();
String password = admin.getPassword();
// login token // login token
String tokenTmp = DigestUtils.md5DigestAsHex(String.valueOf(username + "_" + password).getBytes()); //.getBytes("UTF-8") String tokenTmp = DigestUtils.md5DigestAsHex(String.valueOf(username + "_" + password).getBytes()); //.getBytes("UTF-8")
tokenTmp = new BigInteger(1, tokenTmp.getBytes()).toString(16); tokenTmp = new BigInteger(1, tokenTmp.getBytes()).toString(16);
LOGIN_IDENTITY_TOKEN = tokenTmp; return tokenTmp;
}
return LOGIN_IDENTITY_TOKEN;
} }
public static boolean login(HttpServletResponse response, String username, String password, boolean ifRemember){ public static boolean login(HttpServletResponse response, String username, String password, boolean ifRemember){
// login token // login token
String tokenTmp = DigestUtils.md5DigestAsHex(String.valueOf(username + "_" + password).getBytes()); String tokenTmp = DigestUtils.md5DigestAsHex(String.valueOf(username + "_" + password).getBytes());
tokenTmp = new BigInteger(1, tokenTmp.getBytes()).toString(16); tokenTmp = new BigInteger(1, tokenTmp.getBytes()).toString(16);
......
package com.xxl.job.admin.core.conf; package com.xxl.job.admin.core.conf;
import com.xxl.job.admin.dao.XxlJobGroupDao; import com.xxl.job.admin.dao.*;
import com.xxl.job.admin.dao.XxlJobInfoDao;
import com.xxl.job.admin.dao.XxlJobLogDao;
import com.xxl.job.admin.dao.XxlJobRegistryDao;
import com.xxl.job.core.biz.AdminBiz; import com.xxl.job.core.biz.AdminBiz;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
...@@ -48,12 +45,6 @@ public class XxlJobAdminConfig implements InitializingBean{ ...@@ -48,12 +45,6 @@ public class XxlJobAdminConfig implements InitializingBean{
@Value("${xxl.job.mail.sendNick}") @Value("${xxl.job.mail.sendNick}")
private String mailSendNick; private String mailSendNick;
@Value("${xxl.job.login.username}")
private String loginUsername;
@Value("${xxl.job.login.password}")
private String loginPassword;
@Value("${xxl.job.i18n}") @Value("${xxl.job.i18n}")
private String i18n; private String i18n;
...@@ -72,7 +63,12 @@ public class XxlJobAdminConfig implements InitializingBean{ ...@@ -72,7 +63,12 @@ public class XxlJobAdminConfig implements InitializingBean{
public XxlJobGroupDao xxlJobGroupDao; public XxlJobGroupDao xxlJobGroupDao;
@Resource @Resource
public AdminBiz adminBiz; public AdminBiz adminBiz;
@Resource
public XxlJobAdminDao xxlJobAdminDao;
public XxlJobAdminDao getXxlJobAdminDao() {
return xxlJobAdminDao;
}
public String getMailHost() { public String getMailHost() {
return mailHost; return mailHost;
...@@ -98,14 +94,6 @@ public class XxlJobAdminConfig implements InitializingBean{ ...@@ -98,14 +94,6 @@ public class XxlJobAdminConfig implements InitializingBean{
return mailSendNick; return mailSendNick;
} }
public String getLoginUsername() {
return loginUsername;
}
public String getLoginPassword() {
return loginPassword;
}
public String getI18n() { public String getI18n() {
return i18n; return i18n;
} }
......
package com.xxl.job.admin.core.model;
/**
* Created by xuxueli on 16/9/30.
*/
public class XxlJobAdmin {
private int id;
private String username;
private String password;
public XxlJobAdmin() {
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
package com.xxl.job.admin.dao;
import com.xxl.job.admin.core.model.XxlJobAdmin;
import org.apache.ibatis.annotations.Mapper;
/**
* Created by xuxueli on 16/9/30.
*/
@Mapper
public interface XxlJobAdminDao {
public XxlJobAdmin findOne();
}
...@@ -36,8 +36,8 @@ xxl.job.mail.password=Chyezaq1234 ...@@ -36,8 +36,8 @@ xxl.job.mail.password=Chyezaq1234
xxl.job.mail.sendNick=XXL-JOB xxl.job.mail.sendNick=XXL-JOB
### xxl-job login ### xxl-job login
xxl.job.login.username=admin #xxl.job.login.username=admin
xxl.job.login.password=123456 #xxl.job.login.password=123456
### xxl-job, access token ### xxl-job, access token
xxl.job.accessToken= xxl.job.accessToken=
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xxl.job.admin.dao.XxlJobAdminDao">
<resultMap id="XxlJobAdmin" type="com.xxl.job.admin.core.model.XxlJobAdmin" >
<result column="id" property="id" />
<result column="username" property="username" />
<result column="password" property="password" />
</resultMap>
<sql id="Base_Column_List">
t.id,
t.username,
t.password
</sql>
<select id="findOne" resultMap="XxlJobAdmin">
SELECT <include refid="Base_Column_List" />
FROM XXL_JOB_QRTZ_ADMIN AS t
ORDER BY t.id ASC LIMIT 1
</select>
</mapper>
\ No newline at end of file
...@@ -2,6 +2,8 @@ package com.xxl.job.admin.controller; ...@@ -2,6 +2,8 @@ package com.xxl.job.admin.controller;
import com.xxl.job.admin.controller.interceptor.PermissionInterceptor; import com.xxl.job.admin.controller.interceptor.PermissionInterceptor;
import com.xxl.job.admin.core.conf.XxlJobAdminConfig; import com.xxl.job.admin.core.conf.XxlJobAdminConfig;
import com.xxl.job.admin.core.model.XxlJobAdmin;
import com.xxl.job.admin.dao.XxlJobAdminDao;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
...@@ -19,11 +21,13 @@ public class JobInfoControllerTest extends AbstractSpringMvcTest { ...@@ -19,11 +21,13 @@ public class JobInfoControllerTest extends AbstractSpringMvcTest {
@Before @Before
public void login() throws Exception { public void login() throws Exception {
XxlJobAdminDao xxlJobAdminDao = XxlJobAdminConfig.getAdminConfig().getXxlJobAdminDao();
XxlJobAdmin admin = xxlJobAdminDao.findOne();
MvcResult ret = mockMvc.perform( MvcResult ret = mockMvc.perform(
post("/login") post("/login")
.contentType(MediaType.APPLICATION_FORM_URLENCODED) .contentType(MediaType.APPLICATION_FORM_URLENCODED)
.param("userName", XxlJobAdminConfig.getAdminConfig().getLoginUsername()) .param("userName", admin.getUsername())
.param("password", XxlJobAdminConfig.getAdminConfig().getLoginPassword()) .param("password", admin.getPassword())
).andReturn(); ).andReturn();
cookie = ret.getResponse().getCookie(PermissionInterceptor.LOGIN_IDENTITY_KEY); cookie = ret.getResponse().getCookie(PermissionInterceptor.LOGIN_IDENTITY_KEY);
} }
......
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