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

wordpress后台管理界面美化百度seo详解

wordpress后台管理界面美化,百度seo详解,怎么做网页上小广告,作一个网站要多少钱1、SpringSecurity 1.1 SpringSecurity简介 Spring Security是基于Spring的安全框架,提供了包含认证和授权的落地方案;Spring Security底层充分利用了Spring IOC和AOP功能,为企业应用系统提供了声明式安全访问控制解决方案;SpringSecurity可…

1、SpringSecurity

1.1 SpringSecurity简介

  • Spring Security是基于Spring的安全框架,提供了包含认证和授权的落地方案;
  • Spring Security底层充分利用了Spring IOC和AOP功能,为企业应用系统提供了声明式安全访问控制解决方案;
  • SpringSecurity可在Web请求级别和方法调用级别处理身份认证和授权,为应用系统提供声明式的安全访问控制功能;

官网地址: https://spring.io/projects/spring-security

1.2 SpringSecurity工程搭建

导入基础工程:day10-分库分表项目集成和安全框架\资料\security资料\基础代码\security_demo

A. 创建工程引入依赖

<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.3.4.RELEASE</version><relativePath/>
</parent>
<dependencies><!-- web起步依赖 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!-- springBoot整合Security --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId></dependency><!-- lombok --><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></dependency>
</dependencies>

B. 引导类

@SpringBootApplication
public class MySecurityApplication {public static void main(String[] args) {SpringApplication.run(MySecurityApplication.class,args);}
}

C. Controller

@RestController
public class UserController {@GetMapping("/hello")public String hello(){return "hello security";}@GetMapping("/say")public String say(){return "say security";}@GetMapping("/register")public String register(){return "register security";}
}

D. 测试

访问: http://localhost:8080/hello

会自动拦截,并跳转到登录页面(SpringSecurity提供),登录之后才可以访问; 而登录的用户名和密码都是SpringSecurity中内置的默认的用户名密码, 用户名为user , 密码为控制台输出的一段随机数;

在这里插入图片描述

效果:

在这里插入图片描述

登录成功之后,会自动跳转到之前访问的地址:

在这里插入图片描述

注意:

# 我们也可在配置文件中配置用户名和密码,实际开发中密码不应明文配置
spring.security.user.name=user
spring.security.user.password=6666

2、SpringSecurity自定义认证配置

​ 在上述入门程序中, 用户名、密码都是框架默认帮我们生成的, 方式不够友好,SpringSecurity也为我们提供了通过配置的形式声明合法的账户信息的方式。

A.声明配置类,定义用户名密码信息

@Configuration
@EnableWebSecurity//开启web安全设置生效
public class SecurityConfig extends WebSecurityConfigurerAdapter {/*** 构建认证服务,并将对象注入spring IOC容器,用户登录时,会调用该服务进行用户合法信息认证* @return*/@Beanpublic UserDetailsService userDetailsService(){//从内存获取用户认证信息的服务类(了解)后期用户的信息要从表中获取InMemoryUserDetailsManager inMemoryUserDetailsManager = new InMemoryUserDetailsManager();//构建用户,真实开发中用户信息要从数据库加载构建UserDetails u1 = User.withUsername("itcast").password("{noop}123456")//{noop}:no operration--》表示登录时对避免不做任何操作,说白了就是明文比对.authorities("P5", "ROLE_ADMIN")//用户的权限信息.build();UserDetails u2 = User.withUsername("itheima").password("{noop}123456").authorities("P7", "ROLE_SELLER","ROLE_ADMIN")//如果角色也作为一种权限资源,则角色名称的前缀必须加ROLE_.build();inMemoryUserDetailsManager.createUser(u1);inMemoryUserDetailsManager.createUser(u2);return inMemoryUserDetailsManager;}
}

说明:

1.在userDetailsService()方法中 返回了一个UserDetailsService对象给spring容器管理,当用户发生登录认证行为时,Spring Security底层会自动调用UserDetailsService类型bean提供的用户信息进行合法比对,如果比对成功则资源放行,否则就认证失败;

2.当前暂时使用InMemoryUserDetailsManager实现类,后续我们也可手动实现UserDetailsService接口,做最大程度的自定义;

B.测试配置账户信息

​ 通过测试,配置的账户和密码信息都是有效的。

4、SpringSecurity自定义授权配置

​ 经过上一小结配置,我们发现用户认证通过后,资源是都可被访问的。如果我们想为不同的用户指定不同的访问资源,该如何实现呢?

接下来,我们通过配置为不同用户访问授权。

4.1 基于编码方式定义授权

@Configuration
@EnableWebSecurity
//@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {@Bean@Overridepublic UserDetailsService userDetailsService(){InMemoryUserDetailsManager inMemoryUserDetailsManager = new InMemoryUserDetailsManager();inMemoryUserDetailsManager.createUser(User.withUsername("itcast").password("{noop}123456").authorities("P1","ROLE_ADMIN").build());inMemoryUserDetailsManager.createUser(User.withUsername("itheima").password("{noop}123456").authorities("O1","ROLE_SELLER").build());return inMemoryUserDetailsManager;}@Overrideprotected void configure(HttpSecurity http) throws Exception {http.formLogin()//开启默认form表单登录方式.and().logout()//登出用默认的路径登出 /logout.permitAll()//允许所有的用户访问登录或者登出的路径.and().csrf().disable()//启用CSRF,防止CSRF攻击.authorizeRequests()//授权方法,该方法后有若干子方法进行不同的授权规则处理//允许所有账户都可访问(不登录即可访问),同时可指定多个路径.antMatchers("/register").permitAll()//开发方式1:基于配置
//                .antMatchers("/a1","/a2").hasRole("seller")//拥有seller角色的用户可访问a1和a2资源//拥有指定的任意角色都可以访问对应资源
//                .antMatchers("/b1").hasAnyRole("manager1","manager2")//用户任意指定的aa bb都可以访问c1资源
//                .antMatchers("/c1").hasAnyAuthority("aa","bb")
//                .antMatchers("/d").denyAll()//拒绝任意用户访问
//                .antMatchers("/e").anonymous()//允许匿名访问//指定IP可以访问
//                .antMatchers("/f").hasIpAddress("localhost/82").antMatchers("/hello").hasAuthority("P5") //具有P5权限才可以访问.antMatchers("/say").hasRole("ADMIN") //具有ROLE_ADMIN 角色才可以访问.anyRequest().authenticated(); //除了上边配置的请求资源,其它资源都必须授权才能访问}
}

