自动登录

This commit is contained in:
haozq 2025-12-05 15:40:36 +08:00
parent 5d2339bbed
commit bb56629b6a
31 changed files with 719 additions and 33 deletions

View File

@ -7,7 +7,6 @@
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="bonus-common-log" />
<module name="HnRealNameMw" />
<module name="ldlz-common" />
<module name="bonus-common-datascope" />
<module name="bonus-common-sensitive" />
@ -23,6 +22,7 @@
<module name="ldlz-admin" />
<module name="bonus-common-datasource" />
<module name="ldlz-system" />
<module name="HnRealNameMmw" />
<module name="bonus-common-config" />
<module name="ldlz-generator" />
<module name="hn-czl-service" />
@ -32,7 +32,7 @@
<component name="JavacSettings">
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
<module name="HnRealNameBmw" options="-parameters" />
<module name="HnRealNameMw" options="-parameters" />
<module name="HnRealNameMmw" options="-parameters" />
<module name="hn-czl-service" options="-parameters" />
<module name="hn_czl_screen" options="-parameters" />
</option>

View File

@ -6,11 +6,6 @@
<option name="name" value="aliyun nexus" />
<option name="url" value="https://maven.aliyun.com/repository/public" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />

View File

@ -13,7 +13,7 @@
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="ms-21" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View File

