增加消息模块 修改整体权限包结构 解决与gateway冲突
parent
2c94d18261
commit
2c515071bf
@ -1,46 +0,0 @@
|
||||
### Java template
|
||||
# Compiled class file
|
||||
*.class
|
||||
|
||||
# Log file
|
||||
*.log
|
||||
|
||||
# BlueJ files
|
||||
*.ctxt
|
||||
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.nar
|
||||
*.ear
|
||||
*.zip
|
||||
*.tar.gz
|
||||
*.rar
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
|
||||
### Maven template
|
||||
target/
|
||||
pom.xml.tag
|
||||
pom.xml.releaseBackup
|
||||
pom.xml.versionsBackup
|
||||
pom.xml.next
|
||||
release.properties
|
||||
dependency-reduced-pom.xml
|
||||
buildNumber.properties
|
||||
.mvn/timing.properties
|
||||
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
|
||||
.mvn/wrapper/maven-wrapper.jar
|
||||
|
||||
### Example user template template
|
||||
### Example user template
|
||||
|
||||
# IntelliJ project files
|
||||
.idea
|
||||
*.iml
|
||||
out
|
||||
gen
|
@ -0,0 +1,64 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<artifactId>ad-platform</artifactId>
|
||||
<groupId>com.baiye</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<groupId>com.baiye</groupId>
|
||||
<artifactId>ad-platform-common-auth</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>ad-platform-common-auth</name>
|
||||
<description>ad-platform-common-auth</description>
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.baiye</groupId>
|
||||
<artifactId>ad-platform-common-core</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.baiye</groupId>
|
||||
<artifactId>ad-platform-pojo</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<!-- jwt -->
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-impl</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-jackson</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.whvcse</groupId>
|
||||
<artifactId>easy-captcha</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring boot websocket -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-websocket</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
||||
</project>
|
@ -0,0 +1,35 @@
|
||||
package com.baiye.config;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @date : 2022/1/11
|
||||
*/
|
||||
public class CustomAuthorityDeserializer extends JsonDeserializer {
|
||||
@Override
|
||||
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
ObjectMapper mapper = (ObjectMapper) p.getCodec();
|
||||
JsonNode jsonNode = mapper.readTree(p);
|
||||
LinkedList<GrantedAuthority> grantedAuthorities = new LinkedList<>();
|
||||
Iterator<JsonNode> elements = jsonNode.elements();
|
||||
while (elements.hasNext()) {
|
||||
JsonNode next = elements.next();
|
||||
JsonNode authority = next.get("authority");
|
||||
//将得到的值放入链表 最终返回该链表
|
||||
grantedAuthorities.add(new SimpleGrantedAuthority(authority.asText()));
|
||||
}
|
||||
return grantedAuthorities;
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package com.baiye.feign;
|
||||
|
||||
import com.baiye.model.dto.UserDto;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @date : 2022/1/11
|
||||
*/
|
||||
@FeignClient(contextId = "remoteUserService", value = "ad-platform-management")
|
||||
public interface RemoteUserService {
|
||||
|
||||
/**
|
||||
* 用户名查找名称
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/api/users/info/findByName")
|
||||
UserDto findByName(@RequestParam("username") String username);
|
||||
|
||||
/**
|
||||
* 查找组长
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/api/users/info/deptIds")
|
||||
List<Long> getDeptIds(@RequestBody UserDto user);
|
||||
|
||||
/**
|
||||
* 账号权限
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/api/roles/user/authority")
|
||||
Set<String> mapToGrantedAuthorities(@RequestBody UserDto user);
|
||||
}
|
@ -1,19 +1,4 @@
|
||||
/*
|
||||
* Copyright 2019-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version loginCode.length.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-loginCode.length.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.baiye.modules.security.config.bean;
|
||||
package com.baiye.properties.bean;
|
||||
|
||||
import com.baiye.exception.BadConfigurationException;
|
||||
import com.wf.captcha.*;
|
@ -0,0 +1,49 @@
|
||||
package com.baiye.security;
|
||||
|
||||
import com.baiye.constant.SecurityConstants;
|
||||
import com.baiye.security.TokenProvider;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.http.server.ServerHttpRequest;
|
||||
import org.springframework.http.server.ServerHttpResponse;
|
||||
import org.springframework.http.server.ServletServerHttpRequest;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.server.HandshakeInterceptor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @date : 2022/1/12
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
class PrincipalHandshakeHandler implements HandshakeInterceptor {
|
||||
private final TokenProvider tokenProvider;
|
||||
|
||||
|
||||
@Override
|
||||
public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String, Object> attributes) throws Exception {
|
||||
ServletServerHttpRequest serverHttpRequest = (ServletServerHttpRequest) request;
|
||||
|
||||
//获取参数
|
||||
String token = serverHttpRequest.getServletRequest().getParameter(SecurityConstants.AUTHORIZATION);
|
||||
attributes.put("token", token);
|
||||
if (StringUtils.isNotBlank(token)) {
|
||||
Authentication authentication = tokenProvider.getAuthentication(token);
|
||||
SecurityContextHolder.getContext().setAuthentication(authentication);
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Exception exception) {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package com.baiye.util;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @date : 2022/1/11
|
||||
*/
|
||||
public class AdUser extends User {
|
||||
|
||||
private static final long serialVersionUID = -66600042157219036L;
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
@Getter
|
||||
private final Integer id;
|
||||
|
||||
/**
|
||||
* 部门ID
|
||||
*/
|
||||
@Getter
|
||||
private final Integer deptId;
|
||||
|
||||
|
||||
/**
|
||||
* Construct the <code>User</code> with the details required by
|
||||
* {@link DaoAuthenticationProvider}.
|
||||
* @param id 用户ID
|
||||
* @param deptId 部门ID
|
||||
* @param username the username presented to the
|
||||
* <code>DaoAuthenticationProvider</code>
|
||||
* @param password the password that should be presented to the
|
||||
* <code>DaoAuthenticationProvider</code>
|
||||
* @param enabled set to <code>true</code> if the user is enabled
|
||||
* @param accountNonExpired set to <code>true</code> if the account has not expired
|
||||
* @param credentialsNonExpired set to <code>true</code> if the credentials have not
|
||||
* expired
|
||||
* @param accountNonLocked set to <code>true</code> if the account is not locked
|
||||
* @param authorities the authorities that should be granted to the caller if they
|
||||
* presented the correct username and password and the user is enabled. Not null.
|
||||
* @throws IllegalArgumentException if a <code>null</code> value was passed either as
|
||||
* a parameter or as an element in the <code>GrantedAuthority</code> collection
|
||||
*/
|
||||
public AdUser(Integer id, Integer deptId, String username, String password, boolean enabled,
|
||||
boolean accountNonExpired, boolean credentialsNonExpired, boolean accountNonLocked,
|
||||
Collection<? extends GrantedAuthority> authorities) {
|
||||
super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities);
|
||||
this.id = id;
|
||||
this.deptId = deptId;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2020 pig4cloud Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.baiye.annotation;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 服务调用不鉴权注解
|
||||
*
|
||||
* @author lengleng
|
||||
* @date 2020-06-14
|
||||
*/
|
||||
@Target({ ElementType.METHOD, ElementType.TYPE })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface Inner {
|
||||
|
||||
/**
|
||||
* 是否AOP统一处理
|
||||
* @return false, true
|
||||
*/
|
||||
boolean value() default true;
|
||||
|
||||
/**
|
||||
* 需要特殊判空的字段(预留)
|
||||
* @return {}
|
||||
*/
|
||||
String[] field() default {};
|
||||
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package com.baiye.http;
|
||||
|
||||
import cn.hutool.http.HttpStatus;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import lombok.Getter;
|
@ -1,4 +1,4 @@
|
||||
package com.baiye.filter;
|
||||
package com.baiye.socket.filter;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue