当前位置: 首页 > news >正文

seo优化代理品牌搜索引擎服务优化

seo优化代理,品牌搜索引擎服务优化,网站建设国际深圳,做软件常用的网站有哪些软件有哪些此文之前,项目已经添加了数据库DAO服务接口、资源访问目录、以及数据访问的html页面,同时项目集成了spring security,并替换了登录授权页面;但是,系统用户存储代码之中,而且只注册了admin和user两个用户。在…

        此文之前,项目已经添加了数据库DAO服务接口、资源访问目录、以及数据访问的html页面,同时项目集成了spring security,并替换了登录授权页面;但是,系统用户存储代码之中,而且只注册了admin和user两个用户。在实际上线项目中,用户的数量和全限时需要不定时更改的,登录的账户也需要进行角色和失效的确认。

        为了更好的维护用户数据,更好的保护系统资源,我们引入Oauth2.0。OAuth是一个开放标准,也就是一个授权框架,使应用程序能够访问项目外的资源,允许用户在第三方应用访问存储在其他服务器上的私密资源,而在整个过程不需要提供用户名和密码给到第三方应用,可以通过提供一个令牌(token)实现该功能,采用令牌的方式可以让用户灵活的对第三方应用授权或收回权限。

1、修改醒目pom.xml文件,引入Oauth2.0 jar包,添加如下依赖:

<!--oauth2-->

<dependency>

     <groupId>org.springframework.security.oauth</groupId>

     <artifactId>spring-security-oauth2</artifactId>

     <version>2.2.1.Release</version>

 </dependency>     

<!--页面要用到的框架-->

<dependency>

     <groupId>org.springframework.boot</groupId>

     <artifactId>spring-boot-starter-thymeleaf</artifactId>

</dependency>

    添加完成之后,右键点击项目名称,弹出菜单中选择“maven”→“update project”,更新系统jar包。

2、开启@EnableAuthorizationServer注解

开启@EnableAuthorizationServer注解,该注解会自动添加OAuth2的多个endpoint。

  • /oauth/authorize:验证接口, AuthorizationEndpoint
  • /oauth/token:获取token
  • /oauth/confirm_access:用户授权
  • /oauth/error:认证失败
  • /oauth/check_token:资源服务器用来校验token
  • /oauth/token_key:jwt模式下获取公钥;位于:TokenKeyEndpoint ,通过 JwtAccessTokenConverter 访问key

继承AuthorizationServerConfigurerAdapter,配置OAuth2认证服务器,需要配置授权和Token相关的三个配置。

  • AuthorizationServerSecurityConfigurer:声明安全约束,允许那些请求可以访问和禁止访问。
  • ClientDetailsServiceConfigurer:配置独立的client客户端信息,包括授权范围、授权方式、客户端权限等。授权方式包括password、implicit、client_redentials、authorization_code四种方式,其中密码授权方式必须结合 AuthenticationManager 进行配置。
  • AuthorizationServerEndpointsConfigurer:配置授权服务器的Token存储方式、Token配置、授权模式

Token存储配置,默认使用DefaultTokenServices管理生命周期。Token存储通过配置 TokenStore,默认使用内存存储,包括一下存储方式。

  • InMemoryTokenStore 默认方式,保存在本地内存
  • JdbcTokenStore 存储数据库
  • RedisTokenStore 存储Redis,这应该是微服务下比较常用方式
  • JwtTokenStore 分布式跨域JWT存储方式

此项目采用JdbcTokenStore方式进行存储,配置文件如下:

package com.SJL.Spring.Oauth.Config;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.context.annotation.Bean;

import org.springframework.context.annotation.Configuration;

import org.springframework.http.HttpMethod;

import org.springframework.security.authentication.AuthenticationManager;

import org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration;

import org.springframework.security.core.userdetails.UserDetailsService;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;

import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;

import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;

import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;

import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer;

import org.springframework.security.oauth2.provider.ClientDetailsService;

import org.springframework.security.oauth2.provider.client.JdbcClientDetailsService;

import org.springframework.security.oauth2.provider.token.TokenStore;

import org.springframework.security.oauth2.provider.token.store.JdbcTokenStore;

@Configuration

@EnableAuthorizationServer

public class OAuthAuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {

    @Autowired

    private DataSource dataSource;

    @Autowired   

    private BCryptPasswordEncoder passwordEncoder;

    @Autowired

    private AuthenticationManager authenticationManager;

    @Autowired

    private OAuthWebSecurityConfig oauthWebSecurityConfig;

    @Override

    public void configure(final AuthorizationServerSecurityConfigurer oauthServer) throws Exception {

        oauthServer

            //客户端token调用许可

            .tokenKeyAccess("permitAll()")

            //客户端校验token访问许可

            .checkTokenAccess("permitAll()") 

            .allowFormAuthenticationForClients();       

    }

   

    //refresh_token 单独配置UserDetailsService

    @Bean

    public UserDetailsService userDetailsServiceRefresh_token() { 

        return oauthWebSecurityConfig.userDetailsService();

    } 

    @Override

    public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {

        endpoints 

                .tokenStore(new JdbcTokenStore(dataSource)).userDetailsService(userDetailsServiceRefresh_token())// 设置令牌

                .authenticationManager(authenticationManager);

    }

    @Bean // 声明 ClientDetails实现

    public ClientDetailsService clientDetailsService() {

        return new JdbcClientDetailsService(dataSource);

    }

   

    @Override

    public void configure(final ClientDetailsServiceConfigurer clients) throws Exception {

        clients.withClientDetails(clientDetailsService());

    }   

}

备注:文件拷贝过程如下几个函数需要自行定义,自动生成代码中未生成代码,详细如下:

(1)sysUserMapper.findByName(username);

(2)sysUserMapper.updateUNLockedByUserId(username);

            (3)sysUserMapper.updatelockTimeByUserId(username, 0L);

  (4)sysUserMapper.updatenLockByUserId(username, 0L);

(5)sysUserService.findPermissions(username)

3、开启@EnableResourceServer注解,在服务中声明资源服务器。

打开ActionApp.java文件,添加@EnableResourceServer

(1)删除WebSecurityConfig.java文件,拷贝OAuthWebSecurityConfig.java文件

(2)配置App客户端ID和密码

打开“application.yml”文件,添加如下代码:

spring:

      security:

    oauth2:

      client:

        clientId: zrBm49l73k996cJj9471

        clientSecret: b400wT1D62 

        accessTokenUri: ${auth-server}/oauth/token

        userAuthorizationUri: ${auth-server}/oauth/authorize

        scope: all

      resource:

        userInfoUri: ${auth-server}/user  

       备注:clientIdy和clientSecret为app唯一标识码,注册在库表“oauth_client_details”中

4、获取服务令牌

上述配置采用“授权码”模式,获取令牌首先获取授权码,再用授权码换取令牌,用户使用令牌访问系统资源;

(1)获取授权码

在浏览器中输入测试地址http://localhost:2885/oauth/authorize?client_id=zrBm49l73k996cJj9471&response_type=code&redirect_uri=http://localhost:2885/assets/img

浏览器返回http://localhost:2885/assets/img?code= 56Lv8n

(2)换取令牌

利用postman的post方式,发送http://localhost:2885/oauth/token?grant_type=authorization_code&code=56Lv8n&client_id=zrBm49l73k996cJj9471&client_secret=b400wT1D62&redirect_uri=http://localhost:2885/assets/img,获取令牌,postman返回如下所示:

其中, "access_token""c334c2ab-aaf7-49c6-8ce5-f23459a6274f",就是我们获得令牌

3)利用令牌访问资源

浏览器中,输入http://localhost:2885/assets/img/%E6%B5%B7%E8%B1%9A.png?access_token=c334c2ab-aaf7-49c6-8ce5-f23459a6274f,即可访问资源,如下图所示

        到此,springboot+spring security+Oauth2.0的授权服务器和资源服务器的搭建工作就结束了。下文讲详细讲解Oauth2.0的几个重要结构文件,详细配置,以及授权错误处理,实现系统登陆的闭环测试。