@ -1,4 +1,239 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PropertiesComponent">{}</component>
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="30706c6d-35cd-44ba-b6ec-9865ccea7a75" name="Changes" comment="修改新增用户">
<change afterPath="$PROJECT_DIR$/HnRealNameBmw/src/main/java/com/bonus/hnrn/rnbmw/login/controller/PublicLoginController.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/HnRealNameBmw/src/main/java/com/bonus/hnrn/rnbmw/login/service/PublicLoginService.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/HnRealNameBmw/src/main/java/com/bonus/hnrn/rnbmw/login/vo/LoginForm.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/hn-czl-service/src/main/java/com/bonus/hn/bearing/capacity/backstage/login/controller/PublicLoginController.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/hn-czl-service/src/main/java/com/bonus/hn/bearing/capacity/backstage/login/service/PublicLoginService.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/hn-czl-service/src/main/java/com/bonus/hn/bearing/capacity/backstage/login/vo/LoginForm.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/hn_czl_screen/src/main/java/com/bonus/hn/bearing/capacity/screen/login/controller/PublicLoginController.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/hn_czl_screen/src/main/java/com/bonus/hn/bearing/capacity/screen/login/service/PublicLoginService.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/hn_czl_screen/src/main/java/com/bonus/hn/bearing/capacity/screen/login/vo/LoginForm.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/compiler.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/compiler.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/jarRepositories.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/jarRepositories.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/HnRealNameBmw/src/main/java/com/bonus/hnrn/rnbmw/manager/config/BnsSecurityConfig.java" beforeDir="false" afterPath="$PROJECT_DIR$/HnRealNameBmw/src/main/java/com/bonus/hnrn/rnbmw/manager/config/BnsSecurityConfig.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/HnRealNameBmw/src/main/java/com/bonus/hnrn/rnbmw/manager/entity/Token.java" beforeDir="false" afterPath="$PROJECT_DIR$/HnRealNameBmw/src/main/java/com/bonus/hnrn/rnbmw/manager/entity/Token.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/HnRealNameBmw/src/main/resources/bootstrap.yml" beforeDir="false" afterPath="$PROJECT_DIR$/HnRealNameBmw/src/main/resources/bootstrap.yml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/HnRealNameMw/src/main/java/com/bonus/hnrn/rnmw/core/controller/PublicLoginController.java" beforeDir="false" afterPath="$PROJECT_DIR$/HnRealNameMw/src/main/java/com/bonus/hnrn/rnmw/core/controller/PublicLoginController.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/HnRealNameMw/src/main/java/com/bonus/hnrn/rnmw/core/controller/PublicLoginService.java" beforeDir="false" afterPath="$PROJECT_DIR$/HnRealNameMw/src/main/java/com/bonus/hnrn/rnmw/core/service/PublicLoginService.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/HnRealNameMw/src/main/resources/bootstrap.yml" beforeDir="false" afterPath="$PROJECT_DIR$/HnRealNameMw/src/main/resources/bootstrap.yml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/hn-czl-service/src/main/java/com/bonus/hn/bearing/capacity/backstage/manager/config/BnsSecurityConfig.java" beforeDir="false" afterPath="$PROJECT_DIR$/hn-czl-service/src/main/java/com/bonus/hn/bearing/capacity/backstage/manager/config/BnsSecurityConfig.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/hn-czl-service/src/main/java/com/bonus/hn/bearing/capacity/backstage/manager/entity/Token.java" beforeDir="false" afterPath="$PROJECT_DIR$/hn-czl-service/src/main/java/com/bonus/hn/bearing/capacity/backstage/manager/entity/Token.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/hn-czl-service/src/main/resources/bootstrap.yml" beforeDir="false" afterPath="$PROJECT_DIR$/hn-czl-service/src/main/resources/bootstrap.yml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/hn-gateway/bonus-gateway/src/main/java/com/bonus/gateway/filter/AuthFilter.java" beforeDir="false" afterPath="$PROJECT_DIR$/hn-gateway/bonus-gateway/src/main/java/com/bonus/gateway/filter/AuthFilter.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/hn-gateway/bonus-gateway/src/main/resources/bootstrap-dev.yml" beforeDir="false" afterPath="$PROJECT_DIR$/hn-gateway/bonus-gateway/src/main/resources/bootstrap-dev.yml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/hn-ldlz/ldlz-admin/src/main/resources/bootstrap-druid.yml" beforeDir="false" afterPath="$PROJECT_DIR$/hn-ldlz/ldlz-admin/src/main/resources/bootstrap-druid.yml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/hn-ldlz/ldlz-admin/src/main/resources/bootstrap-prod.yml" beforeDir="false" afterPath="$PROJECT_DIR$/hn-ldlz/ldlz-admin/src/main/resources/bootstrap-prod.yml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/hn_czl_screen/src/main/java/com/bonus/hn/bearing/capacity/screen/manager/config/BnsSecurityConfig.java" beforeDir="false" afterPath="$PROJECT_DIR$/hn_czl_screen/src/main/java/com/bonus/hn/bearing/capacity/screen/manager/config/BnsSecurityConfig.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/hn_czl_screen/src/main/java/com/bonus/hn/bearing/capacity/screen/manager/config/SecurityHandlerConfig.java" beforeDir="false" afterPath="$PROJECT_DIR$/hn_czl_screen/src/main/java/com/bonus/hn/bearing/capacity/screen/manager/config/SecurityHandlerConfig.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/hn_czl_screen/src/main/java/com/bonus/hn/bearing/capacity/screen/manager/entity/Token.java" beforeDir="false" afterPath="$PROJECT_DIR$/hn_czl_screen/src/main/java/com/bonus/hn/bearing/capacity/screen/manager/entity/Token.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/hn_czl_screen/src/main/java/com/bonus/hn/bearing/capacity/screen/manager/filter/VerifyFilter.java" beforeDir="false" afterPath="$PROJECT_DIR$/hn_czl_screen/src/main/java/com/bonus/hn/bearing/capacity/screen/manager/filter/VerifyFilter.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/hn_czl_screen/src/main/resources/bootstrap.yml" beforeDir="false" afterPath="$PROJECT_DIR$/hn_czl_screen/src/main/resources/bootstrap.yml" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="MavenImportPreferences">
<option name="generalSettings">
<MavenGeneralSettings>
<option name="localRepository" value="D:\maven\resp" />
<option name="userSettingsFile" value="D:\maven\apache-maven-3.6.1\conf\settings.xml" />
</MavenGeneralSettings>
</option>
</component>
<component name="ProjectColorInfo"><![CDATA[{
"customColor": "",
"associatedIndex": 4
}]]></component>
<component name="ProjectId" id="36PFiwo4lL3PK4Bc96Z4FeLdqDB" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"RequestMappingsPanelOrder0": "0",
"RequestMappingsPanelOrder1": "1",
"RequestMappingsPanelWidth0": "75",
"RequestMappingsPanelWidth1": "75",
"RunOnceActivity.ShowReadmeOnStart": "true",
"RunOnceActivity.git.unshallow": "true",
"SONARLINT_PRECOMMIT_ANALYSIS": "true",
"Spring Boot.BonusGatewayApplication.executor": "Debug",
"Spring Boot.CzlScreenApplication.executor": "Debug",
"Spring Boot.CzlServiceApplication.executor": "Debug",
"Spring Boot.HnRealNameBmwApplication.executor": "Run",
"Spring Boot.LdlzApplication.executor": "Run",
"Spring Boot.RnmwApplication.executor": "Debug",
"git-widget-placeholder": "main",
"kotlin-language-version-configured": "true",
"last_opened_file_path": "F:/workspace/idea/hn_cloud_service/HnRealNameMw/src/main/java/com/bonus/hnrn/rnmw/login",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"nodejs_package_manager_path": "npm",
"project.structure.last.edited": "Project",
"project.structure.proportion": "0.0",
"project.structure.side.proportion": "0.43843496",
"run.configurations.included.in.services": "true",
"settings.editor.selected.configurable": "MavenSettings",
"vue.rearranger.settings.migration": "true"
}
}]]></component>
<component name="ReactorSettings">
<option name="notificationShown" value="true" />
</component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="F:\workspace\idea\hn_cloud_service\HnRealNameMw\src\main\java\com\bonus\hnrn\rnmw\login" />
<recent name="F:\workspace\idea\hn_cloud_service\hn_czl_screen\src\main\java\com\bonus\hn\bearing\capacity\screen\login" />
</key>
<key name="CopyClassDialog.RECENTS_KEY">
<recent name="com.bonus.hnrn.rnbmw.login.vo" />
<recent name="com.bonus.hnrn.rnbmw.login.service" />
<recent name="com.bonus.hnrn.rnbmw.login.controller" />
<recent name="com.bonus.hn.bearing.capacity.backstage.login.service" />
<recent name="com.bonus.hn.bearing.capacity.backstage.login.vo" />
</key>
</component>
<component name="RunDashboard">
<option name="configurationTypes">
<set>
<option value="KtorApplicationConfigurationType" />
<option value="MicronautRunConfigurationType" />
<option value="QuarkusRunConfigurationType" />
<option value="SpringBootApplicationConfigurationType" />
</set>
</option>
</component>
<component name="RunManager" selected="Spring Boot.CzlScreenApplication">
<configuration name="BonusGatewayApplication" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot" nameIsGenerated="true">
<module name="bonus-gateway" />
<option name="SPRING_BOOT_MAIN_CLASS" value="com.bonus.gateway.BonusGatewayApplication" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="CzlScreenApplication" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot" nameIsGenerated="true">
<option name="FRAME_DEACTIVATION_UPDATE_POLICY" value="UpdateClassesAndResources" />
<module name="hn_czl_screen" />
<option name="SPRING_BOOT_MAIN_CLASS" value="com.bonus.hn.bearing.capacity.screen.CzlScreenApplication" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="CzlServiceApplication" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot" nameIsGenerated="true">
<option name="FRAME_DEACTIVATION_UPDATE_POLICY" value="UpdateClassesAndResources" />
<module name="hn-czl-service" />
<option name="SPRING_BOOT_MAIN_CLASS" value="com.bonus.hn.bearing.capacity.backstage.CzlServiceApplication" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="HnRealNameBmwApplication" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot" nameIsGenerated="true">
<option name="FRAME_DEACTIVATION_UPDATE_POLICY" value="UpdateClassesAndResources" />
<module name="HnRealNameBmw" />
<option name="SPRING_BOOT_MAIN_CLASS" value="com.bonus.hnrn.rnbmw.HnRealNameBmwApplication" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="LdlzApplication" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot" nameIsGenerated="true">
<option name="FRAME_DEACTIVATION_UPDATE_POLICY" value="UpdateClassesAndResources" />
<module name="ldlz-admin" />
<option name="SPRING_BOOT_MAIN_CLASS" value="com.bns.LdlzApplication" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="RnmwApplication" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot" nameIsGenerated="true">
<option name="FRAME_DEACTIVATION_UPDATE_POLICY" value="UpdateClassesAndResources" />
<module name="HnRealNameMmw" />
<option name="SPRING_BOOT_MAIN_CLASS" value="com.bonus.hnrn.rnmw.RnmwApplication" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>
<component name="SharedIndexes">
<attachedChunks>
<set>
<option value="bundled-jdk-9823dce3aa75-a94e463ab2e7-intellij.indexing.shared.core-IU-243.26574.91" />
<option value="bundled-js-predefined-d6986cc7102b-1632447f56bf-JavaScript-IU-243.26574.91" />
</set>
</attachedChunks>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="30706c6d-35cd-44ba-b6ec-9865ccea7a75" name="Changes" comment="" />
<created>1764900432287</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1764900432287</updated>
<workItem from="1764900434133" duration="10291000" />
</task>
<task id="LOCAL-00001" summary="修改新增用户">
<option name="closed" value="true" />
<created>1764900500635</created>
<option name="number" value="00001" />
<option name="presentableId" value="LOCAL-00001" />
<option name="project" value="LOCAL" />
<updated>1764900500635</updated>
</task>
<option name="localTasksCounter" value="2" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
<component name="Vcs.Log.Tabs.Properties">
<option name="TAB_STATES">
<map>
<entry key="MAIN">
<value>
<State />
</value>
</entry>
</map>
</option>
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="修改新增用户" />
<option name="LAST_COMMIT_MESSAGE" value="修改新增用户" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/hn-czl-service/src/main/java/com/bonus/hn/bearing/capacity/backstage/manager/controller/UserController.java</url>
<line>58</line>
<option name="timeStamp" value="4" />
</line-breakpoint>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/hn-czl-service/src/main/java/com/bonus/hn/bearing/capacity/backstage/manager/service/impl/UserServiceImpl.java</url>
<line>93</line>
<option name="timeStamp" value="5" />
</line-breakpoint>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/hn-czl-service/src/main/java/com/bonus/hn/bearing/capacity/backstage/manager/service/impl/UserServiceImpl.java</url>
<line>126</line>
<option name="timeStamp" value="6" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
</component>
</project>

