Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
学习是不可能停的
micro-service-skeleton
提交
0ff5fdaf
M
micro-service-skeleton
项目概览
学习是不可能停的
/
micro-service-skeleton
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
micro-service-skeleton
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
0ff5fdaf
编写于
12月 27, 2017
作者:
M
ManongJu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
security登录认证
上级
7aec65eb
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
212 addition
and
6 deletion
+212
-6
auth-center/pom.xml
auth-center/pom.xml
+16
-5
auth-center/src/main/java/com/microservice/skeleton/auth/AuthCenterApplication.java
...com/microservice/skeleton/auth/AuthCenterApplication.java
+2
-0
auth-center/src/main/java/com/microservice/skeleton/auth/config/WebSecurityConfig.java
.../microservice/skeleton/auth/config/WebSecurityConfig.java
+50
-0
auth-center/src/main/java/com/microservice/skeleton/auth/controller/HelloController.java
...icroservice/skeleton/auth/controller/HelloController.java
+31
-0
auth-center/src/main/java/com/microservice/skeleton/auth/respository/RoleRepository.java
...icroservice/skeleton/auth/respository/RoleRepository.java
+14
-0
auth-center/src/main/java/com/microservice/skeleton/auth/service/impl/UserDetailsServiceImpl.java
...ce/skeleton/auth/service/impl/UserDetailsServiceImpl.java
+35
-0
auth-center/src/main/resources/application.yml
auth-center/src/main/resources/application.yml
+23
-1
auth-center/src/main/resources/templates/hello.html
auth-center/src/main/resources/templates/hello.html
+10
-0
auth-center/src/main/resources/templates/index.html
auth-center/src/main/resources/templates/index.html
+10
-0
auth-center/src/main/resources/templates/login.html
auth-center/src/main/resources/templates/login.html
+21
-0
未找到文件。
auth-center/pom.xml
浏览文件 @
0ff5fdaf
...
...
@@ -21,15 +21,26 @@
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-actuator
</artifactId>
</dependency>
<!--<dependency>-->
<!--<groupId>org.springframework.cloud</groupId>-->
<!--<artifactId>spring-cloud-starter-eureka</artifactId>-->
<!--</dependency>-->
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-eureka
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-security
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-oauth2
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-thymeleaf
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
...
...
auth-center/src/main/java/com/microservice/skeleton/auth/AuthCenterApplication.java
浏览文件 @
0ff5fdaf
...
...
@@ -2,8 +2,10 @@ package com.microservice.skeleton.auth;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.cloud.client.discovery.EnableDiscoveryClient
;
@SpringBootApplication
@EnableDiscoveryClient
public
class
AuthCenterApplication
{
public
static
void
main
(
String
[]
args
)
{
...
...
auth-center/src/main/java/com/microservice/skeleton/auth/config/WebSecurityConfig.java
0 → 100644
浏览文件 @
0ff5fdaf
package
com.microservice.skeleton.auth.config
;
import
com.microservice.skeleton.auth.service.impl.UserDetailsServiceImpl
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder
;
import
org.springframework.security.config.annotation.web.builders.HttpSecurity
;
import
org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
;
import
org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
;
import
org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
;
import
org.springframework.security.crypto.password.PasswordEncoder
;
/**
* Created by Mr.Yangxiufeng on 2017/12/27.
* Time:16:42
* ProjectName:Mirco-Service-Skeleton
*/
@Configuration
@EnableWebSecurity
public
class
WebSecurityConfig
extends
WebSecurityConfigurerAdapter
{
@Autowired
private
UserDetailsServiceImpl
userDetailsService
;
@Bean
public
PasswordEncoder
passwordEncoder
()
{
return
new
BCryptPasswordEncoder
();
}
@Override
protected
void
configure
(
AuthenticationManagerBuilder
auth
)
throws
Exception
{
auth
.
userDetailsService
(
userDetailsService
)
.
passwordEncoder
(
passwordEncoder
());
}
@Override
protected
void
configure
(
HttpSecurity
http
)
throws
Exception
{
http
.
authorizeRequests
()
.
anyRequest
().
authenticated
()
.
and
()
.
formLogin
()
.
loginPage
(
"/login"
)
.
failureUrl
(
"/login?error"
)
.
permitAll
()
.
and
()
.
logout
()
.
permitAll
();
http
.
csrf
().
disable
().
httpBasic
();
}
}
auth-center/src/main/java/com/microservice/skeleton/auth/controller/HelloController.java
0 → 100644
浏览文件 @
0ff5fdaf
package
com.microservice.skeleton.auth.controller
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
/**
* Created by Mr.Yangxiufeng on 2017/12/27.
* Time:17:02
* ProjectName:Mirco-Service-Skeleton
*/
@Controller
public
class
HelloController
{
@RequestMapping
(
"/"
)
public
String
index
()
{
return
"index"
;
}
@RequestMapping
(
"/hello"
)
public
String
hello
()
{
return
"hello"
;
}
@RequestMapping
(
"/login"
)
public
String
login
()
{
return
"login"
;
}
@RequestMapping
(
value
=
"/doLogin"
,
method
=
RequestMethod
.
POST
)
public
void
doLogin
(
String
username
,
String
password
){
System
.
out
.
println
(
username
);
}
}
auth-center/src/main/java/com/microservice/skeleton/auth/respository/RoleRepository.java
0 → 100644
浏览文件 @
0ff5fdaf
package
com.microservice.skeleton.auth.respository
;
import
com.microservice.skeleton.auth.entity.RcRoleEntity
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.stereotype.Repository
;
/**
* Created by Mr.Yangxiufeng on 2017/12/27.
* Time:16:09
* ProjectName:Mirco-Service-Skeleton
*/
@Repository
public
interface
RoleRepository
extends
JpaRepository
<
RcRoleEntity
,
Integer
>{
}
auth-center/src/main/java/com/microservice/skeleton/auth/service/impl/UserDetailsServiceImpl.java
0 → 100644
浏览文件 @
0ff5fdaf
package
com.microservice.skeleton.auth.service.impl
;
import
com.microservice.skeleton.auth.entity.RcUserEntity
;
import
com.microservice.skeleton.auth.service.UserService
;
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
;
import
org.springframework.security.core.userdetails.UserDetailsService
;
import
org.springframework.security.core.userdetails.UsernameNotFoundException
;
import
org.springframework.stereotype.Service
;
import
java.util.HashSet
;
import
java.util.Set
;
/**
* Created by Mr.Yangxiufeng on 2017/12/27.
* Time:16:37
* ProjectName:Mirco-Service-Skeleton
*/
@Service
public
class
UserDetailsServiceImpl
implements
UserDetailsService
{
@Autowired
private
UserService
userService
;
@Override
public
UserDetails
loadUserByUsername
(
String
username
)
throws
UsernameNotFoundException
{
RcUserEntity
userEntity
=
userService
.
findByUsername
(
username
);
if
(
userEntity
==
null
){
throw
new
UsernameNotFoundException
(
"用户:"
+
username
+
",不存在!"
);
}
Set
<
GrantedAuthority
>
grantedAuthorities
=
new
HashSet
<>();
User
user
=
new
User
(
userEntity
.
getUsername
(),
userEntity
.
getPassword
(),
grantedAuthorities
);
return
user
;
}
}
auth-center/src/main/resources/application.yml
浏览文件 @
0ff5fdaf
spring
:
application
:
name
:
auth2.0-center
zipkin
:
base-url
:
http://10.10.8.2:9050
jpa
:
show-sql
:
true
datasource
:
...
...
@@ -10,4 +12,24 @@ spring:
druid
:
driver-class-name
:
com.mysql.jdbc.Driver
server
:
port
:
9060
\ No newline at end of file
port
:
9060
eureka
:
instance
:
prefer-ip-address
:
true
#使用IP注册
instance-id
:
${spring.cloud.client.ipAddress}:${server.port}
lease-renewal-interval-in-seconds
:
5
##为了能够快速删除
lease-expiration-duration-in-seconds
:
10
##为了能够快速删除
client
:
service-url
:
defaultZone
:
http://register1:9010/eureka/,http://register2:9011/eureka/
###actuator监控点 start####
endpoints
:
health
:
sensitive
:
false
enabled
:
true
##默认情况下很多端点是不允许访问的,会返回401:Unauthorized
management
:
security
:
enabled
:
false
###actuator监控点 end####
\ No newline at end of file
auth-center/src/main/resources/templates/hello.html
0 → 100644
浏览文件 @
0ff5fdaf
<!DOCTYPE html>
<html
xmlns=
"http://www.w3.org/1999/xhtml"
xmlns:th=
"http://www.thymeleaf.org"
xmlns:sec=
"http://www.thymeleaf.org/thymeleaf-extras-springsecurity3"
>
<head>
<title>
Hello World!
</title>
</head>
<body>
<h1>
Hello world!
</h1>
</body>
</html>
\ No newline at end of file
auth-center/src/main/resources/templates/index.html
0 → 100644
浏览文件 @
0ff5fdaf
<!DOCTYPE html>
<html
xmlns=
"http://www.w3.org/1999/xhtml"
xmlns:th=
"http://www.thymeleaf.org"
xmlns:sec=
"http://www.thymeleaf.org/thymeleaf-extras-springsecurity3"
>
<head>
<title>
Spring Security入门
</title>
</head>
<body>
<h1>
欢迎使用Spring Security!
</h1>
<p>
点击
<a
th:href=
"@{/hello}"
>
这里
</a>
打个招呼吧
</p>
</body>
</html>
\ No newline at end of file
auth-center/src/main/resources/templates/login.html
0 → 100644
浏览文件 @
0ff5fdaf
<!DOCTYPE html>
<html
xmlns=
"http://www.w3.org/1999/xhtml"
xmlns:th=
"http://www.thymeleaf.org"
xmlns:sec=
"http://www.thymeleaf.org/thymeleaf-extras-springsecurity3"
>
<head>
<title>
Spring Security Example
</title>
</head>
<body>
<div
th:if=
"${param.error}"
>
用户名或密码错
</div>
<div
th:if=
"${param.logout}"
>
您已注销成功
</div>
<form
th:action=
"@{/login}"
method=
"post"
>
<div><label>
用户名 :
<input
type=
"text"
name=
"username"
/>
</label></div>
<div><label>
密 码 :
<input
type=
"password"
name=
"password"
/>
</label></div>
<div><input
type=
"submit"
value=
"登录"
/></div>
</form>
</body>
</html>
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录