mirror of
https://github.com/FatttSnake/Pinnacle-OA.git
synced 2026-04-05 06:51:23 +08:00
Added login, logout and getUserinfo (Include ui and server)
This commit is contained in:
@@ -14,6 +14,11 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.cors.CorsConfigurationSource;
|
||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Configuration
|
||||
public class SecurityConfig {
|
||||
@@ -42,7 +47,7 @@ public class SecurityConfig {
|
||||
}
|
||||
|
||||
@Bean
|
||||
AuthenticationManager authenticationManager(HttpSecurity httpSecurity, PasswordEncoder passwordEncoder) throws Exception {
|
||||
public AuthenticationManager authenticationManager(HttpSecurity httpSecurity, PasswordEncoder passwordEncoder) throws Exception {
|
||||
return httpSecurity.getSharedObject(AuthenticationManagerBuilder.class)
|
||||
.userDetailsService(userDetailsService)
|
||||
.passwordEncoder(passwordEncoder)
|
||||
@@ -50,22 +55,38 @@ public class SecurityConfig {
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CorsConfigurationSource corsConfigurationSource(){
|
||||
CorsConfiguration corsConfiguration = new CorsConfiguration();
|
||||
corsConfiguration.setAllowedMethods(List.of("*"));
|
||||
corsConfiguration.setAllowedHeaders(List.of("*"));
|
||||
corsConfiguration.setMaxAge(3600L);
|
||||
corsConfiguration.setAllowedOrigins(List.of("*"));
|
||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||
source.registerCorsConfiguration("/**",corsConfiguration);
|
||||
return source;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws Exception {
|
||||
return httpSecurity
|
||||
// Disable CSRF
|
||||
.csrf().disable()
|
||||
.csrf()
|
||||
.disable()
|
||||
|
||||
// Do not get SecurityContent by Session
|
||||
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
|
||||
.sessionManagement()
|
||||
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
|
||||
.and()
|
||||
|
||||
// Allow anonymous access
|
||||
.authorizeHttpRequests()
|
||||
.requestMatchers("/login").anonymous()
|
||||
.requestMatchers("/login")
|
||||
.anonymous()
|
||||
|
||||
// Authentication required
|
||||
.anyRequest().authenticated()
|
||||
.anyRequest()
|
||||
.authenticated()
|
||||
.and()
|
||||
|
||||
.logout()
|
||||
@@ -75,6 +96,10 @@ public class SecurityConfig {
|
||||
.authenticationEntryPoint(authenticationEntryPointHandler)
|
||||
.and()
|
||||
|
||||
.cors()
|
||||
.configurationSource(corsConfigurationSource())
|
||||
.and()
|
||||
|
||||
.addFilterBefore(jwtAuthenticationTokenFilter, UsernamePasswordAuthenticationFilter.class)
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -1,8 +1,17 @@
|
||||
package com.cfive.pinnacle.controller.permission;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.cfive.pinnacle.entity.common.ResponseResult;
|
||||
import com.cfive.pinnacle.entity.permission.Element;
|
||||
import com.cfive.pinnacle.service.permission.IElementService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 页面元素 前端控制器
|
||||
@@ -14,5 +23,26 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@RestController
|
||||
@RequestMapping("/element")
|
||||
public class ElementController {
|
||||
private IElementService elementService;
|
||||
|
||||
@Autowired
|
||||
public void setElementService(IElementService elementService) {
|
||||
this.elementService = elementService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public ResponseResult getAllElement() {
|
||||
List<Element> elements = elementService.list();
|
||||
|
||||
return ResponseResult.databaseSelectSuccess(elements);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseResult getElement(@PathVariable long id) {
|
||||
LambdaQueryWrapper<Element> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(Element::getId, id);
|
||||
Element element = elementService.getOne(wrapper);
|
||||
|
||||
return ResponseResult.databaseSelectSuccess(element);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,17 @@
|
||||
package com.cfive.pinnacle.controller.permission;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.cfive.pinnacle.entity.common.ResponseResult;
|
||||
import com.cfive.pinnacle.entity.permission.File;
|
||||
import com.cfive.pinnacle.service.permission.IFileService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 文件 前端控制器
|
||||
@@ -14,5 +23,26 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@RestController
|
||||
@RequestMapping("/file")
|
||||
public class FileController {
|
||||
private IFileService fileService;
|
||||
|
||||
@Autowired
|
||||
public void setFileService(IFileService fileService) {
|
||||
this.fileService = fileService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public ResponseResult getAllFile() {
|
||||
List<File> files = fileService.list();
|
||||
|
||||
return ResponseResult.databaseSelectSuccess(files);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseResult getFile(@PathVariable int id) {
|
||||
LambdaQueryWrapper<File> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(File::getId, id);
|
||||
File file = fileService.getOne(wrapper);
|
||||
|
||||
return ResponseResult.databaseSelectSuccess(file);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,14 +5,14 @@ import com.cfive.pinnacle.entity.common.ResponseCode;
|
||||
import com.cfive.pinnacle.entity.common.ResponseResult;
|
||||
import com.cfive.pinnacle.service.permission.ILoginService;
|
||||
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 org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
public class LoginController {
|
||||
|
||||
private ILoginService loginService;
|
||||
@@ -37,4 +37,11 @@ public class LoginController {
|
||||
return ResponseResult.build(ResponseCode.LOGOUT_FAILED, "Logout Failed", null);
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/userInfo")
|
||||
public ResponseResult getUserInfo() {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
Object principal = authentication.getPrincipal();
|
||||
return ResponseResult.success(principal);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,17 @@
|
||||
package com.cfive.pinnacle.controller.permission;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.cfive.pinnacle.entity.common.ResponseResult;
|
||||
import com.cfive.pinnacle.entity.permission.Menu;
|
||||
import com.cfive.pinnacle.service.permission.IMenuService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 菜单 前端控制器
|
||||
@@ -14,5 +23,26 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@RestController
|
||||
@RequestMapping("/menu")
|
||||
public class MenuController {
|
||||
private IMenuService menuService;
|
||||
|
||||
@Autowired
|
||||
public void setMenuService(IMenuService menuService) {
|
||||
this.menuService = menuService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public ResponseResult getAllMenu() {
|
||||
List<Menu> menus = menuService.list();
|
||||
|
||||
return ResponseResult.databaseSelectSuccess(menus);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseResult getMenu(@PathVariable int id) {
|
||||
LambdaQueryWrapper<Menu> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(Menu::getId, id);
|
||||
Menu menu = menuService.getOne(wrapper);
|
||||
|
||||
return ResponseResult.databaseSelectSuccess(menu);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,17 @@
|
||||
package com.cfive.pinnacle.controller.permission;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.cfive.pinnacle.entity.common.ResponseResult;
|
||||
import com.cfive.pinnacle.entity.permission.Operation;
|
||||
import com.cfive.pinnacle.service.permission.IOperationService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 功能 前端控制器
|
||||
@@ -14,5 +23,26 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@RestController
|
||||
@RequestMapping("/operation")
|
||||
public class OperationController {
|
||||
private IOperationService operationService;
|
||||
|
||||
@Autowired
|
||||
public void setOperationService(IOperationService operationService) {
|
||||
this.operationService = operationService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public ResponseResult getAllOperation() {
|
||||
List<Operation> operations = operationService.list();
|
||||
|
||||
return ResponseResult.databaseSelectSuccess(operations);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseResult getOperation(@PathVariable int id) {
|
||||
LambdaQueryWrapper<Operation> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(Operation::getId, id);
|
||||
Operation operation = operationService.getOne(wrapper);
|
||||
|
||||
return ResponseResult.databaseSelectSuccess(operation);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,17 @@
|
||||
package com.cfive.pinnacle.controller.permission;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.cfive.pinnacle.entity.common.ResponseResult;
|
||||
import com.cfive.pinnacle.entity.permission.OperationLog;
|
||||
import com.cfive.pinnacle.service.permission.IOperationLogService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 操作日志 前端控制器
|
||||
@@ -14,5 +23,26 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@RestController
|
||||
@RequestMapping("/operationLog")
|
||||
public class OperationLogController {
|
||||
private IOperationLogService operationLogService;
|
||||
|
||||
@Autowired
|
||||
public void setOperationLogService(IOperationLogService operationLogService) {
|
||||
this.operationLogService = operationLogService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public ResponseResult getAllOperationLog() {
|
||||
List<OperationLog> operationLogs = operationLogService.list();
|
||||
|
||||
return ResponseResult.databaseSelectSuccess(operationLogs);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseResult getOperationLog(@PathVariable int id) {
|
||||
LambdaQueryWrapper<OperationLog> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(OperationLog::getId, id);
|
||||
OperationLog operationLog = operationLogService.getOne(wrapper);
|
||||
|
||||
return ResponseResult.databaseSelectSuccess(operationLog);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package com.cfive.pinnacle.controller.permission;
|
||||
|
||||
import com.cfive.pinnacle.entity.common.ResponseResult;
|
||||
import com.cfive.pinnacle.entity.permission.PowerSet;
|
||||
import com.cfive.pinnacle.service.permission.IPowerService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@@ -14,5 +19,17 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@RestController
|
||||
@RequestMapping("/power")
|
||||
public class PowerController {
|
||||
private IPowerService powerService;
|
||||
|
||||
@Autowired
|
||||
public void setPowerService(IPowerService powerService) {
|
||||
this.powerService = powerService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public ResponseResult getAllPower() {
|
||||
PowerSet powerSet = powerService.getAllPower();
|
||||
|
||||
return ResponseResult.databaseSelectSuccess(powerSet);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.cfive.pinnacle.controller.permission;
|
||||
|
||||
import com.cfive.pinnacle.entity.common.ResponseCode;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.cfive.pinnacle.entity.common.ResponseResult;
|
||||
import com.cfive.pinnacle.entity.permission.*;
|
||||
import com.cfive.pinnacle.service.permission.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@@ -22,16 +22,25 @@ import java.util.List;
|
||||
@RestController
|
||||
@RequestMapping("/powerType")
|
||||
public class PowerTypeController {
|
||||
IPowerService powerTypeService;
|
||||
IPowerTypeService powerTypeService;
|
||||
|
||||
@Autowired
|
||||
public void setPowerTypeService(IPowerService powerTypeService) {
|
||||
public void setPowerTypeService(IPowerTypeService powerTypeService) {
|
||||
this.powerTypeService = powerTypeService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public ResponseResult getAllPowerType() {
|
||||
List<Power> powerTypes = powerTypeService.list();
|
||||
return ResponseResult.build(ResponseCode.DATABASE_SELECT_OK, "success", powerTypes);
|
||||
List<PowerType> powerTypes = powerTypeService.list();
|
||||
|
||||
return ResponseResult.databaseSelectSuccess(powerTypes);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseResult getPowerType(@PathVariable int id) {
|
||||
LambdaQueryWrapper<PowerType> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(PowerType::getId, id);
|
||||
PowerType powerType = powerTypeService.getOne(wrapper);
|
||||
|
||||
return ResponseResult.databaseSelectSuccess(powerType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,4 +55,20 @@ public class ResponseResult implements Serializable {
|
||||
public static ResponseResult fail(String msg, Object data) {
|
||||
return build(ResponseCode.SYSTEM_ERROR, msg, data);
|
||||
}
|
||||
|
||||
public static ResponseResult databaseSelectSuccess(Object object) {
|
||||
return build(ResponseCode.DATABASE_SELECT_OK, "success", object);
|
||||
}
|
||||
|
||||
public static ResponseResult databaseSaveSuccess(Object object) {
|
||||
return build(ResponseCode.DATABASE_SAVE_OK, "success", object);
|
||||
}
|
||||
|
||||
public static ResponseResult databaseUpdateSuccess(Object object) {
|
||||
return build(ResponseCode.DATABASE_UPDATE_OK, "success", object);
|
||||
}
|
||||
|
||||
public static ResponseResult databaseDeleteSuccess() {
|
||||
return build(ResponseCode.DATABASE_DELETE_OK, "success", null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.cfive.pinnacle.entity.permission;
|
||||
|
||||
import com.cfive.pinnacle.entity.User;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
@@ -14,102 +15,46 @@ import java.util.Collection;
|
||||
@AllArgsConstructor
|
||||
public class LoginUser implements UserDetails {
|
||||
private User user;
|
||||
private Collection<? extends GrantedAuthority> authorities;
|
||||
private String password;
|
||||
private String username;
|
||||
private Boolean accountNonExpired = true;
|
||||
private Boolean accountNonLocked = true;
|
||||
private Boolean credentialsNonExpired = true;
|
||||
private Boolean enabled = true;
|
||||
|
||||
public LoginUser(User user) {
|
||||
this.user = user;
|
||||
this.username = user.getUsername();
|
||||
this.password = user.getPasswd();
|
||||
this.enabled = user.getEnable() == 1;
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||
return authorities;
|
||||
}
|
||||
|
||||
public void setAuthorities(Collection<? extends GrantedAuthority> authorities) {
|
||||
this.authorities = authorities;
|
||||
return null;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
return user.getPasswd();
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public String getUsername() {
|
||||
return username;
|
||||
return user.getUsername();
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public boolean isAccountNonExpired() {
|
||||
return this.accountNonExpired;
|
||||
return true;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public boolean isAccountNonLocked() {
|
||||
return this.accountNonLocked;
|
||||
return true;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public boolean isCredentialsNonExpired() {
|
||||
return this.credentialsNonExpired;
|
||||
return true;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public Boolean getAccountNonExpired() {
|
||||
return accountNonExpired;
|
||||
}
|
||||
|
||||
public void setAccountNonExpired(Boolean accountNonExpired) {
|
||||
this.accountNonExpired = accountNonExpired;
|
||||
}
|
||||
|
||||
public Boolean getAccountNonLocked() {
|
||||
return accountNonLocked;
|
||||
}
|
||||
|
||||
public void setAccountNonLocked(Boolean accountNonLocked) {
|
||||
this.accountNonLocked = accountNonLocked;
|
||||
}
|
||||
|
||||
public Boolean getCredentialsNonExpired() {
|
||||
return credentialsNonExpired;
|
||||
}
|
||||
|
||||
public void setCredentialsNonExpired(Boolean credentialsNonExpired) {
|
||||
this.credentialsNonExpired = credentialsNonExpired;
|
||||
}
|
||||
|
||||
public Boolean getEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(Boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
return user.getEnable() == 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,12 +45,6 @@ public class Operation implements Serializable {
|
||||
@TableField("code")
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* URL 前缀
|
||||
*/
|
||||
@TableField("url_prefix")
|
||||
private String urlPrefix;
|
||||
|
||||
/**
|
||||
* 权限ID
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.cfive.pinnacle.entity.permission;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
public class PowerSet implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private List<Operation> operationList;
|
||||
|
||||
private List<Menu> menuList;
|
||||
|
||||
private List<Element> elementList;
|
||||
|
||||
private List<File> fileList;
|
||||
}
|
||||
@@ -49,7 +49,7 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter {
|
||||
if (Objects.isNull(loginUser)) {
|
||||
throw new RuntimeException("Not logged in");
|
||||
}
|
||||
|
||||
// Todo 权限
|
||||
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(loginUser, null, null);
|
||||
SecurityContextHolder.getContext().setAuthentication(authenticationToken);
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.cfive.pinnacle.service.permission;
|
||||
|
||||
import com.cfive.pinnacle.entity.permission.Power;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.cfive.pinnacle.entity.permission.PowerSet;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -12,5 +13,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
* @since 2023-04-30
|
||||
*/
|
||||
public interface IPowerService extends IService<Power> {
|
||||
|
||||
PowerSet getAllPower();
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ public class LoginServiceImpl implements ILoginService {
|
||||
}
|
||||
|
||||
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
|
||||
loginUser.getUser().setPasswd("");
|
||||
String userId = loginUser.getUser().getId().toString();
|
||||
String jwt = JwtUtil.createJWT(userId);
|
||||
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package com.cfive.pinnacle.service.permission.impl;
|
||||
|
||||
import com.cfive.pinnacle.entity.permission.Power;
|
||||
import com.cfive.pinnacle.entity.permission.*;
|
||||
import com.cfive.pinnacle.mapper.permission.PowerMapper;
|
||||
import com.cfive.pinnacle.service.permission.IPowerService;
|
||||
import com.cfive.pinnacle.service.permission.*;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 权限 服务实现类
|
||||
@@ -16,5 +19,38 @@ import org.springframework.stereotype.Service;
|
||||
*/
|
||||
@Service
|
||||
public class PowerServiceImpl extends ServiceImpl<PowerMapper, Power> implements IPowerService {
|
||||
private IOperationService operationService;
|
||||
private IMenuService menuService;
|
||||
private IElementService elementService;
|
||||
private IFileService fileService;
|
||||
|
||||
@Autowired
|
||||
public void setOperationService(IOperationService operationService) {
|
||||
this.operationService = operationService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setMenuService(IMenuService menuService) {
|
||||
this.menuService = menuService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setElementService(IElementService elementService) {
|
||||
this.elementService = elementService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setFileService(IFileService fileService) {
|
||||
this.fileService = fileService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PowerSet getAllPower() {
|
||||
List<Operation> operationList = operationService.list();
|
||||
List<Menu> menuList = menuService.list();
|
||||
List<Element> elementList = elementService.list();
|
||||
List<File> fileList = fileService.list();
|
||||
|
||||
return new PowerSet(operationList, menuList, elementList, fileList);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,9 @@ public class UserDetailsServiceImpl implements UserDetailsService {
|
||||
if (Objects.isNull(user)) {
|
||||
throw new UsernameNotFoundException("Username not found in database");
|
||||
}
|
||||
|
||||
// Todo 权限
|
||||
|
||||
return new LoginUser(user);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user