代码整理
This commit is contained in:
@@ -10,6 +10,7 @@ import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 程序启动器
|
||||
@@ -27,11 +28,14 @@ public class Application extends SpringBootServletInitializer {
|
||||
public static void main(String[] args) throws Exception {
|
||||
ConfigurableApplicationContext application = SpringApplication.run(Application.class, args);
|
||||
Environment env = application.getEnvironment();
|
||||
String contextPath = env.getProperty("server.servlet.context-path");
|
||||
contextPath = Optional.ofNullable(contextPath).orElse("").replaceFirst("/", "");
|
||||
contextPath = (contextPath.length() <= 0 || contextPath.endsWith("/")) ? contextPath : contextPath + "/";
|
||||
logger.info("\n----------------------------------------------------------\n\t" +
|
||||
"\t\t地址列表\n\t" +
|
||||
"文档地址:http://{}:{}/document.html\n" +
|
||||
"文档地址:http://{}:{}/{}document.html\n" +
|
||||
"----------------------------------------------------------",
|
||||
InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port")
|
||||
InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port"), contextPath
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.zyplayer.doc.manage.framework.config;
|
||||
|
||||
import org.springframework.boot.web.server.ErrorPage;
|
||||
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
|
||||
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
@Configuration
|
||||
public class CustomizationBean implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> {
|
||||
|
||||
@Override
|
||||
public void customize(ConfigurableServletWebServerFactory factory) {
|
||||
factory.addErrorPages(new ErrorPage(HttpStatus.FORBIDDEN, "/statics/common/403.html"));
|
||||
factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/statics/common/404.html"));
|
||||
factory.addErrorPages(new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/statics/common/500.html"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,13 +1,19 @@
|
||||
package com.zyplayer.doc.manage.framework.config;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.mg.swagger.framework.service.MgStorageService;
|
||||
import com.zyplayer.doc.manage.repository.manage.entity.ZyplayerStorage;
|
||||
import com.zyplayer.doc.manage.service.manage.ZyplayerStorageService;
|
||||
import com.zyplayer.doc.swagger.framework.service.MgStorage;
|
||||
import com.zyplayer.doc.swagger.framework.service.MgStorageService;
|
||||
|
||||
/**
|
||||
* 申明为@Service之后网页上才能使用存储能力,同时需要在@EnableSwagger2的地方添加@EnableSwaggerMgUi注解,
|
||||
@@ -31,7 +37,7 @@ public class MgStorageServiceImpl implements MgStorageService {
|
||||
@Override
|
||||
public String get(String key) {
|
||||
QueryWrapper<ZyplayerStorage> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq(true, "doc_key", key);
|
||||
wrapper.eq("doc_key", key);
|
||||
ZyplayerStorage zyplayerStorage = zyplayerStorageService.getOne(wrapper);
|
||||
if (zyplayerStorage == null) {
|
||||
return null;
|
||||
@@ -39,6 +45,21 @@ public class MgStorageServiceImpl implements MgStorageService {
|
||||
return zyplayerStorage.getDocValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MgStorage> like(String key, String value) {
|
||||
QueryWrapper<ZyplayerStorage> wrapper = new QueryWrapper<>();
|
||||
wrapper.like(StringUtils.isNotBlank(key), "doc_key", key);
|
||||
wrapper.like(StringUtils.isNotBlank(value), "doc_value", value);
|
||||
List<ZyplayerStorage> storageList = zyplayerStorageService.list(wrapper);
|
||||
if (storageList == null || storageList.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<MgStorage> resultList = storageList.stream().map(val -> {
|
||||
return new MgStorage(val.getDocKey(), val.getDocValue());
|
||||
}).collect(Collectors.toList());
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用数据库来存储,例: storageMapper.updateOrInsert(key, value);
|
||||
*/
|
||||
|
||||
@@ -1,9 +1,21 @@
|
||||
|
||||
package com.zyplayer.doc.manage.framework.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.mg.swagger.framework.configuration.EnableSwaggerMgUi;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.zyplayer.doc.swagger.framework.configuration.EnableSwaggerMgUi;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.service.ApiInfo;
|
||||
import springfox.documentation.service.Contact;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
/**
|
||||
* 不需要管理本项目的文档,只需要开启@EnableSwaggerMgUi即可
|
||||
@@ -11,12 +23,34 @@ import com.mg.swagger.framework.configuration.EnableSwaggerMgUi;
|
||||
* @since 2018年11月11日
|
||||
*/
|
||||
@Configuration
|
||||
@EnableSwagger2
|
||||
@EnableSwaggerMgUi(
|
||||
selfDoc = false,// 不开启自身的文档,本项目只当管理文档的项目使用
|
||||
defaultResources = {// selfDoc=false时有用,启动后第一次访问没有数据情况下需要加载进来的swagger-resources地址
|
||||
selfDoc = true,// 是否开启自身的文档
|
||||
defaultResources = {// 启动后第一次访问没有数据情况下需要加载进来的swagger-resources地址
|
||||
//"http://localhost:8080/swagger-resources"
|
||||
}
|
||||
)
|
||||
public class SwaggerConfiguration {
|
||||
|
||||
|
||||
@Bean
|
||||
public Docket createRestApi() {
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.apiInfo(apiInfo())
|
||||
.select()
|
||||
.apis(Predicates.or(
|
||||
RequestHandlerSelectors.basePackage("com.zyplayer.doc.manage"),
|
||||
RequestHandlerSelectors.withClassAnnotation(Api.class)))
|
||||
.paths(PathSelectors.any())
|
||||
.build();
|
||||
}
|
||||
|
||||
private ApiInfo apiInfo() {
|
||||
return new ApiInfoBuilder()
|
||||
.title("zyplayer-doc-manage接口文档")
|
||||
.description("欢迎使用")
|
||||
.termsOfServiceUrl("")
|
||||
.contact(new Contact("", "", ""))
|
||||
.version("1.0")
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
package com.zyplayer.doc.manage.framework.config.security;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -7,6 +8,8 @@ import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.web.DefaultRedirectStrategy;
|
||||
import org.springframework.security.web.RedirectStrategy;
|
||||
@@ -15,13 +18,12 @@ import org.springframework.security.web.savedrequest.HttpSessionRequestCache;
|
||||
import org.springframework.security.web.savedrequest.RequestCache;
|
||||
import org.springframework.security.web.savedrequest.SavedRequest;
|
||||
|
||||
/**
|
||||
* 备用
|
||||
* @author Administrator
|
||||
*
|
||||
*/
|
||||
public class MyAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
|
||||
import com.alibaba.fastjson.JSON;
|
||||
|
||||
public class DocAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(DocAuthenticationSuccessHandler.class);
|
||||
|
||||
private RequestCache requestCache = new HttpSessionRequestCache();
|
||||
private RedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
|
||||
|
||||
@@ -29,18 +31,16 @@ public class MyAuthenticationSuccessHandler implements AuthenticationSuccessHand
|
||||
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
|
||||
SavedRequest savedRequest = requestCache.getRequest(request, response);
|
||||
String targetUrl = savedRequest.getRedirectUrl();
|
||||
// boolean isAjax = HttpHelper.isAjaxRequest(request);
|
||||
boolean isAjax = true;
|
||||
boolean isAjax = "XMLHttpRequest".equals(request.getHeader("X-Requested-With"));
|
||||
if (isAjax) {
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
result.put("url", targetUrl);
|
||||
response.getWriter().print(result.toString());
|
||||
response.getWriter().print(JSON.toJSONString(result));
|
||||
response.getWriter().flush();
|
||||
} else {
|
||||
redirectStrategy.sendRedirect(request, response, targetUrl);
|
||||
}
|
||||
|
||||
System.out.println("Redirecting to DefaultSavedRequest Url: " + targetUrl);
|
||||
logger.info("Redirecting to DefaultSavedRequest Url: " + targetUrl);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.zyplayer.doc.manage.framework.config.security;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.zyplayer.doc.manage.repository.manage.entity.AuthInfo;
|
||||
import com.zyplayer.doc.manage.repository.manage.entity.UserAuth;
|
||||
import com.zyplayer.doc.manage.repository.manage.entity.UserInfo;
|
||||
import com.zyplayer.doc.manage.service.manage.AuthInfoService;
|
||||
import com.zyplayer.doc.manage.service.manage.UserAuthService;
|
||||
import com.zyplayer.doc.manage.service.manage.UserInfoService;
|
||||
|
||||
@Service
|
||||
public class DocDetailsServiceImpl implements UserDetailsService {
|
||||
|
||||
@Autowired
|
||||
private UserInfoService userInfoService;
|
||||
@Autowired
|
||||
private UserAuthService userAuthService;
|
||||
@Autowired
|
||||
private AuthInfoService authInfoService;
|
||||
|
||||
@Override
|
||||
public UserDetails loadUserByUsername(String userNo) throws UsernameNotFoundException {
|
||||
QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("user_no", userNo);
|
||||
UserInfo userInfo = userInfoService.getOne(queryWrapper);
|
||||
if (userInfo == null) {
|
||||
throw new UsernameNotFoundException("用户名'" + userNo + "'没有找到!");
|
||||
}
|
||||
QueryWrapper<UserAuth> authWrapper = new QueryWrapper<>();
|
||||
authWrapper.eq("user_id", userInfo.getId()).eq("del_flag", "0");
|
||||
List<UserAuth> userAuthList = userAuthService.list(authWrapper);
|
||||
List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
|
||||
if (userAuthList != null && userAuthList.size() > 0) {
|
||||
List<Long> authIdList = userAuthList.stream().collect(Collectors.mapping(UserAuth::getAuthId, Collectors.toList()));
|
||||
Collection<AuthInfo> authInfoList = authInfoService.listByIds(authIdList);
|
||||
authInfoList.forEach(val -> {
|
||||
authorities.add(new SimpleGrantedAuthority(val.getAuthName()));
|
||||
});
|
||||
}
|
||||
//String pwdMd5 = DigestUtils.md5DigestAsHex(userInfo.getPassword().getBytes());
|
||||
DocUserDetails userDetails = new DocUserDetails(userInfo.getId(), userInfo.getUserNo(), userInfo.getPassword(), true, authorities);
|
||||
return userDetails;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,16 +5,16 @@ import java.util.Collection;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
|
||||
public class MyUserDetails implements UserDetails {
|
||||
public class DocUserDetails implements UserDetails {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Integer userId;
|
||||
private Long userId;
|
||||
private String username;
|
||||
private String password;
|
||||
private boolean enabled;
|
||||
private Collection<? extends GrantedAuthority> authorities;
|
||||
|
||||
public MyUserDetails(Integer userId, String username, String password, boolean enabled) {
|
||||
public DocUserDetails(Long userId, String username, String password, boolean enabled) {
|
||||
super();
|
||||
this.userId = userId;
|
||||
this.username = username;
|
||||
@@ -22,7 +22,7 @@ public class MyUserDetails implements UserDetails {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public MyUserDetails(Integer userId, String username, String password, boolean enabled,
|
||||
public DocUserDetails(Long userId, String username, String password, boolean enabled,
|
||||
Collection<? extends GrantedAuthority> authorities) {
|
||||
super();
|
||||
this.userId = userId;
|
||||
@@ -32,7 +32,7 @@ public class MyUserDetails implements UserDetails {
|
||||
this.authorities = authorities;
|
||||
}
|
||||
|
||||
public Integer getUserId() {
|
||||
public Long getUserId() {
|
||||
return this.userId;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.zyplayer.doc.manage.framework.config.security;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.FilterConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class DocUserFilter implements Filter{
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) throws ServletException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
|
||||
HttpServletRequest httpRequest = (HttpServletRequest) request;
|
||||
Cookie[] cookies = httpRequest.getCookies();
|
||||
boolean haveCtx = false;
|
||||
Object ctxObj = httpRequest.getServletContext().getAttribute("ctx");
|
||||
String ctxStr = String.valueOf(ctxObj);
|
||||
if (cookies != null && cookies.length > 0) {
|
||||
for (Cookie cookie : cookies) {
|
||||
if ("ctx".equals(cookie.getName()) && ctxStr.equals(cookie.getValue())) {
|
||||
haveCtx = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!haveCtx) {
|
||||
// 前后端分离的,前段拿不到项目名,直接写/是不对的,只有后端放到cookie里给前端
|
||||
HttpServletResponse httpResponse = (HttpServletResponse) response;
|
||||
Cookie cookieAdd = new Cookie("ctx", ctxStr);
|
||||
cookieAdd.setPath("/");
|
||||
httpResponse.addCookie(cookieAdd);
|
||||
}
|
||||
chain.doFilter(httpRequest, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,20 +6,20 @@ import org.springframework.security.core.context.SecurityContextHolder;
|
||||
/**
|
||||
* 用户工具类
|
||||
*/
|
||||
public class UserUtil {
|
||||
public class DocUserUtil {
|
||||
|
||||
/**
|
||||
* 获取当前用户
|
||||
* @return
|
||||
*/
|
||||
public static MyUserDetails getCurrentUser() {
|
||||
public static DocUserDetails getCurrentUser() {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
Object principal = null;
|
||||
if (authentication != null) {
|
||||
principal = authentication.getPrincipal();
|
||||
}
|
||||
if (principal != null && principal instanceof MyUserDetails) {
|
||||
return (MyUserDetails) principal;
|
||||
if (principal != null && principal instanceof DocUserDetails) {
|
||||
return (DocUserDetails) principal;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -10,9 +10,9 @@ import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.AuthenticationException;
|
||||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
||||
|
||||
public class MyUsernamePasswordAuthenticationFilter extends UsernamePasswordAuthenticationFilter {
|
||||
public class DocUsernamePasswordAuthenticationFilter extends UsernamePasswordAuthenticationFilter {
|
||||
// 是否开启验证码功能
|
||||
private boolean isOpenValidateCode = true;
|
||||
private boolean isOpenValidateCode = false;
|
||||
|
||||
public static final String VALIDATE_CODE = "validateCode";
|
||||
|
||||
@@ -25,13 +25,11 @@ public class MyUsernamePasswordAuthenticationFilter extends UsernamePasswordAuth
|
||||
|
||||
protected void checkValidateCode(HttpServletRequest request) {
|
||||
HttpSession session = request.getSession();
|
||||
|
||||
String sessionValidateCode = obtainSessionValidateCode(session);
|
||||
sessionValidateCode = "1234";// 做个假的验证码;
|
||||
String sessionCode = this.obtainSessionValidateCode(session);
|
||||
// 让上一次的验证码失效
|
||||
session.setAttribute(VALIDATE_CODE, null);
|
||||
String validateCodeParameter = obtainValidateCodeParameter(request);
|
||||
if (StringUtils.isEmpty(validateCodeParameter) || !sessionValidateCode.equalsIgnoreCase(validateCodeParameter)) {
|
||||
String parameterCode = this.obtainValidateCodeParameter(request);
|
||||
if (StringUtils.isEmpty(sessionCode) || !sessionCode.equalsIgnoreCase(parameterCode)) {
|
||||
throw new AuthenticationServiceException("验证码错误!");
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package com.zyplayer.doc.manage.framework.config.security;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.DigestUtils;
|
||||
|
||||
@Service
|
||||
public class UserDetailsServiceImpl implements UserDetailsService {
|
||||
private Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
@Override
|
||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
if ("1".equals(username)) {
|
||||
List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
|
||||
authorities.add(new SimpleGrantedAuthority("ROLE_1"));
|
||||
String pwd = DigestUtils.md5DigestAsHex("1".getBytes());
|
||||
return new MyUserDetails(1, "1", pwd, true, authorities);
|
||||
}
|
||||
throw new UsernameNotFoundException("用户名 '" + username + "'没有找到!");
|
||||
}
|
||||
}
|
||||
@@ -1,113 +0,0 @@
|
||||
package com.zyplayer.doc.manage.framework.config.security;
|
||||
//package com.zyplayer.doc.manage.framework.config.security;
|
||||
//
|
||||
//import java.io.IOException;
|
||||
//import java.io.PrintWriter;
|
||||
//
|
||||
//import javax.servlet.ServletException;
|
||||
//import javax.servlet.http.HttpServletRequest;
|
||||
//import javax.servlet.http.HttpServletResponse;
|
||||
//
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.context.annotation.Bean;
|
||||
//import org.springframework.context.annotation.Configuration;
|
||||
//import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||
//import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
//import org.springframework.security.config.annotation.web.builders.WebSecurity;
|
||||
//import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
//import org.springframework.security.core.Authentication;
|
||||
//import org.springframework.security.core.AuthenticationException;
|
||||
//import org.springframework.security.web.authentication.AuthenticationFailureHandler;
|
||||
//import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
|
||||
//import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler;
|
||||
//import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler;
|
||||
//
|
||||
//@Configuration
|
||||
//@EnableWebSecurity // 注解开启Spring Security的功能
|
||||
//public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
//
|
||||
// @Override
|
||||
// protected void configure(HttpSecurity http) throws Exception {
|
||||
// http.authorizeRequests()//定义哪些url需要保护,哪些url不需要保护
|
||||
// .antMatchers("/statics/lib/**", "/message/").permitAll()//定义不需要认证就可以访问
|
||||
// .anyRequest()
|
||||
// .authenticated()
|
||||
// .and()
|
||||
// .formLogin()
|
||||
// .loginPage("/statics/manage/login.html")// 定义当需要用户登录时候,转到的登录页面
|
||||
// .successHandler(new AuthenticationSuccessHandler() {
|
||||
// @Override
|
||||
// public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
|
||||
// httpServletResponse.setContentType("application/json;charset=utf-8");
|
||||
// PrintWriter out = httpServletResponse.getWriter();
|
||||
// out.write("{\"status\":\"ok\",\"msg\":\"登录成功\"}");
|
||||
// out.flush();
|
||||
// out.close();
|
||||
// }
|
||||
// }).failureHandler(new AuthenticationFailureHandler() {
|
||||
// @Override
|
||||
// public void onAuthenticationFailure(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
|
||||
// httpServletResponse.setContentType("application/json;charset=utf-8");
|
||||
// PrintWriter out = httpServletResponse.getWriter();
|
||||
// out.write("{\"status\":\"error\",\"msg\":\"登录失败\"}");
|
||||
// out.flush();
|
||||
// out.close();
|
||||
// }
|
||||
// })
|
||||
// .permitAll()
|
||||
// .loginProcessingUrl("/user/login")
|
||||
// .usernameParameter("username")
|
||||
// .passwordParameter("password")
|
||||
// .permitAll()
|
||||
// .and()
|
||||
// .logout()
|
||||
// .permitAll()
|
||||
// .and()
|
||||
// .csrf()
|
||||
// .disable();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
||||
// auth.userDetailsService(userDetailsServiceImpl());//.passwordEncoder(new Md5PasswordEncoder());
|
||||
// }
|
||||
//
|
||||
// @Bean
|
||||
// public UserDetailsServiceImpl userDetailsServiceImpl() {
|
||||
// return new UserDetailsServiceImpl();
|
||||
// }
|
||||
//
|
||||
// @Bean
|
||||
// public MyUsernamePasswordAuthenticationFilter myUsernamePasswordAuthenticationFilter() throws Exception {
|
||||
// MyUsernamePasswordAuthenticationFilter myFilter = new MyUsernamePasswordAuthenticationFilter();
|
||||
// myFilter.setAuthenticationManager(authenticationManagerBean());
|
||||
// myFilter.setAuthenticationSuccessHandler(authenticationSuccessHandler());
|
||||
// myFilter.setAuthenticationFailureHandler(authenticationFailureHandler());
|
||||
// myFilter.setRememberMeServices(tokenBasedRememberMeServices());
|
||||
// return myFilter;
|
||||
// }
|
||||
//
|
||||
// @Bean
|
||||
// public AuthenticationSuccessHandler authenticationSuccessHandler() {
|
||||
// return new SimpleUrlAuthenticationSuccessHandler("/login/success");
|
||||
// }
|
||||
//
|
||||
// @Bean
|
||||
// public AuthenticationFailureHandler authenticationFailureHandler() {
|
||||
// return new SimpleUrlAuthenticationFailureHandler("/login/failure");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void configure(WebSecurity web) throws Exception {
|
||||
// web.ignoring().antMatchers("/statics/lib/**", "**/css/**", "**/js/**", "**/img/**");
|
||||
// }
|
||||
//
|
||||
// @Autowired
|
||||
// public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
|
||||
// //在内存中创建了一个用户,该用户的名称为user,密码为password,用户角色为ADMIN
|
||||
// auth.inMemoryAuthentication()
|
||||
// .withUser("user").password("password").roles("ADMIN");
|
||||
// }
|
||||
//}
|
||||
//
|
||||
@@ -6,6 +6,7 @@ import org.springframework.core.annotation.Order;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.authentication.RememberMeAuthenticationProvider;
|
||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.builders.WebSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
@@ -21,9 +22,10 @@ import org.springframework.security.web.authentication.rememberme.RememberMeAuth
|
||||
import org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices;
|
||||
import org.springframework.util.DigestUtils;
|
||||
|
||||
@Order(1)
|
||||
@Configuration
|
||||
@EnableWebSecurity
|
||||
@Order(1)
|
||||
@EnableGlobalMethodSecurity(prePostEnabled = true)
|
||||
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
|
||||
@Bean
|
||||
@@ -37,38 +39,34 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
*/
|
||||
@Override
|
||||
public void configure(WebSecurity web) throws Exception {
|
||||
web.ignoring().antMatchers("/statics/lib/**", "/css/**", "/js/**", "/img/**");
|
||||
web.ignoring().antMatchers("/statics/lib/**", "/css/**", "/js/**", "/img/**", "/swagger-resources", "/v2/api-docs");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
String loginPage = "/statics/manage/login.html";
|
||||
|
||||
http.authorizeRequests().antMatchers("/login/**").permitAll()//为了测试其他功能,设置“ /** ”允许所有请求
|
||||
// user权限可以访问的请求
|
||||
.antMatchers("/security/user").hasRole("user")
|
||||
// admin权限可以访问的请求
|
||||
.antMatchers("/security/admin").hasRole("admin")
|
||||
// SpEL表达式:需要拥有user权限,且进行了完全认证
|
||||
.antMatchers("/user/account").access("hasRole('user') and isFullyAuthenticated()")
|
||||
// 其他地址的访问均需验证权限(需要登录)
|
||||
.antMatchers("/document.html").hasAuthority("DOC_ALL")
|
||||
// 其他地址的访问均需登录
|
||||
.anyRequest().authenticated().and()
|
||||
// 添加验证码验证
|
||||
.addFilterAt(myUsernamePasswordAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class).exceptionHandling()
|
||||
.authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/statics/manage/login.html")).and()
|
||||
.addFilterAt(rememberMeAuthenticationFilter(), RememberMeAuthenticationFilter.class)
|
||||
.addFilterAt(myUsernamePasswordAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class)
|
||||
.exceptionHandling()
|
||||
.authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint(loginPage))
|
||||
.and().addFilterAt(rememberMeAuthenticationFilter(), RememberMeAuthenticationFilter.class)
|
||||
// 指定登录页面的请求路径
|
||||
.formLogin().loginPage("/statics/manage/login.html")
|
||||
.formLogin().loginPage(loginPage)
|
||||
// 登陆处理路径
|
||||
.loginProcessingUrl("/login").permitAll().and()
|
||||
// 退出请求的默认路径为logout,下面改为signout,
|
||||
// 成功退出登录后的url可以用logoutSuccessUrl设置
|
||||
.logout().deleteCookies("remember-me")
|
||||
.logoutUrl("/signout")
|
||||
.logoutSuccessUrl("/statics/manage/login.html")
|
||||
.permitAll().and()
|
||||
.loginProcessingUrl("/login").permitAll()
|
||||
// 退出请求的默认路径为logout
|
||||
.and().logout().deleteCookies("remember-me")
|
||||
.logoutUrl("/logout").logoutSuccessUrl(loginPage)
|
||||
.permitAll()
|
||||
// 开启rememberMe,设置一个私钥专供testall项目使用,注意与下面TokenBasedRememberMeServices的key保持一致
|
||||
// .rememberMe().key("testallKey").and()
|
||||
// 关闭csrf
|
||||
.csrf().disable();
|
||||
.and().csrf().disable();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -81,19 +79,20 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
}
|
||||
@Override
|
||||
public boolean matches(CharSequence charSequence, String s) {
|
||||
return s.equals(DigestUtils.md5DigestAsHex(charSequence.toString().getBytes()));
|
||||
String digestAsHex = DigestUtils.md5DigestAsHex(charSequence.toString().getBytes());
|
||||
return s.equals(digestAsHex);
|
||||
}
|
||||
}).and().authenticationProvider(rememberMeAuthenticationProvider());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public UserDetailsServiceImpl userDetailsServiceImpl() {
|
||||
return new UserDetailsServiceImpl();
|
||||
public DocDetailsServiceImpl userDetailsServiceImpl() {
|
||||
return new DocDetailsServiceImpl();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MyUsernamePasswordAuthenticationFilter myUsernamePasswordAuthenticationFilter() throws Exception {
|
||||
MyUsernamePasswordAuthenticationFilter myFilter = new MyUsernamePasswordAuthenticationFilter();
|
||||
public DocUsernamePasswordAuthenticationFilter myUsernamePasswordAuthenticationFilter() throws Exception {
|
||||
DocUsernamePasswordAuthenticationFilter myFilter = new DocUsernamePasswordAuthenticationFilter();
|
||||
myFilter.setAuthenticationManager(authenticationManagerBean());
|
||||
myFilter.setAuthenticationSuccessHandler(authenticationSuccessHandler());
|
||||
myFilter.setAuthenticationFailureHandler(authenticationFailureHandler());
|
||||
@@ -133,5 +132,5 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
RememberMeAuthenticationFilter myFilter = new RememberMeAuthenticationFilter(authenticationManagerBean(), tokenBasedRememberMeServices());
|
||||
return myFilter;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
package com.zyplayer.doc.manage.framework.exception;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.security.access.AccessDeniedException;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import org.springframework.web.servlet.handler.SimpleMappingExceptionResolver;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.zyplayer.doc.core.exception.ConfirmException;
|
||||
import com.zyplayer.doc.core.json.DocResponseJson;
|
||||
import com.zyplayer.doc.core.json.ResponseJson;
|
||||
|
||||
/**
|
||||
* 全局异常处理器
|
||||
*/
|
||||
@Component
|
||||
public class GlobalHandlerExceptionResolver extends SimpleMappingExceptionResolver {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(GlobalHandlerExceptionResolver.class);
|
||||
|
||||
@Override
|
||||
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
|
||||
LOGGER.error("---自定义异常处理---", ex);
|
||||
request.setAttribute("throwable", ex);
|
||||
ModelAndView mv = new ModelAndView();
|
||||
response.setStatus(HttpStatus.OK.value());// 设置状态码
|
||||
response.setContentType(MediaType.APPLICATION_JSON_VALUE);// 设置ContentType
|
||||
response.setCharacterEncoding("UTF-8");// 避免乱码
|
||||
response.setHeader("Cache-Control", "no-cache, must-revalidate");
|
||||
DocResponseJson<Object> responseJson = null;
|
||||
if (ex instanceof ConfirmException) {// 提示性异常
|
||||
responseJson = DocResponseJson.warn(ex.getMessage());
|
||||
} else if (ex instanceof AccessDeniedException) {// 没权限
|
||||
responseJson = DocResponseJson.warn("您没有权限访问本接口");
|
||||
} else {// 其他异常
|
||||
responseJson = DocResponseJson.warn("系统错误");
|
||||
}
|
||||
boolean isResponseBody = isResponseBody(handler);// 是否返回body
|
||||
// 返回页面或者返回内容处理
|
||||
if (!isResponseBody) {
|
||||
mv.addObject("errJson", responseJson);
|
||||
String customErrPage = (String) request.getAttribute("customErrPage");
|
||||
// 有定义过错误页面的直接返回自定义的错误页面
|
||||
if(StringUtils.isNotBlank(customErrPage)) {
|
||||
mv.setViewName(customErrPage);
|
||||
} else {// 否则返回默认的错误页面
|
||||
mv.setViewName("/statics/common/500.html");
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
String jsonStr = JSON.toJSONString(responseJson);
|
||||
response.getWriter().write(jsonStr);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return mv;
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果是HttpMessageNotReadableException 则获取错误字段
|
||||
* @param exception
|
||||
* @return
|
||||
*/
|
||||
public static String getExceptionField(String exception) {
|
||||
Pattern pattern = Pattern.compile("Unrecognized field \"(\\w*)[$\"]");
|
||||
Matcher matcher = pattern.matcher(exception);
|
||||
String field = "";
|
||||
if (matcher.find()) {
|
||||
field = matcher.group(1);
|
||||
} else {
|
||||
pattern = Pattern.compile("Field error in object '.+' on field '(\\w+)'");
|
||||
matcher = pattern.matcher(exception);
|
||||
if (matcher.find()) {
|
||||
field = matcher.group(1);
|
||||
}
|
||||
}
|
||||
return field;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否返回body
|
||||
* @author
|
||||
* @since 2017年5月11日
|
||||
* @param handler
|
||||
* @return
|
||||
*/
|
||||
private boolean isResponseBody(Object handler){
|
||||
if (handler instanceof HandlerMethod) {
|
||||
HandlerMethod mathod = (HandlerMethod) handler;
|
||||
ResponseBody body = mathod.getMethodAnnotation(ResponseBody.class);
|
||||
if(body == null){
|
||||
RestController restController = mathod.getMethod().getDeclaringClass().getAnnotation(RestController.class);
|
||||
if(restController == null){
|
||||
if(!mathod.getMethod().getReturnType().isAssignableFrom(ResponseJson.class)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
package com.zyplayer.doc.manage.repository.manage.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import java.util.Date;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018-12-05
|
||||
*/
|
||||
public class AuthInfo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键自增ID
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 权限名
|
||||
*/
|
||||
private String authName;
|
||||
|
||||
/**
|
||||
* 权限说明
|
||||
*/
|
||||
private String authDesc;
|
||||
|
||||
/**
|
||||
* 是否可编辑 0=否 1=是
|
||||
*/
|
||||
private Integer canEdit;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private Long createUid;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date creationTime;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
public String getAuthName() {
|
||||
return authName;
|
||||
}
|
||||
|
||||
public void setAuthName(String authName) {
|
||||
this.authName = authName;
|
||||
}
|
||||
public String getAuthDesc() {
|
||||
return authDesc;
|
||||
}
|
||||
|
||||
public void setAuthDesc(String authDesc) {
|
||||
this.authDesc = authDesc;
|
||||
}
|
||||
public Integer getCanEdit() {
|
||||
return canEdit;
|
||||
}
|
||||
|
||||
public void setCanEdit(Integer canEdit) {
|
||||
this.canEdit = canEdit;
|
||||
}
|
||||
public Long getCreateUid() {
|
||||
return createUid;
|
||||
}
|
||||
|
||||
public void setCreateUid(Long createUid) {
|
||||
this.createUid = createUid;
|
||||
}
|
||||
public Date getCreationTime() {
|
||||
return creationTime;
|
||||
}
|
||||
|
||||
public void setCreationTime(Date creationTime) {
|
||||
this.creationTime = creationTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "AuthInfo{" +
|
||||
"id=" + id +
|
||||
", authName=" + authName +
|
||||
", authDesc=" + authDesc +
|
||||
", canEdit=" + canEdit +
|
||||
", createUid=" + createUid +
|
||||
", creationTime=" + creationTime +
|
||||
"}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
package com.zyplayer.doc.manage.repository.manage.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import java.util.Date;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018-12-05
|
||||
*/
|
||||
public class UserAuth implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键自增ID
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 权限ID
|
||||
*/
|
||||
private Long authId;
|
||||
|
||||
/**
|
||||
* 创建用户ID
|
||||
*/
|
||||
private Long createUid;
|
||||
|
||||
/**
|
||||
* 更新用户ID
|
||||
*/
|
||||
private Long updateUid;
|
||||
|
||||
/**
|
||||
* 是否删除 0=未删除 1=已删除
|
||||
*/
|
||||
private Integer delFlag;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date creationTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
public Long getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(Long userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
public Long getAuthId() {
|
||||
return authId;
|
||||
}
|
||||
|
||||
public void setAuthId(Long authId) {
|
||||
this.authId = authId;
|
||||
}
|
||||
public Long getCreateUid() {
|
||||
return createUid;
|
||||
}
|
||||
|
||||
public void setCreateUid(Long createUid) {
|
||||
this.createUid = createUid;
|
||||
}
|
||||
public Long getUpdateUid() {
|
||||
return updateUid;
|
||||
}
|
||||
|
||||
public void setUpdateUid(Long updateUid) {
|
||||
this.updateUid = updateUid;
|
||||
}
|
||||
public Integer getDelFlag() {
|
||||
return delFlag;
|
||||
}
|
||||
|
||||
public void setDelFlag(Integer delFlag) {
|
||||
this.delFlag = delFlag;
|
||||
}
|
||||
public Date getCreationTime() {
|
||||
return creationTime;
|
||||
}
|
||||
|
||||
public void setCreationTime(Date creationTime) {
|
||||
this.creationTime = creationTime;
|
||||
}
|
||||
public Date getUpdateTime() {
|
||||
return updateTime;
|
||||
}
|
||||
|
||||
public void setUpdateTime(Date updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UserAuth{" +
|
||||
"id=" + id +
|
||||
", userId=" + userId +
|
||||
", authId=" + authId +
|
||||
", createUid=" + createUid +
|
||||
", updateUid=" + updateUid +
|
||||
", delFlag=" + delFlag +
|
||||
", creationTime=" + creationTime +
|
||||
", updateTime=" + updateTime +
|
||||
"}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
package com.zyplayer.doc.manage.repository.manage.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import java.util.Date;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018-12-05
|
||||
*/
|
||||
public class UserInfo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键自增ID
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户编号,用于登录等
|
||||
*/
|
||||
private String userNo;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 头像
|
||||
*/
|
||||
private String avatar;
|
||||
|
||||
/**
|
||||
* 是否删除 0=未删除 1=已删除
|
||||
*/
|
||||
private Integer delFlag;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private Long createUid;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date creationTime;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
public String getUserNo() {
|
||||
return userNo;
|
||||
}
|
||||
|
||||
public void setUserNo(String userNo) {
|
||||
this.userNo = userNo;
|
||||
}
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
public String getAvatar() {
|
||||
return avatar;
|
||||
}
|
||||
|
||||
public void setAvatar(String avatar) {
|
||||
this.avatar = avatar;
|
||||
}
|
||||
public Integer getDelFlag() {
|
||||
return delFlag;
|
||||
}
|
||||
|
||||
public void setDelFlag(Integer delFlag) {
|
||||
this.delFlag = delFlag;
|
||||
}
|
||||
public Long getCreateUid() {
|
||||
return createUid;
|
||||
}
|
||||
|
||||
public void setCreateUid(Long createUid) {
|
||||
this.createUid = createUid;
|
||||
}
|
||||
public Date getCreationTime() {
|
||||
return creationTime;
|
||||
}
|
||||
|
||||
public void setCreationTime(Date creationTime) {
|
||||
this.creationTime = creationTime;
|
||||
}
|
||||
public Date getUpdateTime() {
|
||||
return updateTime;
|
||||
}
|
||||
|
||||
public void setUpdateTime(Date updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UserInfo{" +
|
||||
"id=" + id +
|
||||
", userNo=" + userNo +
|
||||
", password=" + password +
|
||||
", userName=" + userName +
|
||||
", email=" + email +
|
||||
", avatar=" + avatar +
|
||||
", delFlag=" + delFlag +
|
||||
", createUid=" + createUid +
|
||||
", creationTime=" + creationTime +
|
||||
", updateTime=" + updateTime +
|
||||
"}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.zyplayer.doc.manage.repository.manage.mapper;
|
||||
|
||||
import com.zyplayer.doc.manage.repository.manage.entity.AuthInfo;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018-12-03
|
||||
*/
|
||||
public interface AuthInfoMapper extends BaseMapper<AuthInfo> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.zyplayer.doc.manage.repository.manage.mapper;
|
||||
|
||||
import com.zyplayer.doc.manage.repository.manage.entity.UserAuth;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018-12-03
|
||||
*/
|
||||
public interface UserAuthMapper extends BaseMapper<UserAuth> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.zyplayer.doc.manage.repository.manage.mapper;
|
||||
|
||||
import com.zyplayer.doc.manage.repository.manage.entity.UserInfo;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018-12-03
|
||||
*/
|
||||
public interface UserInfoMapper extends BaseMapper<UserInfo> {
|
||||
|
||||
}
|
||||
@@ -22,7 +22,8 @@ public class CodeGenerator {
|
||||
public static void main(String[] args) {
|
||||
|
||||
final String moduleName = "manage";
|
||||
final String[] tableName = { "zyplayer_storage" };
|
||||
final String[] tableName = { "zyplayer_storage", "auth_info", "user_auth", "user_info" };
|
||||
// final String[] tableName = { "zyplayer_storage" };
|
||||
|
||||
// 代码生成器
|
||||
AutoGenerator mpg = new AutoGenerator();
|
||||
@@ -34,6 +35,7 @@ public class CodeGenerator {
|
||||
gc.setOpen(false);
|
||||
gc.setDateType(DateType.ONLY_DATE);
|
||||
gc.setServiceName("%sService");
|
||||
gc.setControllerName("Generator%sController");
|
||||
mpg.setGlobalConfig(gc);
|
||||
|
||||
// 数据源配置
|
||||
@@ -42,14 +44,14 @@ public class CodeGenerator {
|
||||
// dsc.setSchemaName("public");
|
||||
dsc.setDriverName("com.mysql.jdbc.Driver");
|
||||
dsc.setUsername("root");
|
||||
dsc.setPassword("11111");
|
||||
dsc.setPassword("root");
|
||||
mpg.setDataSource(dsc);
|
||||
|
||||
// 包配置
|
||||
final PackageConfig pc = new PackageConfig();
|
||||
pc.setModuleName(null);
|
||||
pc.setParent("com.zyplayer.doc.manage");
|
||||
pc.setController("web");
|
||||
pc.setController("web.generator");
|
||||
pc.setEntity("repository.manage.entity");
|
||||
pc.setMapper("repository.manage.mapper");
|
||||
pc.setService("service.manage");
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.zyplayer.doc.manage.service.manage;
|
||||
|
||||
import com.zyplayer.doc.manage.repository.manage.entity.AuthInfo;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018-12-03
|
||||
*/
|
||||
public interface AuthInfoService extends IService<AuthInfo> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.zyplayer.doc.manage.service.manage;
|
||||
|
||||
import com.zyplayer.doc.manage.repository.manage.entity.UserAuth;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018-12-03
|
||||
*/
|
||||
public interface UserAuthService extends IService<UserAuth> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.zyplayer.doc.manage.service.manage;
|
||||
|
||||
import com.zyplayer.doc.manage.repository.manage.entity.UserInfo;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018-12-03
|
||||
*/
|
||||
public interface UserInfoService extends IService<UserInfo> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.zyplayer.doc.manage.service.manage.impl;
|
||||
|
||||
import com.zyplayer.doc.manage.repository.manage.entity.AuthInfo;
|
||||
import com.zyplayer.doc.manage.repository.manage.mapper.AuthInfoMapper;
|
||||
import com.zyplayer.doc.manage.service.manage.AuthInfoService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018-12-03
|
||||
*/
|
||||
@Service
|
||||
public class AuthInfoServiceImpl extends ServiceImpl<AuthInfoMapper, AuthInfo> implements AuthInfoService {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.zyplayer.doc.manage.service.manage.impl;
|
||||
|
||||
import com.zyplayer.doc.manage.repository.manage.entity.UserAuth;
|
||||
import com.zyplayer.doc.manage.repository.manage.mapper.UserAuthMapper;
|
||||
import com.zyplayer.doc.manage.service.manage.UserAuthService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018-12-03
|
||||
*/
|
||||
@Service
|
||||
public class UserAuthServiceImpl extends ServiceImpl<UserAuthMapper, UserAuth> implements UserAuthService {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.zyplayer.doc.manage.service.manage.impl;
|
||||
|
||||
import com.zyplayer.doc.manage.repository.manage.entity.UserInfo;
|
||||
import com.zyplayer.doc.manage.repository.manage.mapper.UserInfoMapper;
|
||||
import com.zyplayer.doc.manage.service.manage.UserInfoService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018-12-03
|
||||
*/
|
||||
@Service
|
||||
public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> implements UserInfoService {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.zyplayer.doc.manage.web.generator;
|
||||
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018-12-05
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/auth-info")
|
||||
public class GeneratorAuthInfoController {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.zyplayer.doc.manage.web.generator;
|
||||
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018-12-05
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/user-auth")
|
||||
public class GeneratorUserAuthController {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.zyplayer.doc.manage.web.generator;
|
||||
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018-12-05
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/user-info")
|
||||
public class GeneratorUserInfoController {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.zyplayer.doc.manage.web.generator;
|
||||
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018-12-05
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/zyplayer-storage")
|
||||
public class GeneratorZyplayerStorageController {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.zyplayer.doc.manage.web.manage;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.zyplayer.doc.core.json.DocResponseJson;
|
||||
import com.zyplayer.doc.core.json.ResponseJson;
|
||||
import com.zyplayer.doc.manage.framework.config.security.DocUserDetails;
|
||||
import com.zyplayer.doc.manage.framework.config.security.DocUserUtil;
|
||||
import com.zyplayer.doc.manage.repository.manage.entity.AuthInfo;
|
||||
import com.zyplayer.doc.manage.service.manage.AuthInfoService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/auth/info")
|
||||
@PreAuthorize("hasAuthority('AUTH_MANAGE')")
|
||||
public class AuthInfoController {
|
||||
|
||||
@Autowired
|
||||
AuthInfoService authInfoService;
|
||||
|
||||
@PostMapping("/list")
|
||||
public ResponseJson<Object> list() {
|
||||
List<AuthInfo> authList = authInfoService.list();
|
||||
return DocResponseJson.ok(authList);
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public ResponseJson<Object> delete(Long id) {
|
||||
AuthInfo authInfo = authInfoService.getById(id);
|
||||
if (authInfo == null || authInfo.getCanEdit() == 0) {
|
||||
return DocResponseJson.warn("该权限不允许删除");
|
||||
}
|
||||
authInfoService.removeById(id);
|
||||
return DocResponseJson.ok();
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public ResponseJson<Object> update(Long id, String authName, String authDesc) {
|
||||
AuthInfo authInfo = new AuthInfo();
|
||||
authInfo.setAuthDesc(authDesc);
|
||||
authInfo.setAuthName(authName);
|
||||
if (id != null && id > 0) {
|
||||
AuthInfo authInfoSel = authInfoService.getById(id);
|
||||
if (authInfoSel == null || authInfoSel.getCanEdit() == 0) {
|
||||
return DocResponseJson.warn("该权限不允许编辑");
|
||||
}
|
||||
authInfo.setId(id);
|
||||
authInfoService.updateById(authInfo);
|
||||
} else {
|
||||
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||
authInfo.setCreationTime(new Date());
|
||||
authInfo.setCreateUid(currentUser.getUserId());
|
||||
authInfoService.save(authInfo);
|
||||
}
|
||||
return DocResponseJson.ok();
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package com.zyplayer.doc.manage.web.manage;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
@Controller
|
||||
public class HelloController {
|
||||
|
||||
// @RequestMapping("/")
|
||||
// public String index() {
|
||||
// return "manage/index";
|
||||
// }
|
||||
//
|
||||
// @RequestMapping("/hello")
|
||||
// public String hello() {
|
||||
// return "manage/hello";
|
||||
// }
|
||||
//
|
||||
// @RequestMapping("/login")
|
||||
// public String login() {
|
||||
// return "statics/manage/hello.html";
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.zyplayer.doc.manage.web.manage;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.security.core.AuthenticationException;
|
||||
import org.springframework.security.web.WebAttributes;
|
||||
import org.springframework.security.web.savedrequest.HttpSessionRequestCache;
|
||||
import org.springframework.security.web.savedrequest.RequestCache;
|
||||
import org.springframework.security.web.savedrequest.SavedRequest;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import com.zyplayer.doc.core.json.DocResponseJson;
|
||||
|
||||
@RestController
|
||||
public class LoginController {
|
||||
private RequestCache requestCache = new HttpSessionRequestCache();
|
||||
|
||||
@GetMapping(value = "/login")
|
||||
public ModelAndView loginPage(HttpServletRequest request) {
|
||||
return new ModelAndView("/statics/manage/login.html");
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果是访问受限页面后,跳转到登录页的,则在targetUrl保存之前受限页面的路径,供页面调用
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/login/success")
|
||||
public DocResponseJson<String> loginSuccess(HttpServletRequest request, HttpServletResponse response) {
|
||||
SavedRequest savedRequest = requestCache.getRequest(request, response);
|
||||
String targetUrl = null;
|
||||
if (savedRequest != null) {
|
||||
targetUrl = savedRequest.getRedirectUrl();
|
||||
}
|
||||
if (StringUtils.isBlank(targetUrl)) {
|
||||
targetUrl = "/";
|
||||
}
|
||||
return DocResponseJson.ok(targetUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取异常信息返回给页面
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/login/failure")
|
||||
public DocResponseJson<String> loginFailure(HttpServletRequest request, HttpServletResponse response) {
|
||||
AuthenticationException ae = (AuthenticationException) request.getSession().getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);
|
||||
return DocResponseJson.warn(ae.getMessage());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.zyplayer.doc.manage.web.manage;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.zyplayer.doc.core.json.DocResponseJson;
|
||||
import com.zyplayer.doc.core.json.ResponseJson;
|
||||
import com.zyplayer.doc.manage.framework.config.security.DocUserDetails;
|
||||
import com.zyplayer.doc.manage.framework.config.security.DocUserUtil;
|
||||
import com.zyplayer.doc.manage.repository.manage.entity.AuthInfo;
|
||||
import com.zyplayer.doc.manage.repository.manage.entity.UserAuth;
|
||||
import com.zyplayer.doc.manage.service.manage.AuthInfoService;
|
||||
import com.zyplayer.doc.manage.service.manage.UserAuthService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/user/auth")
|
||||
@PreAuthorize("hasAuthority('AUTH_ASSIGN')")
|
||||
public class UserAuthController {
|
||||
|
||||
@Autowired
|
||||
AuthInfoService authInfoService;
|
||||
@Autowired
|
||||
UserAuthService userAuthService;
|
||||
|
||||
@PostMapping("/list")
|
||||
public ResponseJson<Object> list(Long userId) {
|
||||
QueryWrapper<UserAuth> userAuthWrapper = new QueryWrapper<>();
|
||||
userAuthWrapper.eq("user_id", userId);
|
||||
List<UserAuth> userAuthList = userAuthService.list(userAuthWrapper);
|
||||
if (userAuthList == null || userAuthList.isEmpty()) {
|
||||
return DocResponseJson.ok();
|
||||
}
|
||||
QueryWrapper<AuthInfo> authQueryWrapper = new QueryWrapper<>();
|
||||
authQueryWrapper.in("id", userAuthList.stream().collect(Collectors.mapping(UserAuth::getAuthId, Collectors.toList())));
|
||||
List<AuthInfo> authList = authInfoService.list(authQueryWrapper);
|
||||
return DocResponseJson.ok(authList);
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public ResponseJson<Object> delete(Long id) {
|
||||
userAuthService.removeById(id);
|
||||
return DocResponseJson.ok();
|
||||
}
|
||||
|
||||
@PostMapping("/insert")
|
||||
public ResponseJson<Object> insert(Long id, Long userId, Long authId) {
|
||||
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||
UserAuth userAuth = new UserAuth();
|
||||
userAuth.setAuthId(authId);
|
||||
userAuth.setUserId(userId);
|
||||
if (id != null && id > 0) {
|
||||
userAuth.setId(id);
|
||||
userAuthService.updateById(userAuth);
|
||||
} else {
|
||||
userAuth.setCreationTime(new Date());
|
||||
userAuth.setCreateUid(currentUser.getUserId());
|
||||
userAuthService.save(userAuth);
|
||||
}
|
||||
return DocResponseJson.ok();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,123 +0,0 @@
|
||||
package com.zyplayer.doc.manage.web.manage;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.security.core.AuthenticationException;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.web.WebAttributes;
|
||||
import org.springframework.security.web.savedrequest.HttpSessionRequestCache;
|
||||
import org.springframework.security.web.savedrequest.RequestCache;
|
||||
import org.springframework.security.web.savedrequest.SavedRequest;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import com.zyplayer.doc.manage.framework.config.security.MyUserDetails;
|
||||
import com.zyplayer.doc.manage.framework.config.security.UserUtil;
|
||||
|
||||
@RestController
|
||||
public class UserController {
|
||||
private RequestCache requestCache = new HttpSessionRequestCache();
|
||||
|
||||
@RequestMapping(value = "/login_page", method = RequestMethod.GET)
|
||||
public ModelAndView loginPage(HttpServletRequest request) {
|
||||
if (true) {
|
||||
return new ModelAndView("/login/ajax");
|
||||
} else {
|
||||
return new ModelAndView("login.html");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果是访问受限页面后,跳转到登录页的,则在targetUrl保存之前受限页面的路径,供页面调用
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/login/success", method = RequestMethod.GET)
|
||||
public Map<String, Object> loginSuccess(HttpServletRequest request, HttpServletResponse response) {
|
||||
SavedRequest savedRequest = requestCache.getRequest(request, response);
|
||||
String targetUrl = null;
|
||||
if (savedRequest != null) {
|
||||
targetUrl = savedRequest.getRedirectUrl();
|
||||
}
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
result.put("success", true);
|
||||
result.put("targetUrl", targetUrl);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取异常信息返回给页面
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/login/failure", method = RequestMethod.GET)
|
||||
public Map<String, Object> loginFailure(HttpServletRequest request, HttpServletResponse response) {
|
||||
AuthenticationException ae = (AuthenticationException) request.getSession().getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
result.put("success", false);
|
||||
result.put("message", ae.getMessage());
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/login/ajax", method = RequestMethod.GET)
|
||||
public Map<String, Object> loginAjax() {
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
result.put("success", false);
|
||||
result.put("message", "you need login!");
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/security/user", method = RequestMethod.GET)
|
||||
public Map<String, Object> securityUser(HttpServletRequest request) {
|
||||
MyUserDetails user = UserUtil.getCurrentUser();
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
StringBuilder userRole = new StringBuilder();
|
||||
if (user != null) {
|
||||
result.put("userId", user.getUserId());
|
||||
result.put("userName", user.getUsername());
|
||||
Collection<? extends GrantedAuthority> roleLst = user.getAuthorities();
|
||||
for (GrantedAuthority sga : roleLst) {
|
||||
userRole.append(sga.toString() + "; ");
|
||||
}
|
||||
}
|
||||
result.put("userRole", userRole.toString());
|
||||
result.put("message", "This message is only visible to the user");
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/security/admin", method = RequestMethod.GET)
|
||||
public Map<String, Object> securityAdmin(HttpServletRequest request) {
|
||||
MyUserDetails user = UserUtil.getCurrentUser();
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
StringBuilder userRole = new StringBuilder();
|
||||
if (user != null) {
|
||||
result.put("userId", user.getUserId());
|
||||
result.put("userName", user.getUsername());
|
||||
Collection<? extends GrantedAuthority> roleLst = user.getAuthorities();
|
||||
for (GrantedAuthority sga : roleLst) {
|
||||
userRole.append(sga.toString() + "; ");
|
||||
}
|
||||
}
|
||||
result.put("userRole", userRole.toString());
|
||||
result.put("message", "This message is only visible to the admin");
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/user/account", method = RequestMethod.GET)
|
||||
public Map<String, Object> getUserAcctunt(HttpServletRequest request) {
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
result.put("message", "需要进行完整认证的请求(不是通过Remember-me功能进行的认证)");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.zyplayer.doc.manage.web.manage;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.zyplayer.doc.core.json.DocResponseJson;
|
||||
import com.zyplayer.doc.core.json.ResponseJson;
|
||||
import com.zyplayer.doc.manage.framework.config.security.DocUserDetails;
|
||||
import com.zyplayer.doc.manage.framework.config.security.DocUserUtil;
|
||||
import com.zyplayer.doc.manage.repository.manage.entity.UserInfo;
|
||||
import com.zyplayer.doc.manage.service.manage.UserInfoService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/user/info")
|
||||
@PreAuthorize("hasAuthority('USER_MANAGE')")
|
||||
public class UserInfoController {
|
||||
|
||||
@Autowired
|
||||
UserInfoService userInfoService;
|
||||
|
||||
@PostMapping("/list")
|
||||
public ResponseJson<Object> list(String userName) {
|
||||
QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
|
||||
if (StringUtils.isNotBlank(userName)) {
|
||||
queryWrapper.like("user_name", userName);
|
||||
}
|
||||
List<UserInfo> userInfoList = userInfoService.list(queryWrapper);
|
||||
return DocResponseJson.ok(userInfoList);
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public ResponseJson<Object> delete(Long id) {
|
||||
UserInfo userInfo = new UserInfo();
|
||||
userInfo.setId(id);
|
||||
userInfo.setDelFlag(1);
|
||||
userInfo.setUpdateTime(new Date());
|
||||
userInfoService.updateById(userInfo);
|
||||
return DocResponseJson.ok();
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public ResponseJson<Object> update(UserInfo userInfo) {
|
||||
if (userInfo.getId() != null && userInfo.getId() > 0) {
|
||||
userInfo.setUpdateTime(new Date());
|
||||
userInfoService.updateById(userInfo);
|
||||
} else {
|
||||
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||
userInfo.setCreationTime(new Date());
|
||||
userInfo.setCreateUid(currentUser.getUserId());
|
||||
userInfoService.save(userInfo);
|
||||
}
|
||||
return DocResponseJson.ok();
|
||||
}
|
||||
}
|
||||
@@ -6,16 +6,8 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.zyplayer.doc.manage.repository.manage.mapper.ZyplayerStorageMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018-11-27
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/zyplayer-storage")
|
||||
@RequestMapping("/zyplayer/storage")
|
||||
public class ZyplayerStorageController {
|
||||
|
||||
@Autowired
|
||||
|
||||
Reference in New Issue
Block a user