REM:
1. 更新认证配置项
2. 配置为不需要认证时,登录、注销接口报错
3. 增加处置任务管理功能
This commit is contained in:
HuangXin 2020-08-13 17:27:21 +08:00
parent c6d3b3f0fe
commit 6e345aee01
11 changed files with 289 additions and 19 deletions

View File

@ -1,7 +1,6 @@
#调试配置 #调试配置
dispose.debug-model=true dispose.debug-model=true
dispose.check-protocol-timeout=false dispose.check-protocol-timeout=false
dispose.check-request-token=true
dispose.split_char=, dispose.split_char=,
dispose.request-timeout-second=5 dispose.request-timeout-second=5
@ -18,4 +17,5 @@ permission.admin-check=true
permission.admin-users=admin permission.admin-users=admin
# 认证配置 # 认证配置
auth.verify-request-token=true
auth.token-timeout-minute=30 auth.token-timeout-minute=30

View File

@ -1,11 +1,16 @@
package com.dispose.common; package com.dispose.common;
/** /**
* The type Global configure. * The type Auth config value.
* *
* @author <huangxin@cmhi.chinamoblie.com> * @author <huangxin@cmhi.chinamoblie.com>
*/ */
public class AuthConfigValue { public class AuthConfigValue {
/**
* The constant VERIFY_REQUEST_TOKEN.
*/
public static volatile boolean VERIFY_REQUEST_TOKEN = true;
/** /**
* The constant ALLOW_PWD_ERR_TIMES. * The constant ALLOW_PWD_ERR_TIMES.
*/ */

View File

@ -16,7 +16,12 @@ import org.springframework.stereotype.Component;
@ConfigurationProperties(prefix = "auth") @ConfigurationProperties(prefix = "auth")
public class AuthConfigure { public class AuthConfigure {
/** /**
* The Token timout value. * The Token timeout minute.
*/ */
private String tokenTimeoutMinute; private String tokenTimeoutMinute;
/**
* The Verify request token.
*/
private String verifyRequestToken;
} }

View File

@ -19,10 +19,7 @@ public class DisposeConfigure {
* The Check protocol timeout. * The Check protocol timeout.
*/ */
private String checkProtocolTimeout; private String checkProtocolTimeout;
/**
* The Check request token.
*/
private String checkRequestToken;
/** /**
* The Split char. * The Split char.
*/ */

View File

@ -1,5 +1,6 @@
package com.dispose.interceptor; package com.dispose.interceptor;
import com.dispose.common.AuthConfigValue;
import com.dispose.common.ConstValue; import com.dispose.common.ConstValue;
import com.dispose.common.ErrorCode; import com.dispose.common.ErrorCode;
import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO; import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO;
@ -20,6 +21,9 @@ import javax.servlet.http.HttpServletResponse;
*/ */
@Slf4j @Slf4j
public class TokenInterceptor implements HandlerInterceptor { public class TokenInterceptor implements HandlerInterceptor {
/**
* The User account service.
*/
@Resource @Resource
private UserAccountService userAccountService; private UserAccountService userAccountService;
@ -33,9 +37,13 @@ public class TokenInterceptor implements HandlerInterceptor {
* @throws Exception the exception * @throws Exception the exception
*/ */
@Override @Override
public boolean preHandle(HttpServletRequest request, public boolean preHandle(@NonNull HttpServletRequest request,
@NonNull HttpServletResponse response, @NonNull HttpServletResponse response,
@NonNull Object handler) throws Exception { @NonNull Object handler) throws Exception {
// 配置为不需要认证
if (!AuthConfigValue.VERIFY_REQUEST_TOKEN) {
return true;
}
// 提取header中的Authorization字段里面的token值 // 提取header中的Authorization字段里面的token值
String token = request.getHeader("Authorization"); String token = request.getHeader("Authorization");

View File

@ -0,0 +1,97 @@
package com.dispose.manager;
import com.dispose.common.DisposeTaskStatus;
import com.dispose.common.ErrorCode;
import com.dispose.pojo.entity.DisposeTask;
import com.dispose.pojo.entity.TaskInfo;
import com.dispose.pojo.po.MulReturnType;
import java.util.List;
/**
* The interface Dispose task manager.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
public interface DisposeTaskManager {
/**
* Gets unfinished task.
*
* @return the unfinished task
*/
List<TaskInfo> getUnfinishedTask();
/**
* Create new task mul return type.
*
* @param task the task
* @return the mul return type
*/
MulReturnType<ErrorCode, Long> createNewTask(DisposeTask task);
/**
* Add task info mul return type.
*
* @param taskId the task id
* @param taskInfo the task info
* @return the mul return type
*/
MulReturnType<ErrorCode, Long> addTaskInfo(Long taskId, TaskInfo taskInfo);
/**
* Sets dispose task status.
*
* @param taskId the task id
* @param status the status
* @return the dispose task status
*/
ErrorCode setDisposeTaskStatus(Long taskId, DisposeTaskStatus status);
/**
* Gets task attack type mask.
*
* @param taskId the task id
* @return the task attack type mask
*/
Long getTaskAttackTypeMask(Long taskId);
/**
* Gets cur attack type mask.
*
* @param taskId the task id
* @return the cur attack type mask
*/
Long getCurAttackTypeMask(Long taskId);
/**
* Gets attack type mask status.
*
* @param taskId the task id
* @return the attack type mask status
*/
Long getAttackTypeMaskStatus(Long taskId);
/**
* Sets task attack type mask.
*
* @param taskId the task id
* @param mask the mask
*/
void setTaskAttackTypeMask(Long taskId, Long mask);
/**
* Sets cur attack type mask.
*
* @param taskId the task id
* @param mask the mask
*/
void setCurAttackTypeMask(Long taskId, Long mask);
/**
* Sets attack type mask status.
*
* @param taskId the task id
* @param mask the mask
*/
void setAttackTypeMaskStatus(Long taskId, Long mask);
}

View File

@ -11,7 +11,6 @@ import java.security.NoSuchAlgorithmException;
* @author <huangxin@cmhi.chinamoblie.com> * @author <huangxin@cmhi.chinamoblie.com>
*/ */
public interface UserAccountManager { public interface UserAccountManager {
/** /**
* Gets user by name. * Gets user by name.
* *

View File

@ -0,0 +1,143 @@
package com.dispose.manager.impl;
import com.dispose.common.DisposeTaskStatus;
import com.dispose.common.ErrorCode;
import com.dispose.manager.DisposeTaskManager;
import com.dispose.mapper.DisposeTaskMapper;
import com.dispose.mapper.TaskInfoMapper;
import com.dispose.pojo.entity.DisposeTask;
import com.dispose.pojo.entity.TaskInfo;
import com.dispose.pojo.po.MulReturnType;
import javax.annotation.Resource;
import java.util.List;
/**
* The type Dispose task manager.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
public class DisposeTaskManagerImpl implements DisposeTaskManager {
/**
* The Dispose task mapper.
*/
@Resource
private DisposeTaskMapper disposeTaskMapper;
/**
* The Task info mapper.
*/
@Resource
private TaskInfoMapper taskInfoMapper;
/**
* Create new task mul return type.
*
* @param task the task
* @return the mul return type
*/
@Override
public MulReturnType<ErrorCode, Long> createNewTask(DisposeTask task) {
return null;
}
/**
* Add task info mul return type.
*
* @param taskId the task id
* @param taskInfo the task info
* @return the mul return type
*/
@Override
public MulReturnType<ErrorCode, Long> addTaskInfo(Long taskId, TaskInfo taskInfo) {
return null;
}
/**
* Gets unfinished task.
*
* @return the unfinished task
*/
@Override
public List<TaskInfo> getUnfinishedTask() {
return null;
}
/**
* Gets task attack type mask.
*
* @param taskId the task id
* @return the task attack type mask
*/
@Override
public Long getTaskAttackTypeMask(Long taskId) {
return null;
}
/**
* Gets attack type mask status.
*
* @param taskId the task id
* @return the attack type mask status
*/
@Override
public Long getAttackTypeMaskStatus(Long taskId) {
return null;
}
/**
* Gets cur attack type mask.
*
* @param taskId the task id
* @return the cur attack type mask
*/
@Override
public Long getCurAttackTypeMask(Long taskId) {
return null;
}
/**
* Sets task attack type mask.
*
* @param taskId the task id
* @param mask the mask
*/
@Override
public void setTaskAttackTypeMask(Long taskId, Long mask) {
}
/**
* Sets cur attack type mask.
*
* @param taskId the task id
* @param mask the mask
*/
@Override
public void setCurAttackTypeMask(Long taskId, Long mask) {
}
/**
* Sets attack type mask status.
*
* @param taskId the task id
* @param mask the mask
*/
@Override
public void setAttackTypeMaskStatus(Long taskId, Long mask) {
}
/**
* Sets dispose task status.
*
* @param taskId the task id
* @param status the status
* @return the dispose task status
*/
@Override
public ErrorCode setDisposeTaskStatus(Long taskId, DisposeTaskStatus status) {
return null;
}
}

View File

@ -3,7 +3,6 @@ package com.dispose.service.impl;
import com.dispose.common.AuthConfigValue; import com.dispose.common.AuthConfigValue;
import com.dispose.common.ErrorCode; import com.dispose.common.ErrorCode;
import com.dispose.common.ObjectStatus; import com.dispose.common.ObjectStatus;
import com.dispose.config.DisposeConfigure;
import com.dispose.manager.UserAccountManager; import com.dispose.manager.UserAccountManager;
import com.dispose.pojo.entity.UserAccount; import com.dispose.pojo.entity.UserAccount;
import com.dispose.pojo.po.MulReturnType; import com.dispose.pojo.po.MulReturnType;
@ -29,12 +28,6 @@ public class UserAccountServiceImpl implements UserAccountService {
@Resource @Resource
private UserAccountManager userAccountManager; private UserAccountManager userAccountManager;
/**
* The Dispose configure.
*/
@Resource
private DisposeConfigure disposeConfigure;
/** /**
* Auth token check error code. * Auth token check error code.
* *
@ -44,7 +37,7 @@ public class UserAccountServiceImpl implements UserAccountService {
@Override @Override
public ErrorCode authTokenCheck(String token) { public ErrorCode authTokenCheck(String token) {
// 判断当前配置是否需要校验 token // 判断当前配置是否需要校验 token
if (String.valueOf(false).equals(disposeConfigure.getCheckRequestToken())) { if (!AuthConfigValue.VERIFY_REQUEST_TOKEN) {
return ErrorCode.ERR_OK; return ErrorCode.ERR_OK;
} }
@ -61,6 +54,12 @@ public class UserAccountServiceImpl implements UserAccountService {
*/ */
@Override @Override
public MulReturnType<ErrorCode, String> loginService(String username, String password) throws NoSuchAlgorithmException { public MulReturnType<ErrorCode, String> loginService(String username, String password) throws NoSuchAlgorithmException {
// 配置文件配置为不检测认证则不需要登录
if(!AuthConfigValue.VERIFY_REQUEST_TOKEN) {
return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, "");
}
userAccountManager.upgradeLoginTime(username); userAccountManager.upgradeLoginTime(username);
UserAccount loginUser = userAccountManager.getUserByName(username); UserAccount loginUser = userAccountManager.getUserByName(username);
@ -114,6 +113,11 @@ public class UserAccountServiceImpl implements UserAccountService {
*/ */
@Override @Override
public ErrorCode logoutService(String username, String token) { public ErrorCode logoutService(String username, String token) {
// 配置文件配置为不检测认证则不需要登录
if(!AuthConfigValue.VERIFY_REQUEST_TOKEN) {
return ErrorCode.ERR_UNSUPPORT;
}
UserAccount loginUser = userAccountManager.getUserByName(username); UserAccount loginUser = userAccountManager.getUserByName(username);
if (loginUser == null) { if (loginUser == null) {
@ -137,6 +141,11 @@ public class UserAccountServiceImpl implements UserAccountService {
*/ */
@Override @Override
public UserAccount getUserByToken(String token) { public UserAccount getUserByToken(String token) {
// 无需认证
if (!AuthConfigValue.VERIFY_REQUEST_TOKEN) {
return null;
}
return userAccountManager.getUserByToken(token); return userAccountManager.getUserByToken(token);
} }

View File

@ -60,6 +60,12 @@ public class SystemInitial implements CommandLineRunner {
log.error("load TOKEN_EXPIRED_TIME_MS configure error: {}", ex.getMessage()); log.error("load TOKEN_EXPIRED_TIME_MS configure error: {}", ex.getMessage());
} }
try {
AuthConfigValue.VERIFY_REQUEST_TOKEN = Boolean.parseBoolean(authConfigure.getVerifyRequestToken());
} catch (Exception ex) {
log.error("load VERIFY_REQUEST_TOKEN configure error: {}", ex.getMessage());
}
try { try {
DpTechConfigValue.SOAP_CONNECT_TIMEOUT_SECOND = DpTechConfigValue.SOAP_CONNECT_TIMEOUT_SECOND =
Integer.parseInt(dpTechConfigure.getSoapConnTimeoutSecond()); Integer.parseInt(dpTechConfigure.getSoapConnTimeoutSecond());

View File

@ -1,5 +1,6 @@
package com.dispose.test.service; package com.dispose.test.service;
import com.dispose.common.AuthConfigValue;
import com.dispose.common.ErrorCode; import com.dispose.common.ErrorCode;
import com.dispose.config.DisposeConfigure; import com.dispose.config.DisposeConfigure;
import com.dispose.pojo.entity.UserAccount; import com.dispose.pojo.entity.UserAccount;
@ -115,7 +116,7 @@ public class UserAccountServiceTest extends InitTestEnvironment {
public void a4_authTokenCheckTest() { public void a4_authTokenCheckTest() {
Assert.assertEquals(userAccountService.authTokenCheck(token), ErrorCode.ERR_OK); Assert.assertEquals(userAccountService.authTokenCheck(token), ErrorCode.ERR_OK);
if (String.valueOf(true).equals(disposeConfigure.getCheckRequestToken())) { if (AuthConfigValue.VERIFY_REQUEST_TOKEN) {
Assert.assertEquals(userAccountService.authTokenCheck(token + "1235"), ErrorCode.ERR_LOGOUT); Assert.assertEquals(userAccountService.authTokenCheck(token + "1235"), ErrorCode.ERR_LOGOUT);
} }
} }