提交 70ce26cc 编写于 作者: M ManongJu

commit

上级 5b8ddf72
package com.microservice.skeleton.common.vo;
import lombok.Data;
import java.io.Serializable;
/**
* Created with IntelliJ IDEA.
* Description:
* User: Mr.Yangxiufeng
* Date: 2018-05-10
* Time: 21:03
*/
@Data
public class RoleVo implements Serializable {
private static final long serialVersionUID = 2179037393108205286L;
private Integer roleId;
private String name;
private String value;
}
......@@ -42,10 +42,10 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!--<dependency>-->
<!--<groupId>org.springframework.boot</groupId>-->
<!--<artifactId>spring-boot-starter-actuator</artifactId>-->
<!--</dependency>-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
......
......@@ -4,10 +4,12 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
@SpringBootApplication
@EnableDiscoveryClient
@EnableZuulProxy
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class GatewayApplication {
public static void main(String[] args) {
......
......@@ -4,6 +4,7 @@ import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
/**
* Created by Mr.Yangxiufeng on 2017/12/29.
......@@ -11,7 +12,8 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur
* ProjectName:Mirco-Service-Skeleton
*/
@Configuration
@EnableOAuth2Sso
//@EnableOAuth2Sso
//@EnableResourceServer
public class SecurityConfig extends WebSecurityConfigurerAdapter{
@Override
......
......@@ -4,6 +4,8 @@ import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
......@@ -38,6 +40,7 @@ public class PreRequestFilter extends ZuulFilter {
public Object run() {
RequestContext ctx = RequestContext.getCurrentContext();
HttpServletRequest request = ctx.getRequest();
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
LOG.info("send {} request to {}",request.getMethod(),request.getRequestURL().toString());
return null;
}
......
......@@ -17,14 +17,14 @@ eureka:
service-url:
defaultZone: http://mss-eureka1:9010/eureka/,http://mss-eureka2:9011/eureka/
###actuator监控点 start####
endpoints:
health:
sensitive: false
enabled: true
#endpoints:
# health:
# sensitive: false
# enabled: true
##默认情况下很多端点是不允许访问的,会返回401:Unauthorized
management:
security:
enabled: false
#management:
# security:
# enabled: false
###actuator监控点 end####
###如下Oauth2.0配置参考##
......@@ -42,17 +42,23 @@ zuul:
strip-prefix: true
sensitiveHeaders:
serviceId: auth2.0-center
security:
basic:
enabled: false
oauth2:
client:
##网关的地址
access-token-uri: http://localhost:9030/uaa/oauth/token
user-authorization-uri: http://localhost:9030/uaa/oauth/authorize
resource:
user-info-uri: http://localhost:9030/uaa/user
prefer-token-info: false
#security:
# basic:
# enabled: false
# oauth2:
# client:
# ##网关的地址
# access-token-uri: http://localhost:9030/uaa/oauth/token
# user-authorization-uri: http://localhost:9030/uaa/oauth/authorize
# resource:
# user-info-uri: http://localhost:9060/user
# prefer-token-info: false
#security:
# oauth2:
# resource:
# id: resource
# user-info-uri: http://localhost:9060/user
# prefer-token-info: false
##############end#####################
####超时配置####
ribbon:
......
......@@ -3,15 +3,15 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.microservice.skeleton</groupId>
<artifactId>Micro-Service-Skeleton-Parent</artifactId>
<groupId>com.microservice.skeleton.modules</groupId>
<artifactId>Micro-Service-Skeleton-modules</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>Micro-Service-Skeleton-Resource</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>resource</name>
<name>mss-resource</name>
<description>Demo project for Spring Boot</description>
<dependencies>
......
package com.microservice.skeleton.resource.config;
import org.springframework.boot.autoconfigure.security.Http401AuthenticationEntryPoint;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
......@@ -18,9 +17,6 @@ public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
public void configure(HttpSecurity http) throws Exception {
http.
csrf().disable()
.exceptionHandling()
.authenticationEntryPoint(new Http401AuthenticationEntryPoint("Bearer realm=\"webrealm\""))
.and()
.authorizeRequests()
.mvcMatchers("/v2/api-docs").permitAll()
.anyRequest().authenticated()
......
server:
port: 9023
spring:
application:
name: resource
zipkin:
base-url: http://localhost:9050
eureka:
instance:
prefer-ip-address: true
instance-id: ${spring.cloud.client.ipAddress}:${server.port}
##续约更新时间间隔设置5秒,m默认30s
lease-renewal-interval-in-seconds: 5
##续约到期时间10秒,默认是90秒
lease-expiration-duration-in-seconds: 10
client:
service-url:
defaultZone: http://mss-eureka1:9010/eureka/,http://mss-eureka2:9011/eureka/
endpoints:
health:
sensitive: false
enabled: true
management:
security:
enabled: false
security:
oauth2:
resource:
id: resource
user-info-uri: http://localhost:9030/uaa/user
prefer-token-info: false
\ No newline at end of file
package com.microservice.skeleton.upms.service.impl;
import com.microservice.skeleton.upms.entity.RcUser;
import com.microservice.skeleton.upms.mapper.RcUserMapper;
import com.microservice.skeleton.upms.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.util.Sqls;
/**
* Created with IntelliJ IDEA.
* Description:
* User: Mr.Yangxiufeng
* Date: 2018-05-10
* Time: 19:57
*/
@Service
public class UserServiceImpl implements UserService {
@Autowired
private RcUserMapper userMapper;
@Override
public RcUser findByUsername(String username) {
Example example = Example.builder(RcUser.class)
.where(Sqls.custom().andEqualTo("username",username))
.build();
return userMapper.selectOneByExample(example);
}
}
package com.microservice.skeleton.auth.config;
import org.springframework.boot.autoconfigure.security.Http401AuthenticationEntryPoint;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
......@@ -19,9 +18,6 @@ public class ResourceServerConfig extends ResourceServerConfigurerAdapter{
public void configure(HttpSecurity http) throws Exception {
http.
csrf().disable()
.exceptionHandling()
.authenticationEntryPoint(new Http401AuthenticationEntryPoint("Bearer realm=\"webrealm\""))
.and()
.authorizeRequests().anyRequest().authenticated()
.and()
.httpBasic();
......
......@@ -19,18 +19,21 @@
<druid-starter.version>1.1.6</druid-starter.version>
<swagger2.version>2.8.0</swagger2.version>
<lombok.version>1.16.20</lombok.version>
<mybatis-plus.version>2.2.0</mybatis-plus.version>
<tk.mybatis.starter.version>2.0.2</tk.mybatis.starter.version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<version>1.5.12.RELEASE</version>
</parent>
<modules>
<module>mss-common</module>
<module>mss-eureka</module>
<module>mss-oauth</module>
<module>mss-gateway</module>
<module>mss-monitor</module>
<module>mss-resource</module>
<module>mss-modules</module>
</modules>
<dependencies>
<!--Lombok-->
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册