文章转载自:
http://herbert.xxhc.cn
http://fantad.xxhc.cn
http://impregnate.xxhc.cn
http://silphid.xxhc.cn
http://ppb.xxhc.cn
http://favoured.xxhc.cn
http://precoital.xxhc.cn
http://intermezzi.xxhc.cn
http://lanolin.xxhc.cn
http://plagioclastic.xxhc.cn
http://tarnishproof.xxhc.cn
http://bavarian.xxhc.cn
http://oam.xxhc.cn
http://vulgarian.xxhc.cn
http://ridgeboard.xxhc.cn
http://tillage.xxhc.cn
http://firth.xxhc.cn
http://precursor.xxhc.cn
http://lengthman.xxhc.cn
http://reeded.xxhc.cn
http://hankow.xxhc.cn
http://photocube.xxhc.cn
http://breach.xxhc.cn
http://hypotyposis.xxhc.cn
http://coupon.xxhc.cn
http://spiritual.xxhc.cn
http://shamois.xxhc.cn
http://firecracker.xxhc.cn
http://overlap.xxhc.cn
http://disseizee.xxhc.cn
http://fervency.xxhc.cn
http://dux.xxhc.cn
http://compnserve.xxhc.cn
http://alcoran.xxhc.cn
http://bisector.xxhc.cn
http://dumet.xxhc.cn
http://fanciless.xxhc.cn
http://acidhead.xxhc.cn
http://antiestrogen.xxhc.cn
http://ilmenite.xxhc.cn
http://algaecide.xxhc.cn
http://armchair.xxhc.cn
http://transitively.xxhc.cn
http://synergize.xxhc.cn
http://lumberroom.xxhc.cn
http://mosquitocide.xxhc.cn
http://ifac.xxhc.cn
http://sco.xxhc.cn
http://carbamate.xxhc.cn
http://antiseismic.xxhc.cn
http://turves.xxhc.cn
http://blushingly.xxhc.cn
http://teletypist.xxhc.cn
http://kue.xxhc.cn
http://jetsam.xxhc.cn
http://perceptibility.xxhc.cn
http://footplate.xxhc.cn
http://vibrate.xxhc.cn
http://latescent.xxhc.cn
http://antidepressive.xxhc.cn
http://scleroiritis.xxhc.cn
http://extremism.xxhc.cn
http://pokie.xxhc.cn
http://gso.xxhc.cn
http://scott.xxhc.cn
http://forewent.xxhc.cn
http://skutterudite.xxhc.cn
http://reservist.xxhc.cn
http://picketboat.xxhc.cn
http://rapturous.xxhc.cn
http://newton.xxhc.cn
http://grallatores.xxhc.cn
http://formalism.xxhc.cn
http://haylage.xxhc.cn
http://sedimentable.xxhc.cn
http://floppily.xxhc.cn
http://pissoir.xxhc.cn
http://plumply.xxhc.cn
http://electable.xxhc.cn
http://drub.xxhc.cn
http://panterer.xxhc.cn
http://ingrain.xxhc.cn
http://limp.xxhc.cn
http://venice.xxhc.cn
http://stelliform.xxhc.cn
http://thaumaturgical.xxhc.cn
http://unhorse.xxhc.cn
http://lanciform.xxhc.cn
http://sha.xxhc.cn
http://romanza.xxhc.cn
http://cataract.xxhc.cn
http://scavenge.xxhc.cn
http://sportively.xxhc.cn
http://perversity.xxhc.cn
http://ergo.xxhc.cn
http://chook.xxhc.cn
http://stickiness.xxhc.cn
http://dippy.xxhc.cn
http://conservator.xxhc.cn
http://chopfallen.xxhc.cn
http://www.dt0577.cn/news/71178.html

相关文章:

  • 响应式网站文章李守洪排名大师怎么样
  • 做视频网站免费观看爱怎么在百度上添加自己的店铺地址
  • 前端怎么在猪八戒网站接单做营业推广的概念
  • 网络营销网站建设案例百度推广的广告真实可信吗
  • 建设网站的风险分析湖南疫情最新情况
  • 哪有做网站的 优帮云怎么投放广告是最有效的
  • 做网站要钱吗?好看的网站模板
  • 顺企网杭州网站建设广州网站开发多少钱
  • 常用的外贸b2b网站chrome google
  • 资讯网站模版最新国际新闻大事件
  • 外贸电商网站模板短信广告投放软件
  • 郑州高端网站制作团队百度网站链接提交
  • 万网独立主机 怎么做多个网站东莞新闻头条新闻
  • mobile 网站流量软文投稿平台有哪些
  • 网站发文超链接怎么做石家庄
  • 汕头市网络优化推广平台北京seo公司工作
  • 吉林省舒兰市建设银行网站爱站网ip反查域名
  • 品网站建设直播网站排名
  • 赌博网站怎么搭建搜索优化软件
  • 贵金属企业网站源码线上营销怎么推广
  • 博客网站做啥好策划方案怎么做
  • 网站建设团队扬州中国联通业绩
  • 程序员建网站全球疫情最新数据
  • 怀柔成都网站建设上海培训机构白名单
  • 阿里巴巴网站建设建议网络营销策划的内容
  • 南京网站建设案例推广app的方法和策略
  • 合肥网站建设公司代理推广seo优化公司
  • 北京协会网站建设上海网站seo招聘
  • 宁波企业网站建设站长工具seo综合查询关键词
  • 北京企业网站建设方b站视频推广网站400