View File

@ -0,0 +1,38 @@
package com.bonus.hnrn.rnbmw.login.controller;
import com.bonus.hnrn.rnbmw.login.service.PublicLoginService;
import com.bonus.hnrn.rnbmw.login.vo.LoginForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
/**
* 默认公共登录方法
*/
@RestController
@RequestMapping(value = "/publicLogin")
public class PublicLoginController {
@Autowired
private PublicLoginService loginService;
/**
* 系统登录
* @param token
* @param response
*/
@PostMapping("defaultLogin")
public void login(@RequestBody LoginForm token, HttpServletResponse response) {
loginService.login(token,response);
}
}

View File

@ -0,0 +1,71 @@
package com.bonus.hnrn.rnbmw.login.service;
import com.bonus.hnrn.rnbmw.login.vo.LoginForm;
import com.bonus.hnrn.rnbmw.manager.dao.PermissionDao;
import com.bonus.hnrn.rnbmw.manager.entity.LoginUser;
import com.bonus.hnrn.rnbmw.manager.entity.Token;
import com.bonus.hnrn.rnbmw.manager.model.Permission;
import com.bonus.hnrn.rnbmw.manager.model.SysUser;
import com.bonus.hnrn.rnbmw.manager.service.TokenService;
import com.bonus.hnrn.rnbmw.manager.service.UserService;
import com.bonus.hnrn.rnbmw.manager.utils.AESCBCUtils;
import com.bonus.hnrn.rnbmw.manager.utils.ResponseUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.security.authentication.AuthenticationCredentialsNotFoundException;
import org.springframework.security.authentication.DisabledException;
import org.springframework.security.authentication.LockedException;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* 系统登录
*/
@Service
@Slf4j
public class PublicLoginService {
@Autowired
private UserService userService;
@Autowired
private PermissionDao permissionDao;
@Autowired
private TokenService tokenService;
/**
* 系统登录
* @param us
* @param response
*/
public void login(LoginForm us, HttpServletResponse response) {
String username = AESCBCUtils.decrypt(us.getUsername());
SysUser sysUser = userService.getUser(username);
if (sysUser == null) {
throw new AuthenticationCredentialsNotFoundException("用户名不存在");
} else if (sysUser.getStatus() == SysUser.Status.LOCKED) {
throw new LockedException("用户被锁定,请联系管理员");
} else if (sysUser.getStatus() == SysUser.Status.DISABLED) {
throw new DisabledException("用户已作废");
}
LoginUser loginUser = new LoginUser();
BeanUtils.copyProperties(sysUser, loginUser);
List<Permission> permissions = permissionDao.listByUserId(sysUser.getId());
loginUser.setPermissions(permissions);
try{
Token token = tokenService.saveToken(loginUser);
token.setCode("200");
token.setUsername(username);
ResponseUtil.responseJson(response, HttpStatus.OK.value(), token);
} catch (Exception e) {
log.error(e.toString(),e);
}
}
}

