Commit f1fdc4b3 by zzrdark

1.渠道号

2.跨域等
3.认证问题
parent bde8517c
......@@ -24,4 +24,6 @@ public class JwtToken implements Serializable {
private String scope;
private String jti;
private String token;
}
package com.mx.cneeds.common.vo;
import lombok.Data;
/**
* @ClassName DeviceChannelVo
* @Author zzrdark
* @Date 2020-03-05 14:46
* @Description TODO
**/
@Data
public class DeviceChannelVo {
/**
* 渠道号
*/
private String channelNums;
/**
* 提示信息
*/
private String channelNumsMessage;
/**
* 名单规则
*/
private Integer channelRules;
public DeviceChannelVo(String channelNums, String channelNumsMessage, Integer channelRules) {
this.channelNums = channelNums;
this.channelNumsMessage = channelNumsMessage;
this.channelRules = channelRules;
}
public DeviceChannelVo() {
}
}
package com.mx.cneeds.common.vo;
import lombok.Data;
/**
* @ClassName UserInfoVo
* @Author zzrdark
* @Date 2020-01-19 17:07
* @Description TODO
**/
@Data
public class UserInfoVo {
private String roles;
private String name;
private String avatar;
private String introduction;
}
......@@ -43,5 +43,10 @@
<version>${commons.io.version}</version>
</dependency>
<dependency>
<groupId>com.mx.cneeds</groupId>
<artifactId>cneeds-common-pojo</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -19,7 +19,7 @@ import javax.servlet.http.HttpServletRequest;
**/
@Configuration
@Slf4j
public class FeignConfig implements RequestInterceptor {
public class FeignInterceptor implements RequestInterceptor {
@Override
public void apply(RequestTemplate requestTemplate) {
......
......@@ -18,7 +18,9 @@ public class OAuth2ResourceServer extends ResourceServerConfigurerAdapter {
@Override
public void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/user/login")
.antMatchers("/user/login",
"/device/getChannel_nums",
"/statics/**")
.permitAll()
// 开启认证
.anyRequest()
......
/**
* Copyright (c) 2016-2019 人人开源 All rights reserved.
*
* https://www.renren.io
*
* 版权所有,侵权必究!
*/
package com.mx.cneeds.server.datashow.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* WebMvc配置
*
* @author Mark sunlightcs@gmail.com
*/
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/statics/**").addResourceLocations("classpath:/statics/");
}
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")
.allowCredentials(true)
.maxAge(3600)
.allowedHeaders("*");
}
}
\ No newline at end of file
package com.mx.cneeds.server.datashow.filter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* @ClassName CrossFilter
* @Author zzrdark
* @Date 2020-01-17 19:22
* @Description TODO
**/
@WebFilter(filterName = "CorsFilter")
@Configuration
@Slf4j
public class CrossFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
log.info(httpServletRequest.getRequestURL().toString());
// log.info(httpServletRequest.getHeader("Access-Control-Allow-Origin"));
HttpServletResponse httpResponse = (HttpServletResponse) response;
httpResponse.setHeader("Access-Control-Allow-Origin", "*");
httpResponse.setHeader("Access-Control-Allow-Methods", "*");
httpResponse.setHeader("Access-Control-Max-Age", "3600");
httpResponse.setHeader("Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept, Connection, User-Agent, Cookie, Authorization");
httpResponse.setHeader("Access-Control-Allow-Credentials", "true");
// httpResponse.setHeader("Content-type", "application/json");
httpResponse.setHeader("Cache-Control", "no-cache, must-revalidate");
filterChain.doFilter(request, httpResponse);
}
@Override
public void destroy() {
}
}
package com.mx.cneeds.server.datashow.web.device;
import com.mx.cneeds.common.result.R;
import com.mx.cneeds.common.vo.DeviceChannelVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @ClassName DeviceController
* @Author zzrdark
* @Date 2020-03-05 14:42
* @Description TODO
**/
@RestController
@Slf4j
@RequestMapping("/device")
public class DeviceController {
@GetMapping("/getChannel_nums")
public R getChannel_nums(String imei){
DeviceChannelVo channelVo = new DeviceChannelVo("123456,112233,654321", "提示的信息", 0);
return new R().put("data",channelVo);
}
}
package com.mx.cneeds.server.datashow.web.user;
import com.mx.cneeds.common.result.R;
import com.mx.cneeds.common.vo.UserInfoVo;
import com.mx.cneeds.server.datashow.client.AuthorizationClient;
import com.mx.cneeds.common.dto.JwtToken;
import lombok.extern.slf4j.Slf4j;
......@@ -24,11 +26,31 @@ public class UserController {
@Autowired
private AuthorizationClient authenticatorClient;
@GetMapping("/login")
public JwtToken login(String username, String password){
/**
* 登陆接口
* @param username
* @param password
* @return
*/
@RequestMapping("/login")
public R login(String username, String password){
JwtToken token = authenticatorClient.getToken("password", username, password, "all");
token.setToken(token.getTokenType()+" "+token.getAccessToken());
log.info(token.toString());
return token;
return new R().put("data",token);
}
@RequestMapping("/info")
public UserInfoVo getInfo(){
UserInfoVo userInfoVo = new UserInfoVo();
log.info("getInfo");
userInfoVo.setName("admin");
userInfoVo.setIntroduction("manager");
userInfoVo.setRoles("admin");
userInfoVo.setAvatar("avatar");
return userInfoVo;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment