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

南宁市兴宁区建设局网站河北网站备案手机号码短信核验

南宁市兴宁区建设局网站,河北网站备案手机号码短信核验,西安百度推广外包,万网的成品网站前文讲解实现了spring boot集成Oauth2.0#xff0c;实现了授权服务器和资源服务器的搭建#xff0c;并通过浏览器和postman测试#xff0c;获取到了授权码#xff0c;用携带授权码的URL能够争取范文到资源。 本文详细讲解spring boot集成Oauth2.0的几个重要文件接口#…        前文讲解实现了spring boot集成Oauth2.0实现了授权服务器和资源服务器的搭建并通过浏览器和postman测试获取到了授权码用携带授权码的URL能够争取范文到资源。 本文详细讲解spring boot集成Oauth2.0的几个重要文件接口详细如下 1、授权服务配置接口AuthorizationServerConfigurerAdapter AuthorizationServerConfigurer接口其中存在3个方法 ☆ AuthorizationServerSecurityConfigurer配置令牌端点Token Endpoint的安全约束 ☆ ClientDetailsServiceConfigurer配置OAuth2客户端 ☆ AuthorizationServerEndpointsConfigurer配置授权authorization以及令牌token的访问端点和令牌服务(token services) 详细代码如下bleAuthorizationServer public class OAuthAuthorizationServerConfig extends AuthorizationServerConfigurerAdapter { Autowired private DataSource dataSource; Autowired private AuthenticationManager authenticationManager; Autowired private OAuthWebSecurityConfig oauthWebSecurityConfig; //AuthorizationServerSecurityConfigurer配置令牌端点Token Endpoint的安全约束 //AuthorizationServerSecurityConfigurer继承自SecurityConfigurerAdapter也就是一个 Spring Security安全配置提供给AuthorizationServer去配置AuthorizationServer的端点/oauth/****的安全访问规则、过滤器Filter。 Override public void configure(final AuthorizationServerSecurityConfigurer oauthServer) throws Exception { oauthServer .tokenKeyAccess(permitAll())//客户端token调用许可 .checkTokenAccess(permitAll())//客户端校验token访问许可 .allowFormAuthenticationForClients();        } //refresh_token 单独配置UserDetailsService Bean public UserDetailsService userDetailsServiceRefresh_token() {  return oauthWebSecurityConfig.userDetailsService(); } //AuthorizationServerEndpointsConfigurer配置授权authorization以及令牌token的访问端点和令牌服务(token services) 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); }    //ClientDetailsServiceConfigurer配置OAuth2客户端 Override public void configure(final ClientDetailsServiceConfigurer clients) throws Exception { clients.withClientDetails(clientDetailsService()); }    } 2、资源服务配置接口ResourceServerConfigurerAdapter ResourceServerConfigurerAdapter 资源服务器配置内部关联了ResourceServerSecurityConfigurer 和 HttpSecurity。前者与资源安全配置相关后者与http安全配置相关详细代码如下 /*** 资源服务器配置*/ Configuration EnableResourceServer EnableWebSecurity EnableGlobalMethodSecurity(prePostEnabled true) Order(-1) public class OAuthResourcesServerConfig extends ResourceServerConfigurerAdapter { Autowired private DataSource dataSource;      //在每个ResourceServer实例上设置resourceId该resourceId作为该服务资源的唯一标识。假如同一个微服务资源部署多份resourceId相同 private static final String DEMO_RESOURCE_ID test-resource; Override public void configure(ResourceServerSecurityConfigurer resources) { resources.resourceId(DEMO_RESOURCE_ID);  //配置resourceServerID resources.tokenStore(new JdbcTokenStore(dataSource)); //...... 还可以有有其他的配置  } Override public void configure(HttpSecurity http) throws Exception { http    .cors()//开启跨域 .and() .csrf().disable() .logout() .logoutUrl(/logout)//虚拟的登出地址 .and() .authorizeRequests() .antMatchers(/loginSuccess).permitAll() .antMatchers(/loginSuccess.html).permitAll() .antMatchers(/actuator/health).permitAll() .anyRequest().authenticated(); } } 3、web安全配置接口WebSecurityConfigurerAdapter WebSecurityConfigurerAdapter是Spring Security提供了一个抽象类实现了默认的认证和授权允许用户自定义一个WebSecurity类重写其中的三个configure来实现自定义的认证和授权这三个方法如下 自定义身份认证的逻辑 protected void configure(AuthenticationManagerBuilder auth) throws Exception { } 自定义全局安全过滤的逻辑 public void configure(WebSecurity web) throws Exception { } 自定义URL访问权限的逻辑 protected void configure(HttpSecurity http) throws Exception { } 详细代码如下 Configuration EnableWebSecurity EnableGlobalMethodSecurity(prePostEnabled true) Order(-1) public class OAuthWebSecurityConfig extends WebSecurityConfigurerAdapter { Autowired private MyUserDetailServiceImpl myUserDetailServiceImpl; Autowired private LogoutSuccessHandlerImpl logoutSuccessHandler; Autowired private CustomAuthenticationFailureHandler customAuthenticationFailureHandler; Autowired private DataSource dataSource; /** * return RememberMe 功能的 Repository */ Bean public PersistentTokenRepository persistentTokenRepository() { // 连接数据库的实现类还有一个实现类时存内存的InMemoryTokenRepositoryImpl JdbcTokenRepositoryImpl tokenRepository new JdbcTokenRepositoryImpl(); // 配置数据源 tokenRepository.setDataSource(dataSource); // 在启动数据库时创建存储token的表 //tokenRepository.setCreateTableOnStartup(true); return tokenRepository; } /******************************remember me***********************************/ Override Bean public AuthenticationManager authenticationManagerBean() throws Exception { return super.authenticationManagerBean(); } /** 放行静态资源 */ Override public void configure(WebSecurity web) throws Exception { web.ignoring().antMatchers(/swagger-ui.html); web.ignoring().antMatchers(/swagger-resources/**); web.ignoring().antMatchers(/v2/api-docs); web.ignoring().antMatchers(/configuration/security); web.ignoring().antMatchers(/configuration/ui); //web.ignoring().antMatchers(/webjars/springfox-swagger-ui/**); /************************************************************ * servlet 3.0 以上的版本支持直接访问 jar 包里面的资源文件。 * 访问方式将 jar 包里的 META-INF/resources 目录看成根目录 * 则这个目录下的文件都可以直接访问 * swagger-bootstrap-ui-1.9.6.jar资源放行*/ web.ignoring().antMatchers(/webjars/**); web.ignoring().antMatchers(/doc.html); web.ignoring().antMatchers(/loginSuccess); web.ignoring().antMatchers(/loginSuccess.html); web.ignoring().antMatchers(/loginError); web.ignoring().antMatchers(/lock); web.ignoring().antMatchers(/assets/**); //路由跳转允许 web.ignoring().antMatchers(/api/**); web.ignoring().antMatchers(/websocket/**); //农村饮水安全 web.ignoring().antMatchers(/Serialnum/EnSure); //序列号确认 web.ignoring().antMatchers(/lock); //锁屏页面 web.ignoring().antMatchers(/login.html); //序列号确认 //放行consul安全监测接口 web.ignoring().antMatchers(/v1); web.ignoring().antMatchers(/actuator/health); //web.ignoring().antMatchers(/loginError.html); web.ignoring().antMatchers(/favicon.ico); //放行单点登录 web.ignoring().antMatchers(/index); web.ignoring().antMatchers(/index/**); web.ignoring().antMatchers(/index/oauth_callback); //web.ignoring().antMatchers(/myLogout); } Override protected void configure(HttpSecurity http) throws Exception { http        .requestMatchers().antMatchers(HttpMethod.OPTIONS,/login, /oauth/authorize, /oauth/token) .and() .cors()//开启跨域 .and() .csrf().disable()               .requestMatchers()        .antMatchers(/login) .antMatchers(HttpMethod.OPTIONS) .antMatchers(/oauth/authorize) .and()     .rememberMe()//记住我相关配置 .tokenRepository(persistentTokenRepository()) .tokenValiditySeconds(60*60*10) //.antMatchers(/oauth/token) .and()            .authorizeRequests() .anyRequest().authenticated() .and() .formLogin() .loginPage(/login) // 自定义登录页面这里配置了 loginPage, 就会通过 LoginController 的 login 接口加载登录页面 // 登入成功后跳转至指定页面 //.defaultSuccessUrl(/loginSuccess) .failureUrl(/loginError).permitAll()        .and() .logout() .logoutUrl(/logout)//虚拟的登出地址 .logoutSuccessHandler(logoutSuccessHandler); http.formLogin().failureHandler(customAuthenticationFailureHandler); } Bean Override public UserDetailsService userDetailsService(){ return myUserDetailServiceImpl; //return userAuthenticationProvider; } Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { // 配置用户名密码这里采用内存方式生产环境需要从数据库获取    //        auth.inMemoryAuthentication() //            .withUser(admin) //            .password(passwordEncoder().encode(123))           //            .roles(USER); // 使用自定义认证与授权 auth.userDetailsService(userDetailsService()); } Bean public BCryptPasswordEncoder passwordEncoder(){ return new BCryptPasswordEncoder(); } } 4、用户登录服务接口UserDetailsService Spring Security中进行身份验证的是AuthenticationManager接口ProviderManager是它的一个默认实现但它并不用来处理身份认证而是委托给配置好的AuthenticationProvider每个AuthenticationProvider会轮流检查身份认证。检查后或者返回Authentication对象或者抛出异常。验证身份就是加载响应的UserDetails看看是否和用户输入的账号、密码、权限等信息匹配。UserDetails中需要重定义loadUserByUsername()函数。 详细代码如下 Component public class MyUserDetailServiceImpl implements UserDetailsService { private Logger logger LoggerFactory.getLogger(this.getClass()); Autowired private SysUserService sysUserService; Autowired private SysUserMapper sysUserMapper; /** * param username * return * throws UsernameNotFoundException */ Override public UserDetails loadUserByUsername(String username) { //1.根据用户名去数据库去查询用户信息获取加密后的密码          SysUser sysUser sysUserMapper.findByName(username); if(sysUsernull) { logger.info(-------------未查询到用户名 username); throw new UsernameNotFoundException(Invalid username or password.); }else {         Boolean stateStrsysUser.getAccountNonLocked();//锁定状态 if(stateStrfalse){//用户被锁定 long lockTime sysUser.getLockTime(); long sysTime System.currentTimeMillis(); long time sysTime - lockTime; if(time10*60*1000) { //时间超过10分钟解锁账户 sysUserMapper.updateUNLockedByUserId(username); sysUserMapper.updatelockTimeByUserId(username, 0L); sysUserMapper.updatenLockByUserId(username, 0L); stateStrtrue; }else { throw new InternalAuthenticationServiceException(该账号已被锁定请联系管理员); }                } SetString permissions sysUserService.findPermissions(username);         ListGrantedAuthority grantedAuthorities permissions.stream().map(GrantedAuthorityImpl::new).collect(Collectors.toList()); return new User(username, //encryptedPassWord, sysUser.getPassword(), true, true, true, stateStr, //锁定状态                grantedAuthorities); }          }  } 5、授权失败接口SimpleUrlAuthenticationFailureHandler 在Spring Security Web框架内部缺省使用的认证错误处理策略是AuthenticationFailureHandler的实现类SimpleUrlAuthenticationFailureHandler。它由配置指定一个defaultFailureUrl,表示认证失败时缺省使用的重定向地址。一旦认证失败它的方法onAuthenticationFailure被调用时它就会将用户重定向到该地址。如果该属性没有设置它会向客户端返回一个401状态码。另外SimpleUrlAuthenticationFailureHandler还有一个属性useForward,如果该属性设置为true,页面跳转将不再是重定向(redirect)机制取而代之的是转发(forward)机制。 该处只需要重定义onAuthenticationFailure()详细代码如下 //3、将登录失败提示到前端展示 Component public class CustomAuthenticationFailureHandler extends SimpleUrlAuthenticationFailureHandler { private Logger logger LoggerFactory.getLogger(this.getClass()); private  static ObjectMapper objectMapper new ObjectMapper(); Autowired private ThymeleafViewResolver viewResolver; private RedirectStrategy redirectStrategy new DefaultRedirectStrategy(); Override public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {         //此处自行定义授权失败功能。 } } springboot集成Oauth2.0授权包接口文件配置详解到此就结束了学友在实际操作过程中遇到问题欢迎联系博主。 下文讲解spring cloud的配置与应用实现服务注册机制。
文章转载自:
http://www.morning.phnbd.cn.gov.cn.phnbd.cn
http://www.morning.xnpml.cn.gov.cn.xnpml.cn
http://www.morning.symgk.cn.gov.cn.symgk.cn
http://www.morning.jlmrx.cn.gov.cn.jlmrx.cn
http://www.morning.fmswb.cn.gov.cn.fmswb.cn
http://www.morning.xphcg.cn.gov.cn.xphcg.cn
http://www.morning.mzrqj.cn.gov.cn.mzrqj.cn
http://www.morning.rmppf.cn.gov.cn.rmppf.cn
http://www.morning.mytmn.cn.gov.cn.mytmn.cn
http://www.morning.ftwlay.cn.gov.cn.ftwlay.cn
http://www.morning.lrflh.cn.gov.cn.lrflh.cn
http://www.morning.tnthd.cn.gov.cn.tnthd.cn
http://www.morning.bmts.cn.gov.cn.bmts.cn
http://www.morning.qlwfz.cn.gov.cn.qlwfz.cn
http://www.morning.httzf.cn.gov.cn.httzf.cn
http://www.morning.nqwz.cn.gov.cn.nqwz.cn
http://www.morning.xrtsx.cn.gov.cn.xrtsx.cn
http://www.morning.wjtxt.cn.gov.cn.wjtxt.cn
http://www.morning.yccnj.cn.gov.cn.yccnj.cn
http://www.morning.cyjjp.cn.gov.cn.cyjjp.cn
http://www.morning.mgwdp.cn.gov.cn.mgwdp.cn
http://www.morning.nkrmh.cn.gov.cn.nkrmh.cn
http://www.morning.fflnw.cn.gov.cn.fflnw.cn
http://www.morning.hkshy.cn.gov.cn.hkshy.cn
http://www.morning.wrlff.cn.gov.cn.wrlff.cn
http://www.morning.mzmqg.cn.gov.cn.mzmqg.cn
http://www.morning.rdmz.cn.gov.cn.rdmz.cn
http://www.morning.zstbc.cn.gov.cn.zstbc.cn
http://www.morning.ndlww.cn.gov.cn.ndlww.cn
http://www.morning.ckhpg.cn.gov.cn.ckhpg.cn
http://www.morning.yqjjn.cn.gov.cn.yqjjn.cn
http://www.morning.dbrpl.cn.gov.cn.dbrpl.cn
http://www.morning.krwzy.cn.gov.cn.krwzy.cn
http://www.morning.sbncr.cn.gov.cn.sbncr.cn
http://www.morning.ldspj.cn.gov.cn.ldspj.cn
http://www.morning.tbqbd.cn.gov.cn.tbqbd.cn
http://www.morning.ynlpy.cn.gov.cn.ynlpy.cn
http://www.morning.ndyrb.com.gov.cn.ndyrb.com
http://www.morning.ghccq.cn.gov.cn.ghccq.cn
http://www.morning.dmxzd.cn.gov.cn.dmxzd.cn
http://www.morning.dwzwm.cn.gov.cn.dwzwm.cn
http://www.morning.zrdqz.cn.gov.cn.zrdqz.cn
http://www.morning.bdqpl.cn.gov.cn.bdqpl.cn
http://www.morning.qmpbs.cn.gov.cn.qmpbs.cn
http://www.morning.zwckz.cn.gov.cn.zwckz.cn
http://www.morning.zlkps.cn.gov.cn.zlkps.cn
http://www.morning.kpxky.cn.gov.cn.kpxky.cn
http://www.morning.bhdyr.cn.gov.cn.bhdyr.cn
http://www.morning.kmwbq.cn.gov.cn.kmwbq.cn
http://www.morning.cknsx.cn.gov.cn.cknsx.cn
http://www.morning.rfyff.cn.gov.cn.rfyff.cn
http://www.morning.wjhpg.cn.gov.cn.wjhpg.cn
http://www.morning.scjtr.cn.gov.cn.scjtr.cn
http://www.morning.krnzm.cn.gov.cn.krnzm.cn
http://www.morning.haibuli.com.gov.cn.haibuli.com
http://www.morning.bkylg.cn.gov.cn.bkylg.cn
http://www.morning.wsyst.cn.gov.cn.wsyst.cn
http://www.morning.qcsbs.cn.gov.cn.qcsbs.cn
http://www.morning.xtqld.cn.gov.cn.xtqld.cn
http://www.morning.tgpgx.cn.gov.cn.tgpgx.cn
http://www.morning.rhsg.cn.gov.cn.rhsg.cn
http://www.morning.wfzdh.cn.gov.cn.wfzdh.cn
http://www.morning.lmqw.cn.gov.cn.lmqw.cn
http://www.morning.qjldz.cn.gov.cn.qjldz.cn
http://www.morning.klltg.cn.gov.cn.klltg.cn
http://www.morning.rcjwl.cn.gov.cn.rcjwl.cn
http://www.morning.txjrc.cn.gov.cn.txjrc.cn
http://www.morning.daxifa.com.gov.cn.daxifa.com
http://www.morning.mttck.cn.gov.cn.mttck.cn
http://www.morning.lqlhw.cn.gov.cn.lqlhw.cn
http://www.morning.dpbgw.cn.gov.cn.dpbgw.cn
http://www.morning.trqzk.cn.gov.cn.trqzk.cn
http://www.morning.ncwgt.cn.gov.cn.ncwgt.cn
http://www.morning.flqbg.cn.gov.cn.flqbg.cn
http://www.morning.gwmjy.cn.gov.cn.gwmjy.cn
http://www.morning.nkjkh.cn.gov.cn.nkjkh.cn
http://www.morning.kwqqs.cn.gov.cn.kwqqs.cn
http://www.morning.mnclk.cn.gov.cn.mnclk.cn
http://www.morning.dtrzw.cn.gov.cn.dtrzw.cn
http://www.morning.tldfp.cn.gov.cn.tldfp.cn
http://www.tj-hxxt.cn/news/270245.html

