一 Spring Security
1. 2种认证的方式
基于token认证


基于session认证


方案选型

2. Spring Security 过滤器链


认证过程:

授权过程

二 OAuth2.0

授权的流程:



-
(1) 验证token(令牌):
http://localhost:8001/uaa/oauth/check_token?token=xxxx -
(2) 携带令牌访问具体请求: http://localhost:8003/order/r1
参数放在header: Authorization Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsicmVzMSJdLCJ1c2VyX25hbWUiOiJ7XCJmdWxsbmFtZVwiOlwi5YiY5bCP5YiAXCIsXCJpZFwiOlwiMVwiLFwibW9iaWxlXCI6XCIxNzUyMDQyNzQxOVwiLFwicGFzc3dvcmRcIjpcIiQyYSQxMCRkLk5WN1gwdjBWb1FObXdpMW5lR0kuMDVvNUlmNTRqaXFXekJlWVlCTFNhUU5sQkk3bnlGV1wiLFwidXNlcm5hbWVcIjpcInRpbmFcIn0iLCJzY29wZSI6WyJST0xFX0FETUlOIiwiUk9MRV9VU0VSIiwiUk9MRV9BUEkiXSwiZXhwIjoxNTk0NjE2MTQ4LCJhdXRob3JpdGllcyI6WyJwMSIsInAzIl0sImp0aSI6IjRiNTAxN2NiLTNjNjctNGFhNS1hZmIyLTM5N2JkZjRlMzQ3MiIsImNsaWVudF9pZCI6ImMxIn0.6GIEgYeG3mFiioMK134y18jO518O1uLIkIgNZDJ-PV4
授权码模式
- (1)获取授权码的接口:
get请求 http://localhost:8001/uaa/oauth/authorize?client_id=c1&response_type=code&scope=all&redirect_uri=http://www.baidu.com - (2)获取令牌的接口:
post请求 http://localhost:8001/uaa/oauth/token?client_id=c1&client_secret=secret&grant_type=authorization_code&code=pl9IyX&redirect_uri=http://www.baidu.com

简化模式
- (1) 获取令牌(token)
get 请求 /uaa/oauth/authorize client_id=c1&response_type=token&scope=all&redirect_uri=http://www.baidu.com
密码模式
- (1) 获取令牌(token)
post 请求 http://localhost:8001/uaa/oauth/token?client_id=c1&client_secret=secret&grant_type=password&username=tina&password=123
客户端模式
- (1) 获取令牌(token)
post 请求 http://localhost:8001/uaa/oauth/token?client_id=c1&client_secret=secret&grant_type=client_credentials

三 Jwt


网友评论