View File

@ -0,0 +1,11 @@
package com.bonus.hnrn.rnbmw.login.vo;
import lombok.Data;
@Data
public class LoginForm {
private String username;
private String type;
}

View File

@ -68,8 +68,8 @@ public class BnsSecurityConfig extends WebSecurityConfigurerAdapter {
http.authorizeRequests()
.antMatchers("/", "/gzRealName/**","/attendance/**","/*.html", "/favicon.ico", "/css/**", "/js/**", "/fonts/**", "/layui/**", "/layui-v2.9.2/**","/layui2.3.6/**", "/layer-v3.1.0/**","/img/**",
"/v2/api-docs/**", "/swagger-resources/**", "/webjars/**", "/pages/**", "/druid/**","/interface/**",
"/statics/**","/download/**","/allSystem/login","/realname/allSystem/login","/register/**","/companyManager/resetUserPwd","/getCode/**","/OwnContract/updateDownloadState")
"/v2/api-docs/**", "/swagger-resources/**", "/webjars/**", "/pages/**", "/druid/**","/interface/**","/publicLogin/**",
"/statics/**","/download/**","/allSystem/login","/register/**","/companyManager/resetUserPwd","/getCode/**","/OwnContract/updateDownloadState")
.permitAll().
anyRequest().authenticated();
http.formLogin().loginProcessingUrl("/login")