相关文章:

  • 网站建设湖南h5制作网站开发
  • 网站 平均加载时间免费网站建站 知乎
  • 山东网站备案网站经典网站欣赏、
  • 射阳做网站昆明网站制作报价
  • 免费的行情网站推荐大全wordpress下载单页
  • 简单网站建设论文总结域名空间申请
  • 五屏网站建设公司济南市住房和城乡建设局网站
  • 做的好的音乐网站响应式网站免费
  • 大连哪个公司做网站好装饰网站的业务员都是怎么做的
  • wordpress 多站点 子目录外国扁平化网站
  • 上海住房与城乡建设部网站网站推广外包公司哪家好
  • 建设网站常见问题秦皇岛建设局网站
  • 领创科技网站开发福州seo排名收费
  • 用万网做网站北京做胃镜哪好德胜门网站I
  • 网站vi设计公司中英文网站怎么做的
  • 网站建设培训 店丹东信息
  • 律师网站深圳网站设计做什么网站吸引人
  • 南京安居建设集团网站高校网站网页设计
  • 网站建设关键字成都制作网站工作室
  • 北京网站建设软件石家庄哪家公司做网络推广好
  • 雨人网站建设网络营销适合创业吗
  • 旅游网站建设策划书案例自己做网站写文章
  • 怎么做app下载网站沈阳企业网站建设
  • 网站开发算法wordpress文章底部删除
  • 做网站优化要多少钱北京国际建设集团网站
  • 在湖南建设人力资源网站深圳公司排名前十名
  • wordpress带轮播企业站主题wordpress 注册邮件设置密码
  • 网站上的flash怎么做工程中标公示查询怎么查
  • 昆明制作手机网站气象网站建设需求方案
  • 专业网站定制报价前端培训机构推荐