springsecurityoauth2简单示例.docx

上传人:小飞机 文档编号:3166076 上传时间:2023-03-11 格式:DOCX 页数:5 大小:37.69KB
返回 下载 相关 举报
springsecurityoauth2简单示例.docx_第1页
第1页 / 共5页
springsecurityoauth2简单示例.docx_第2页
第2页 / 共5页
springsecurityoauth2简单示例.docx_第3页
第3页 / 共5页
springsecurityoauth2简单示例.docx_第4页
第4页 / 共5页
springsecurityoauth2简单示例.docx_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

《springsecurityoauth2简单示例.docx》由会员分享,可在线阅读,更多相关《springsecurityoauth2简单示例.docx(5页珍藏版)》请在三一办公上搜索。

1、springsecurityoauth2简单示例Spring-security-oauth2介绍 1 oauth2.0流程 具体的协议可参考 这里主要说明一下Authorization Grant,主要有四类Authorization Code,Implicit,Resource Owner Password Credentials,Client Credentials。 这里主要介绍服务端Authorization Code授权流程,基本流程:1.请求用户授权,2.获取code,3.获取token,4.请求资源验证token。 1.1 请求用户授权和获取code 首先要请求用户授权,其次才会

2、生成一个临时的code.可参考一下,我简单画得一个流程图如下: code关联类如下: 1.2 获取token token相关的类图 1.3 请求资源验证token 大体的流程基本如上,具体的xml配置请参考sparklr2的src/main/webapp/WEB-INF/spring-servlet.xml。 2 下载代码 Svn: 3 编译 mvn install -P bootstrap cd samples/oauth2/sparklr mvn war cd samples/oauth2/tonr mvn war 4 启动服务端 拷贝sparklr2到tomcat1webapps下,启动

3、服务器 访问:http:/localhost:8080/sparklr2/ 5 启动客户端 拷贝tonr2到tomcat2webapps下,启动服务器 访问:http:/localhost:8888/tonr2/ 6 OpenApi授权机制 首先必须申请成为平台的有效用户; 其次必须申请App授权,平台提供应用ID和授权码。 登录分2部分: 1、 用户、密码验证登录价立方; 2、 App访问的授权验证。 7 例子改造说明 1、 创建相关JDBC授权认证的表:oauth_client_details create table oauth_client_details ( client_id VA

4、RCHAR(50) PRIMARY KEY, resource_ids VARCHAR(256), client_secret VARCHAR(256), scope VARCHAR(256), authorized_grant_types VARCHAR(256), web_server_redirect_uri VARCHAR(256), authorities VARCHAR(256), access_token_validity VARCHAR(256), refresh_token_validity VARCHAR(256), additional_information VARCH

5、AR(256) ); insert into oauth_client_details(client_id,resource_ids,client_secret,scope,authorized_grant_types,authorities) values(client,sparklr,secret,read,write,authorization_code,implicit,ROLE_CLIENT); 也可以自己实现ClientDetailsService 2、 修改InMemoryClientDetailsService的为JdbcClientDetailsService 3、 如果To

6、ken要用JDBC存储,修改InMemoryTokenStore为JdbcMemoryTokenStore 4、 修改user-service为jdbc-user-service create table users( username VARCHAR(50) not null primary key, password VARCHAR(50) not null, enabled boolean not null); create table authorities ( username VARCHAR(50) not null, authority VARCHAR(50) not null,

7、 constraint fk_authorities_users foreign key(username) references users(username); create unique index ix_auth_username on authorities (username,authority); ); INSERT into users(username,password,enabled) values(marissa,koala,true); INSERT into authorities(username,authority) values(marissa,ROLE_USER); 也可以自己实现user-service org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl 结束

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号