Commit f173a2a5 by yw

项目初始化

parent 88f36356
......@@ -50,6 +50,12 @@
<artifactId>datax-common-redis</artifactId>
<version>${app.version}</version>
</dependency>
<dependency>
<groupId>cn.datax</groupId>
<artifactId>system-service-api</artifactId>
<version>${app.version}</version>
</dependency>
</dependencies>
<build>
......
......@@ -9,6 +9,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.ComponentScan;
@EnableDiscoveryClient
@EnableCircuitBreaker
......@@ -17,6 +18,7 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
@EnableDataMybatis
@EnableDataRedis
@EnableFeignClients
@ComponentScan({"cn.datax"})
@SpringBootApplication
public class DataxAuthApplication {
......
package cn.datax.auth.service;
import cn.datax.common.core.R;
import cn.datax.service.system.api.entity.UserEntity;
import cn.datax.service.system.api.feign.UserServiceFeign;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
......@@ -12,15 +18,26 @@ import org.springframework.stereotype.Service;
import java.util.HashSet;
import java.util.Set;
@Slf4j
@Service
public class DataUserDetailService implements UserDetailsService {
@Autowired
private UserServiceFeign userServiceFeign;
@Override
public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
//远程获取用户
R result = userServiceFeign.getUserByUsername(s);
log.info(JSON.toJSONString(result));
if (!StrUtil.equals("admin", s)) {
throw new UsernameNotFoundException(s);
throw new UsernameNotFoundException(StrUtil.format("{}用户不存在", s));
}
// if(result == null || result.getData() == null){
// throw new UsernameNotFoundException(StrUtil.format("{}用户不存在", s));
// }
// UserEntity userEntity = (UserEntity) result.getData();
Set<GrantedAuthority> grantedAuthorities = new HashSet<>();
// 可用性 :true:可用 false:不可用
boolean enabled = true;
......
package cn.datax.gateway.filter;
import cn.datax.gateway.config.SwaggerProvider;
import org.apache.commons.lang3.StringUtils;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
@Component
public class SwaggerHeaderFilter extends AbstractGatewayFilterFactory {
private static final String HEADER_NAME = "X-Forwarded-Prefix";
@Override
public GatewayFilter apply(Object config) {
return (exchange, chain) -> {
ServerHttpRequest request = exchange.getRequest();
String path = request.getURI().getPath();
if (!StringUtils.endsWithIgnoreCase(path, SwaggerProvider.API_URI)) {
return chain.filter(exchange);
}
String basePath = path.substring(0, path.lastIndexOf(SwaggerProvider.API_URI));
ServerHttpRequest newRequest = request.mutate().header(HEADER_NAME, basePath).build();
ServerWebExchange newExchange = exchange.mutate().request(newRequest).build();
return chain.filter(newExchange);
};
}
}
package cn.datax.service.system.api.feign;
import cn.datax.common.core.R;
import cn.datax.service.system.api.feign.factory.UserServiceFeignFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@FeignClient(contextId = "userServiceFeign", value = "datax-service-system", fallbackFactory = UserServiceFeignFallbackFactory.class)
public interface UserServiceFeign {
@GetMapping("/users/username/{username}")
R getUserByUsername(@PathVariable("username") String username);
}
package cn.datax.service.system.api.feign.factory;
import cn.datax.service.system.api.feign.UserServiceFeign;
import cn.datax.service.system.api.feign.fallback.UserServiceFeignFallbackImpl;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;
@Component
public class UserServiceFeignFallbackFactory implements FallbackFactory<UserServiceFeign> {
@Override
public UserServiceFeign create(Throwable throwable) {
UserServiceFeignFallbackImpl userServiceFeignFallbackImpl = new UserServiceFeignFallbackImpl();
userServiceFeignFallbackImpl.setCause(throwable);
return userServiceFeignFallbackImpl;
}
}
package cn.datax.service.system.api.feign.fallback;
import cn.datax.common.core.R;
import cn.datax.service.system.api.feign.UserServiceFeign;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@Slf4j
@Component
public class UserServiceFeignFallbackImpl implements UserServiceFeign {
@Setter
private Throwable cause;
@Override
public R getUserByUsername(String username) {
log.error("feign 获取用户信息失败", cause);
return null;
}
}
......@@ -10,6 +10,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.ComponentScan;
@EnableDataAuthExceptionHandler
@EnableDataServerProtect
......@@ -19,6 +20,7 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
@EnableDiscoveryClient
@EnableCircuitBreaker
@EnableFeignClients
@ComponentScan({"cn.datax"})
@SpringBootApplication
public class DataxSystemApplication {
......
......@@ -50,6 +50,15 @@ public class UserController extends BaseController {
return R.ok().setData(userMapper.toVO(userEntity));
}
@ApiOperation(value = "获取用户详细信息", notes = "根据url的username来获取用户详细信息")
@ApiImplicitParam(name = "username", value = "用户名", required = true, dataType = "String", paramType = "path")
@GetMapping("/username/{username}")
public R getUserByUsername(@PathVariable String username) {
UserEntity userEntity = userService.getOne(Wrappers.<UserEntity>query()
.lambda().eq(UserEntity::getUsername, username));
return R.ok().setData(userEntity);
}
@ApiOperation(value = "用户分页查询", notes = "")
@ApiImplicitParams({
@ApiImplicitParam(name = "pageNum", value = "当前页码", required = true, dataType = "int", example = "1"),
......
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