Showing
11 changed files
with
102 additions
and
14 deletions
| @@ -5,7 +5,7 @@ | @@ -5,7 +5,7 @@ | ||
| 5 | <parent> | 5 | <parent> |
| 6 | <artifactId>begete</artifactId> | 6 | <artifactId>begete</artifactId> |
| 7 | <groupId>com.begete</groupId> | 7 | <groupId>com.begete</groupId> |
| 8 | - <version>3.3.0</version> | 8 | + <version>1.0.1</version> |
| 9 | </parent> | 9 | </parent> |
| 10 | <modelVersion>4.0.0</modelVersion> | 10 | <modelVersion>4.0.0</modelVersion> |
| 11 | <packaging>jar</packaging> | 11 | <packaging>jar</packaging> |
| @@ -5,7 +5,7 @@ | @@ -5,7 +5,7 @@ | ||
| 5 | <parent> | 5 | <parent> |
| 6 | <artifactId>begete</artifactId> | 6 | <artifactId>begete</artifactId> |
| 7 | <groupId>com.begete</groupId> | 7 | <groupId>com.begete</groupId> |
| 8 | - <version>3.3.0</version> | 8 | + <version>1.0.1</version> |
| 9 | </parent> | 9 | </parent> |
| 10 | <modelVersion>4.0.0</modelVersion> | 10 | <modelVersion>4.0.0</modelVersion> |
| 11 | 11 |
| @@ -5,7 +5,7 @@ | @@ -5,7 +5,7 @@ | ||
| 5 | <parent> | 5 | <parent> |
| 6 | <artifactId>begete</artifactId> | 6 | <artifactId>begete</artifactId> |
| 7 | <groupId>com.begete</groupId> | 7 | <groupId>com.begete</groupId> |
| 8 | - <version>3.3.0</version> | 8 | + <version>1.0.1</version> |
| 9 | </parent> | 9 | </parent> |
| 10 | <modelVersion>4.0.0</modelVersion> | 10 | <modelVersion>4.0.0</modelVersion> |
| 11 | 11 |
| 1 | package com.begete.framework.config; | 1 | package com.begete.framework.config; |
| 2 | 2 | ||
| 3 | +import com.begete.framework.config.properties.PermissionProperties; | ||
| 3 | import org.springframework.beans.factory.annotation.Autowired; | 4 | import org.springframework.beans.factory.annotation.Autowired; |
| 4 | import org.springframework.context.annotation.Bean; | 5 | import org.springframework.context.annotation.Bean; |
| 5 | import org.springframework.http.HttpMethod; | 6 | import org.springframework.http.HttpMethod; |
| @@ -8,6 +9,7 @@ import org.springframework.security.config.annotation.authentication.builders.Au | @@ -8,6 +9,7 @@ import org.springframework.security.config.annotation.authentication.builders.Au | ||
| 8 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; | 9 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; |
| 9 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; | 10 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; |
| 10 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; | 11 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; |
| 12 | +import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer; | ||
| 11 | import org.springframework.security.config.http.SessionCreationPolicy; | 13 | import org.springframework.security.config.http.SessionCreationPolicy; |
| 12 | import org.springframework.security.core.userdetails.UserDetailsService; | 14 | import org.springframework.security.core.userdetails.UserDetailsService; |
| 13 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | 15 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; |
| @@ -18,6 +20,9 @@ import com.begete.framework.security.filter.JwtAuthenticationTokenFilter; | @@ -18,6 +20,9 @@ import com.begete.framework.security.filter.JwtAuthenticationTokenFilter; | ||
| 18 | import com.begete.framework.security.handle.AuthenticationEntryPointImpl; | 20 | import com.begete.framework.security.handle.AuthenticationEntryPointImpl; |
| 19 | import com.begete.framework.security.handle.LogoutSuccessHandlerImpl; | 21 | import com.begete.framework.security.handle.LogoutSuccessHandlerImpl; |
| 20 | 22 | ||
| 23 | +import javax.annotation.Resource; | ||
| 24 | +import java.util.List; | ||
| 25 | + | ||
| 21 | /** | 26 | /** |
| 22 | * spring security配置 | 27 | * spring security配置 |
| 23 | * | 28 | * |
| @@ -55,6 +60,9 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter | @@ -55,6 +60,9 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter | ||
| 55 | */ | 60 | */ |
| 56 | @Autowired | 61 | @Autowired |
| 57 | private CorsFilter corsFilter; | 62 | private CorsFilter corsFilter; |
| 63 | + | ||
| 64 | + @Resource | ||
| 65 | + private PermissionProperties permissionProperties; | ||
| 58 | 66 | ||
| 59 | /** | 67 | /** |
| 60 | * 解决 无法直接注入 AuthenticationManager | 68 | * 解决 无法直接注入 AuthenticationManager |
| @@ -87,7 +95,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter | @@ -87,7 +95,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter | ||
| 87 | @Override | 95 | @Override |
| 88 | protected void configure(HttpSecurity httpSecurity) throws Exception | 96 | protected void configure(HttpSecurity httpSecurity) throws Exception |
| 89 | { | 97 | { |
| 90 | - httpSecurity | 98 | + ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry expressionInterceptUrlRegistry = httpSecurity |
| 91 | // CSRF禁用,因为不使用session | 99 | // CSRF禁用,因为不使用session |
| 92 | .csrf().disable() | 100 | .csrf().disable() |
| 93 | // 认证失败处理类 | 101 | // 认证失败处理类 |
| @@ -104,7 +112,9 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter | @@ -104,7 +112,9 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter | ||
| 104 | "/**/*.html", | 112 | "/**/*.html", |
| 105 | "/**/*.css", | 113 | "/**/*.css", |
| 106 | "/**/*.js" | 114 | "/**/*.js" |
| 107 | - ).permitAll() | 115 | + ).permitAll(); |
| 116 | + | ||
| 117 | + expressionInterceptUrlRegistry | ||
| 108 | .antMatchers("/profile/**").anonymous() | 118 | .antMatchers("/profile/**").anonymous() |
| 109 | .antMatchers("/common/download**").anonymous() | 119 | .antMatchers("/common/download**").anonymous() |
| 110 | .antMatchers("/common/download/resource**").anonymous() | 120 | .antMatchers("/common/download/resource**").anonymous() |
| @@ -112,9 +122,14 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter | @@ -112,9 +122,14 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter | ||
| 112 | .antMatchers("/swagger-resources/**").anonymous() | 122 | .antMatchers("/swagger-resources/**").anonymous() |
| 113 | .antMatchers("/webjars/**").anonymous() | 123 | .antMatchers("/webjars/**").anonymous() |
| 114 | .antMatchers("/*/api-docs").anonymous() | 124 | .antMatchers("/*/api-docs").anonymous() |
| 115 | - .antMatchers("/druid/**").anonymous() | 125 | + .antMatchers("/druid/**").anonymous(); |
| 126 | + | ||
| 127 | + List<String> excludeUrls = permissionProperties.getExcludeUrls(); | ||
| 128 | + if(excludeUrls != null) | ||
| 129 | + excludeUrls.stream().forEach(e -> expressionInterceptUrlRegistry.antMatchers(e).anonymous()); | ||
| 130 | + | ||
| 116 | // 除上面外的所有请求全部需要鉴权认证 | 131 | // 除上面外的所有请求全部需要鉴权认证 |
| 117 | - .anyRequest().authenticated() | 132 | + expressionInterceptUrlRegistry.anyRequest().authenticated() |
| 118 | .and() | 133 | .and() |
| 119 | .headers().frameOptions().disable(); | 134 | .headers().frameOptions().disable(); |
| 120 | httpSecurity.logout().logoutUrl("/logout").logoutSuccessHandler(logoutSuccessHandler); | 135 | httpSecurity.logout().logoutUrl("/logout").logoutSuccessHandler(logoutSuccessHandler); |
begete-framework/src/main/java/com/begete/framework/config/YamlPropertySourceFactory.java
0 → 100644
| 1 | +package com.begete.framework.config; | ||
| 2 | + | ||
| 3 | +import org.springframework.beans.factory.config.YamlPropertiesFactoryBean; | ||
| 4 | +import org.springframework.core.env.PropertiesPropertySource; | ||
| 5 | +import org.springframework.core.env.PropertySource; | ||
| 6 | +import org.springframework.core.io.support.EncodedResource; | ||
| 7 | +import org.springframework.core.io.support.PropertySourceFactory; | ||
| 8 | +import org.springframework.lang.Nullable; | ||
| 9 | + | ||
| 10 | +import java.io.FileNotFoundException; | ||
| 11 | +import java.io.IOException; | ||
| 12 | +import java.util.Properties; | ||
| 13 | + | ||
| 14 | +public class YamlPropertySourceFactory implements PropertySourceFactory { | ||
| 15 | + | ||
| 16 | + @Override | ||
| 17 | + public PropertySource<?> createPropertySource(@Nullable String name, EncodedResource resource) throws IOException { | ||
| 18 | + Properties propertiesFromYaml = loadYamlIntoProperties(resource); | ||
| 19 | + String sourceName = name != null ? name : resource.getResource().getFilename(); | ||
| 20 | + return new PropertiesPropertySource(sourceName, propertiesFromYaml); | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + private Properties loadYamlIntoProperties(EncodedResource resource) throws FileNotFoundException { | ||
| 24 | + try { | ||
| 25 | + YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean(); | ||
| 26 | + factory.setResources(resource.getResource()); | ||
| 27 | + factory.afterPropertiesSet(); | ||
| 28 | + return factory.getObject(); | ||
| 29 | + } catch (IllegalStateException e) { | ||
| 30 | + // for ignoreResourceNotFound | ||
| 31 | + Throwable cause = e.getCause(); | ||
| 32 | + if (cause instanceof FileNotFoundException) | ||
| 33 | + throw (FileNotFoundException) e.getCause(); | ||
| 34 | + throw e; | ||
| 35 | + } | ||
| 36 | + } | ||
| 37 | +} |
begete-framework/src/main/java/com/begete/framework/config/properties/PermissionProperties.java
0 → 100644
| 1 | +package com.begete.framework.config.properties; | ||
| 2 | + | ||
| 3 | +import com.begete.framework.config.YamlPropertySourceFactory; | ||
| 4 | +import org.springframework.boot.context.properties.ConfigurationProperties; | ||
| 5 | +import org.springframework.context.annotation.Configuration; | ||
| 6 | +import org.springframework.context.annotation.PropertySource; | ||
| 7 | + | ||
| 8 | +import java.util.List; | ||
| 9 | + | ||
| 10 | +/** | ||
| 11 | + * @author: LiYang | ||
| 12 | + * @Email: lyflyyvip@163.com | ||
| 13 | + * @create: 2020-02-02 16:58 | ||
| 14 | + * @Description: | ||
| 15 | + **/ | ||
| 16 | +@Configuration | ||
| 17 | +@PropertySource(value = {"classpath:config/permission-properties.yml"}, factory = YamlPropertySourceFactory.class) | ||
| 18 | +@ConfigurationProperties("permission") | ||
| 19 | +public class PermissionProperties { | ||
| 20 | + | ||
| 21 | + private List<String> excludeUrls; | ||
| 22 | + | ||
| 23 | + | ||
| 24 | + public List<String> getExcludeUrls() { | ||
| 25 | + return excludeUrls; | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + public void setExcludeUrls(List<String> excludeUrls) { | ||
| 29 | + this.excludeUrls = excludeUrls; | ||
| 30 | + } | ||
| 31 | +} |
| @@ -5,7 +5,7 @@ | @@ -5,7 +5,7 @@ | ||
| 5 | <parent> | 5 | <parent> |
| 6 | <artifactId>begete</artifactId> | 6 | <artifactId>begete</artifactId> |
| 7 | <groupId>com.begete</groupId> | 7 | <groupId>com.begete</groupId> |
| 8 | - <version>3.3.0</version> | 8 | + <version>1.0.1</version> |
| 9 | </parent> | 9 | </parent> |
| 10 | <modelVersion>4.0.0</modelVersion> | 10 | <modelVersion>4.0.0</modelVersion> |
| 11 | 11 |
| @@ -5,7 +5,7 @@ | @@ -5,7 +5,7 @@ | ||
| 5 | <parent> | 5 | <parent> |
| 6 | <artifactId>begete</artifactId> | 6 | <artifactId>begete</artifactId> |
| 7 | <groupId>com.begete</groupId> | 7 | <groupId>com.begete</groupId> |
| 8 | - <version>3.3.0</version> | 8 | + <version>1.0.1</version> |
| 9 | </parent> | 9 | </parent> |
| 10 | <modelVersion>4.0.0</modelVersion> | 10 | <modelVersion>4.0.0</modelVersion> |
| 11 | 11 |
| @@ -5,7 +5,7 @@ | @@ -5,7 +5,7 @@ | ||
| 5 | <parent> | 5 | <parent> |
| 6 | <artifactId>begete</artifactId> | 6 | <artifactId>begete</artifactId> |
| 7 | <groupId>com.begete</groupId> | 7 | <groupId>com.begete</groupId> |
| 8 | - <version>3.3.0</version> | 8 | + <version>1.0.1</version> |
| 9 | </parent> | 9 | </parent> |
| 10 | <modelVersion>4.0.0</modelVersion> | 10 | <modelVersion>4.0.0</modelVersion> |
| 11 | 11 |
| @@ -6,13 +6,13 @@ | @@ -6,13 +6,13 @@ | ||
| 6 | 6 | ||
| 7 | <groupId>com.begete</groupId> | 7 | <groupId>com.begete</groupId> |
| 8 | <artifactId>begete</artifactId> | 8 | <artifactId>begete</artifactId> |
| 9 | - <version>3.3.0</version> | 9 | + <version>1.0.1</version> |
| 10 | 10 | ||
| 11 | <name>begete</name> | 11 | <name>begete</name> |
| 12 | <description>贝斯管理系统</description> | 12 | <description>贝斯管理系统</description> |
| 13 | 13 | ||
| 14 | <properties> | 14 | <properties> |
| 15 | - <begete.version>3.3.0</begete.version> | 15 | + <begete.version>1.0.1</begete.version> |
| 16 | <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | 16 | <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
| 17 | <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | 17 | <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> |
| 18 | <java.version>1.8</java.version> | 18 | <java.version>1.8</java.version> |
| @@ -255,12 +255,12 @@ | @@ -255,12 +255,12 @@ | ||
| 255 | <repository> | 255 | <repository> |
| 256 | <id>releases</id> | 256 | <id>releases</id> |
| 257 | <name>Nexus Release Repository</name> | 257 | <name>Nexus Release Repository</name> |
| 258 | - <url>http://112.126.101.137/repository/hosted/</url> | 258 | + <url>http://nexus.begete.com/repository/maven-releases/</url> |
| 259 | </repository> | 259 | </repository> |
| 260 | <snapshotRepository> | 260 | <snapshotRepository> |
| 261 | <id>snapshots</id> | 261 | <id>snapshots</id> |
| 262 | <name>Nexus Snapshot Repository</name> | 262 | <name>Nexus Snapshot Repository</name> |
| 263 | - <url>http://112.126.101.137/repository/maven-snapshots/</url> | 263 | + <url>http://nexus.begete.com/repository/maven-snapshots/</url> |
| 264 | </snapshotRepository> | 264 | </snapshotRepository> |
| 265 | </distributionManagement> | 265 | </distributionManagement> |
| 266 | 266 |
-
Please register or login to post a comment