CSRF(Cross-site request forgery)跨站请求伪造,也被称为"One Click Attack"或者 Session Riding,通常缩写为 CSRF 或者 XSRF,是一种对网站的恶意利用。

4.2 基于注解方式定义授权

​ 基于注解的方式维护权限更偏向于集中化配置管理,但是这种方式带来的问题是随着权限管理的资源的增多,会导致权限配置变得十分的臃肿,所以SpringSecurity为我们提供了基于注解的配置方式。

A.在配置类开启security的前置注解

//开启SpringSecurity相关注解支持
@EnableGlobalMethodSecurity(prePostEnabled = true)

B.调整资源配置类

    @Overrideprotected void configure(HttpSecurity http) throws Exception {http.formLogin()//定义认证时使用form表单的方式提交数据.and().logout()//登出用默认的路径登出 /logout.permitAll()//允许所有的用户访问登录或者登出的路径,如果 .anyRequest().authenticated()注释掉,则必须添加permitAll(),否则就不能正常访问登录或者登出的路径.and().csrf().disable().authorizeRequests()//授权方法,该方法后有若干子方法进行不同的授权规则处理//允许所有账户都可访问(不登录即可访问),同时可指定多个路径
//                .antMatchers("/register").permitAll()//开发方式1:基于配置
//                .antMatchers("/a1","/a2").hasRole("seller")//拥有seller角色的用户可访问a1和a2资源//拥有指定的任意角色都可以访问对应资源
//                .antMatchers("/b1").hasAnyRole("manager1","manager2")//用户任意指定的aa bb都可以访问c1资源
//                .antMatchers("/c1").hasAnyAuthority("aa","bb")
//                .antMatchers("/d").denyAll()//拒绝任意用户访问
//                .antMatchers("/e").anonymous()//允许匿名访问//指定IP可以访问
//                .antMatchers("/f").hasIpAddress("localhost/82")
//                .antMatchers("/hello").hasAuthority("P5") //具有P5权限才可以访问
//                .antMatchers("/say").hasRole("ADMIN") //具有ROLE_ADMIN 角色才可以访问.anyRequest().authenticated(); //与注解@PermitAll冲突,需要注掉该行}

C.注解配置资源权限

在控制方法/URL的权限时, 可以通过配置类中配置的方式进行控制, 也可以使用 注解 @PreAuthorize 来进行控制, 推荐使用注解:

    /***  @PreAuthorize:指在注解作用的方法执行之前,做权限校验*  @PostAuthorize:指在注解作用的方法执行之后,做权限校验*  @return*/@PreAuthorize("hasAuthority('P5')")
//    @PostAuthorize("hasAuthority('P4')")@GetMapping("/hello")public String hello(){return "hello security";}@PreAuthorize("hasRole('ADMIN')")@GetMapping("/say")public String say(){return "say security";}@PermitAll//等价于antMatchers("/register").permitAll()//任何用户都可访问//@PreAuthorize("isAnonymous()")@GetMapping("/register")public String register(){return "register security";}

说明:使用@PreAuthorize,需要开启全局方法授权开关,加上注解@EnableGlobalMethodSecurity(prePostEnabled=true)

http://www.wangmingla.cn/news/67104.html

相关文章:

  • 做网站的背景图片要多大链接是什么意思
  • 查域名注册信息昆山seo网站优化软件
  • 刷单网站开发企业整站seo
  • 门户网站和新闻网站的区别天津百度推广代理商
  • 好用的wordpress主题鸡西seo
  • 企业网站 设计需求长沙网站优化方法
  • 网站管理助手 伪静态大兵seo博客
  • w网站怎么做百度推广的定义
  • 南京疫情最新通报seo推广宣传
  • 网站怎么做才能赚钱网站关键词搜索排名优化
  • 北京网站制作推广2022年免费云服务器
  • 网站运营是具体的推广码怎么填
  • 做国外商品的网站百度指数官网查询
  • 做移动网站点击软件广告网络推广
  • 重庆网络推广培训广州关键词seo
  • wordpress图片一排百度怎么优化网站排名
  • anew wordpress 下载丽水网站seo
  • 网站做反向代理后样式加载错误品牌营销策划怎么写
  • 做质粒图谱的网站百度下载安装到桌面
  • discuz做企业网站百度一下浏览器下载安装
  • wordpress无法下载杭州seo推广排名稳定
  • 微企申请网站深圳百度快照优化
  • wordpress程序网站信阳百度推广公司电话
  • 网站推广做招商加盟线上营销怎么推广
  • 网站详情页链接怎么做长沙网站优化对策
  • 云南建设人力资源网站seo站长综合查询
  • 烟台城发建设集团网站外链seo招聘
  • 沈阳企业免费建站微信营销的功能
  • 公司品牌网站建设价格低友链交易网
  • 做鸭网站关键词可以分为哪三类