View File

@ -18,7 +18,27 @@ public class Token implements Serializable {
/** 登陆时间戳(毫秒) */
private Long loginTime;
public Token(String token, Long loginTime,String roleId) {
private String code;
private String username;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public Token(String token, Long loginTime, String roleId) {
super();
this.token = token;
this.loginTime = loginTime;

View File

@ -20,7 +20,7 @@ spring:
nacos:
config:
server-addr: 192.168.0.14:18848
namespace: e0337b55-080d-456e-8449-46d68dceee5b
namespace: 7c801fed-8b1c-4e57-8099-fe4e5e2b6b64
# 配置文件格式
file-extension: yml
group: DEFAULT_GROUP
@ -28,7 +28,7 @@ spring:
discovery:
# nacos地址
server-addr: 192.168.0.14:18848
namespace: e0337b55-080d-456e-8449-46d68dceee5b
namespace: 7c801fed-8b1c-4e57-8099-fe4e5e2b6b64
logging:
level:

View File

@ -1,6 +1,7 @@
package com.bonus.hnrn.rnmw.core.controller;
import com.bonus.hnrn.rnmw.core.entity.LoginForm;
import com.bonus.hnrn.rnmw.core.service.PublicLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

View File

@ -1,9 +1,8 @@
package com.bonus.hnrn.rnmw.core.controller;
package com.bonus.hnrn.rnmw.core.service;
import com.bonus.hnrn.rnmw.core.dao.UserDao;
import com.bonus.hnrn.rnmw.core.entity.LoginForm;
import com.bonus.hnrn.rnmw.core.entity.UserBean;
import com.bonus.hnrn.rnmw.core.service.TokenService;
import com.bonus.hnrn.rnmw.core.util.AESCBCUtils;
import com.bonus.hnrn.rnmw.core.util.ResponseUtil;
import com.bonus.hnrn.rnmw.core.util.StringHelper;

View File

@ -20,7 +20,7 @@ spring:
nacos:
config:
server-addr: 192.168.0.14:18848
namespace: e0337b55-080d-456e-8449-46d68dceee5b
namespace: 7c801fed-8b1c-4e57-8099-fe4e5e2b6b64
# 配置文件格式
file-extension: yml
group: DEFAULT_GROUP
@ -28,7 +28,7 @@ spring:
discovery:
# nacos地址
server-addr: 192.168.0.14:18848
namespace: e0337b55-080d-456e-8449-46d68dceee5b
namespace: 7c801fed-8b1c-4e57-8099-fe4e5e2b6b64
logging:

View File

@ -0,0 +1,37 @@
package com.bonus.hn.bearing.capacity.backstage.login.controller;
import com.bonus.hn.bearing.capacity.backstage.login.service.PublicLoginService;
import com.bonus.hn.bearing.capacity.backstage.login.vo.LoginForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
/**
* 默认公共登录方法
*/
@RestController
@RequestMapping(value = "/publicLogin")
public class PublicLoginController {
@Autowired
private PublicLoginService loginService;
/**
* 系统登录
* @param token
* @param response
*/
@PostMapping("defaultLogin")
public void login(@RequestBody LoginForm token, HttpServletResponse response) {
loginService.login(token,response);
}
}

View File

@ -0,0 +1,103 @@
package com.bonus.hn.bearing.capacity.backstage.login.service;
import com.bonus.hn.bearing.capacity.backstage.login.vo.LoginForm;
import com.bonus.hn.bearing.capacity.backstage.manager.dao.PermissionDao;
import com.bonus.hn.bearing.capacity.backstage.manager.dao.UtilDao;
import com.bonus.hn.bearing.capacity.backstage.manager.entity.LoginUser;
import com.bonus.hn.bearing.capacity.backstage.manager.entity.Token;
import com.bonus.hn.bearing.capacity.backstage.manager.model.Permission;
import com.bonus.hn.bearing.capacity.backstage.manager.model.SysUser;
import com.bonus.hn.bearing.capacity.backstage.manager.service.TokenService;
import com.bonus.hn.bearing.capacity.backstage.manager.service.UserService;
import com.bonus.hn.bearing.capacity.backstage.manager.utils.ResponseUtil;
import com.bonus.hn.bearing.capacity.backstage.utils.Aes;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.security.authentication.AuthenticationCredentialsNotFoundException;
import org.springframework.security.authentication.DisabledException;
import org.springframework.security.authentication.LockedException;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
/**
* 系统登录
*/
@Service
@Slf4j
public class PublicLoginService {
@Autowired
private UserService userService;
@Autowired
private PermissionDao permissionDao;
@Autowired
private UtilDao utilDao;
@Autowired
private TokenService tokenService;
/**
* 系统登录
* @param us
* @param response
*/
public void login(LoginForm us, HttpServletResponse response) {
String username= Aes.aesDecrypt(us.getUsername());
SysUser sysUser = userService.getUser(username);
if (sysUser == null) {
throw new AuthenticationCredentialsNotFoundException("用户名不存在");
} else if (sysUser.getStatus() == SysUser.Status.LOCKED) {
throw new LockedException("用户被锁定,请联系管理员");
} else if (sysUser.getStatus() == SysUser.Status.DISABLED) {
throw new DisabledException("用户已作废");
}
LoginUser loginUser = new LoginUser();
BeanUtils.copyProperties(sysUser, loginUser);
List<Permission> permissions = permissionDao.listByUserId(sysUser.getId());
loginUser.setPermissions(permissions);
try {
// 获取当前IP地址
InetAddress ipAddress = InetAddress.getLocalHost();
String ip = ipAddress.getHostAddress();
// 获取系统名称
String systemName = System.getProperty("os.name");
// 获取所在位置主机名
String hostName = ipAddress.getHostName();
LocalDate currentYearMonth = LocalDate.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
String formattedYearMonth = currentYearMonth.format(formatter);
// 创建SysUser对象并设置值
SysUser b = new SysUser();
b.setIpAddress(ip);
b.setSystemName(systemName);
b.setHostName(hostName);
b.setMonth(formattedYearMonth);
b.setUserId(sysUser.getId().toString());
utilDao.insertLoginInfo(b);
//创建token
Token token = tokenService.saveToken(loginUser);
token.setCode("200");
token.setUserName(username);
ResponseUtil.responseJson(response, HttpStatus.OK.value(), token);
} catch (UnknownHostException e) {
log.error(e.toString(),e);
}
}
}

View File

@ -0,0 +1,11 @@
package com.bonus.hn.bearing.capacity.backstage.login.vo;
import lombok.Data;
@Data
public class LoginForm {
private String username;
private String type;
}

View File

@ -63,7 +63,7 @@ public class BnsSecurityConfig extends WebSecurityConfigurerAdapter {
http.authorizeRequests()
.antMatchers("/", "/*.html", "/favicon.ico", "/css/**", "/js/**", "/fonts/**", "/layui/**", "/img/**","/layui-v2.8.18/**","/downloadTemplateController/**",
"/newPro/**","/v2/api-docs/**", "/swagger-resources/**", "/webjars/**", "/pages/**", "/druid/**","/getCode/**",
"/statics/**")
"/statics/**","/publicLogin/**")
.permitAll().anyRequest().authenticated();
http.formLogin().loginProcessingUrl("/login")
.successHandler(authenticationSuccessHandler).failureHandler(authenticationFailureHandler).and()

View File

@ -14,6 +14,27 @@ public class Token implements Serializable {
private static final long serialVersionUID = 6314027741784310221L;
private String token;
private String code;
private String userName;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
/** 登陆时间戳(毫秒) */
private Long loginTime;

View File

@ -24,10 +24,10 @@ spring:
discovery:
# nacos地址
server-addr: 192.168.0.14:18848
namespace: e0337b55-080d-456e-8449-46d68dceee5b
namespace: 7c801fed-8b1c-4e57-8099-fe4e5e2b6b64
config:
server-addr: 192.168.0.14:18848
namespace: e0337b55-080d-456e-8449-46d68dceee5b
namespace: 7c801fed-8b1c-4e57-8099-fe4e5e2b6b64
# 配置文件格式
file-extension: yml
group: DEFAULT_GROUP

View File

@ -56,7 +56,7 @@ public class AuthFilter implements GlobalFilter, Ordered {
}
}
String token = getToken(request);
if (StringUtils.isEmpty(token)) {
if (StringUtils.isEmpty(token) || "null".equals(token)) {
return unauthorizedResponse(exchange, "令牌不能为空");
}
Claims claims = JwtUtils.parseToken(token);

View File

@ -7,11 +7,11 @@ spring:
discovery:
# 服务注册地址
server-addr: 192.168.0.14:18848
namespace: e0337b55-080d-456e-8449-46d68dceee5b
namespace: 7c801fed-8b1c-4e57-8099-fe4e5e2b6b64
config:
# 配置中心地址
server-addr: 192.168.0.14:18848
namespace: e0337b55-080d-456e-8449-46d68dceee5b
namespace: 7c801fed-8b1c-4e57-8099-fe4e5e2b6b64
# 配置文件格式
file-extension: yml
# 共享配置

View File

@ -9,10 +9,10 @@ spring:
nacos:
discovery:
server-addr: 192.168.0.14:18848
namespace: e0337b55-080d-456e-8449-46d68dceee5b
namespace: 7c801fed-8b1c-4e57-8099-fe4e5e2b6b64
config:
server-addr: 192.168.0.14:18848
namespace: e0337b55-080d-456e-8449-46d68dceee5b
namespace: 7c801fed-8b1c-4e57-8099-fe4e5e2b6b64
# 配置文件格式
file-extension: yml
group: DEFAULT_GROUP

View File

@ -9,10 +9,10 @@ spring:
nacos:
discovery:
server-addr: 192.168.0.14:18848
namespace: e0337b55-080d-456e-8449-46d68dceee5b
namespace: 7c801fed-8b1c-4e57-8099-fe4e5e2b6b64
config:
server-addr: 192.168.0.14:18848
namespace: e0337b55-080d-456e-8449-46d68dceee5b
namespace: 7c801fed-8b1c-4e57-8099-fe4e5e2b6b64
# 配置文件格式
file-extension: yml
group: DEFAULT_GROUP

View File

@ -0,0 +1,38 @@
package com.bonus.hn.bearing.capacity.screen.login.controller;
import com.bonus.hn.bearing.capacity.screen.login.service.PublicLoginService;
import com.bonus.hn.bearing.capacity.screen.login.vo.LoginForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
/**
* 默认公共登录方法
*/
@RestController
@RequestMapping(value = "/publicLogin")
public class PublicLoginController {
@Autowired
private PublicLoginService loginService;
/**
* 系统登录
* @param token
* @param response
*/
@PostMapping("defaultLogin")
public void login(@RequestBody LoginForm token, HttpServletResponse response) {
loginService.login(token,response);
}
}

View File

@ -0,0 +1,74 @@
package com.bonus.hn.bearing.capacity.screen.login.service;
import com.bonus.hn.bearing.capacity.screen.login.vo.LoginForm;
import com.bonus.hn.bearing.capacity.screen.manager.dao.PermissionDao;
import com.bonus.hn.bearing.capacity.screen.manager.entity.LoginUser;
import com.bonus.hn.bearing.capacity.screen.manager.entity.Token;
import com.bonus.hn.bearing.capacity.screen.manager.model.Permission;
import com.bonus.hn.bearing.capacity.screen.manager.model.SysUser;
import com.bonus.hn.bearing.capacity.screen.manager.service.TokenService;
import com.bonus.hn.bearing.capacity.screen.manager.service.UserService;
import com.bonus.hn.bearing.capacity.screen.manager.utils.Aes;
import com.bonus.hn.bearing.capacity.screen.manager.utils.ResponseUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.security.authentication.AuthenticationCredentialsNotFoundException;
import org.springframework.security.authentication.DisabledException;
import org.springframework.security.authentication.LockedException;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletResponse;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
/**
* 系统登录
*/
@Service
@Slf4j
public class PublicLoginService {
@Autowired
private UserService userService;
@Autowired
private PermissionDao permissionDao;
@Autowired
private TokenService tokenService;
/**
* 系统登录
* @param us
* @param response
*/
public void login(LoginForm us, HttpServletResponse response) {
String username= Aes.aesDecrypt(us.getUsername());
SysUser sysUser = userService.getUser(username);
if (sysUser == null) {
throw new AuthenticationCredentialsNotFoundException("用户名不存在");
} else if (sysUser.getStatus() == SysUser.Status.LOCKED) {
throw new LockedException("用户被锁定,请联系管理员");
} else if (sysUser.getStatus() == SysUser.Status.DISABLED) {
throw new DisabledException("用户已作废");
}
try {
LoginUser loginUser = new LoginUser();
BeanUtils.copyProperties(sysUser, loginUser);
List<Permission> permissions = permissionDao.listByUserId(sysUser.getId());
loginUser.setPermissions(permissions);
Token token = tokenService.saveToken(loginUser);
token.setCode("200");
token.setUserame(username);
ResponseUtil.responseJson(response, HttpStatus.OK.value(), token);
} catch (Exception e) {
log.error(e.toString(),e);
}
}
}

View File

@ -0,0 +1,11 @@
package com.bonus.hn.bearing.capacity.screen.login.vo;
import lombok.Data;
@Data
public class LoginForm {
private String username;
private String type;
}

View File

@ -59,7 +59,7 @@ public class BnsSecurityConfig extends WebSecurityConfigurerAdapter {
http.authorizeRequests()
.antMatchers("/", "/*.html", "/favicon.ico", "/css/**", "/js/**", "/fonts/**", "/layui/**", "/img/**",
"/v2/api-docs/**", "/swagger-resources/**", "/webjars/**", "/pages/**", "/druid/**","/getCode/**",
"/statics/**","/dataInterface/**","/static/pages/img/home/**")
"/statics/**","/dataInterface/**","/static/pages/img/home/**","/publicLogin/**")
.permitAll().anyRequest().authenticated();
http.formLogin().loginProcessingUrl("/login")
.successHandler(authenticationSuccessHandler)

View File

@ -73,8 +73,8 @@ public class SecurityHandlerConfig {
} else {
msg = exception.getMessage();
}
ResponseInfo info = new ResponseInfo(HttpStatus.UNAUTHORIZED.value() + "", msg);
ResponseUtil.responseJson(response, HttpStatus.UNAUTHORIZED.value(), info);
ResponseInfo info = new ResponseInfo(HttpStatus.INTERNAL_SERVER_ERROR.value() + "", msg);
ResponseUtil.responseJson(response, HttpStatus.INTERNAL_SERVER_ERROR.value(), info);
}
};

View File

@ -17,6 +17,26 @@ public class Token implements Serializable {
/** 登陆时间戳(毫秒) */
private Long loginTime;
private String code;
private String userame;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getUserame() {
return userame;
}
public void setUserame(String userame) {
this.userame = userame;
}
public Token(String token, Long loginTime) {
super();
this.token = token;

View File

@ -41,6 +41,7 @@ public class VerifyFilter extends OncePerRequestFilter {
String vCode = request.getParameter("verifyCode");// 图片验证码的 value
String s = validateVerify(request, uuid, vCode);
if(!"".equals(s)) {
response.setStatus(HttpServletResponse.SC_PAYMENT_REQUIRED); // 401 状态码
authenticationFailureHandler.onAuthenticationFailure(request, response,new VerifyCodeException(s));
} else {
filterChain.doFilter(request,response);

View File

@ -24,10 +24,10 @@ spring:
discovery:
# nacos地址
server-addr: 192.168.0.14:18848
namespace: e0337b55-080d-456e-8449-46d68dceee5b
namespace: 7c801fed-8b1c-4e57-8099-fe4e5e2b6b64
config:
server-addr: 192.168.0.14:18848
namespace: e0337b55-080d-456e-8449-46d68dceee5b
namespace: 7c801fed-8b1c-4e57-8099-fe4e5e2b6b64
# 配置文件格式
file-extension: yml
group: DEFAULT_GROUP