SSO DAY02

    认证服务器里的常用路径

路径

说明

/oauth/authoriz

授权端点

/oauth/token

令牌端点 获取token

/oauth/confirm_access

用户确认授权提交端点

/oauth/error

授权服务错误信息端点

/oauth/check_token

用于资源服务访问的令牌解析端点

/oauth/token_key

提供公有密匙的端点,如果你使用JWT(RSA)令牌的

编写oauth配置类

在编写SecurityConfiguration配置类

授权码模式

使用http://localhost:8050/oauth/authorize?response_type=code&client_id=admin&scop=all

获取授权码

使用第三方软件请求得出结果

=========================================================================

简单模式

直接访问路径

返回路径会显示具体参数

 客户端模式

填写相对应数据即可

安全模式

 安全配置

添加jwt依赖

配置bean

使用bean

 

 

获取到 jwt 类型的 token

 

编写

搭载资源服务器

新建service模块

添加依赖

再其中在创建一个model 

修改配置文件

访问http://localhost:8010/login

但是可以直接访问不安全所以增加配置类

package com.aaa.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;

@Configuration
@EnableResourceServer
@EnableGlobalMethodSecurity(jsr250Enabled = true,prePostEnabled = true,securedEnabled = true)
public class MyResConfig extends ResourceServerConfigurerAdapter {

    @Override
    public void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .anyRequest().authenticated()
                //.access("@RbacConfig.hasPermission(request,authentication)")
                .and()
                .csrf().disable();
    }
    @Bean
    public TokenStore tokenStore() {
        return new JwtTokenStore(jwtAccessTokenConverter());
    }
    @Bean
    public JwtAccessTokenConverter jwtAccessTokenConverter(){
        JwtAccessTokenConverter jwtAccessTokenConverter = new JwtAccessTokenConverter();
        jwtAccessTokenConverter.setSigningKey("dev");
        return jwtAccessTokenConverter;
    }


}

   测试资源是否生效

       携带token 访问资源服务器,Authorization  放在headers里面的,Token的值 要求必须是bearer 类型的 token前面加上这个类型

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值