700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 如何使用postman访问若依后台权限功能

如何使用postman访问若依后台权限功能

时间:2019-05-01 10:35:34

相关推荐

如何使用postman访问若依后台权限功能

1.前言

今天需要使用postman测试一下后端代码,但是访问方法需要登录权限,在询问了前辈后了解了解决方法,特此记录。

2. 解决方法

首先将想要测试的方法上的权限注解注释掉

@PreAuthorize("@ss.hasPermi(‘system:project:list’)")注释的这里表示方法的请求URL。

//@PreAuthorize("@ss.hasPermi('system:project:list')")@GetMapping("/list")public TableDataInfo list(SysProjectVO sysProjectVO){startPage();List<SysProject> list = sysProjectService.selectSysProjectList(sysProjectVO);return getDataTable(list);}

然后找到framework/config/SecurityConfig

protected void configure(HttpSecurity httpSecurity) throws Exception{httpSecurity// CRSF禁用,因为不使用session.csrf().disable()// 认证失败处理类.exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()// 基于token,所以不需要session.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()// 过滤请求.authorizeRequests()// 对于登录login 验证码captchaImage 允许匿名访问.antMatchers("/login", "/captchaImage").anonymous().antMatchers(HttpMethod.GET,"/*.html","/**/*.html","/**/*.css","/**/*.js").permitAll().antMatchers("/profile/**").anonymous().antMatchers("/common/download**").anonymous().antMatchers("/common/download/resource**").anonymous().antMatchers("/swagger-ui.html").anonymous().antMatchers("/swagger-resources/**").anonymous().antMatchers("/webjars/**").anonymous().antMatchers("/*/api-docs").anonymous().antMatchers("/druid/**").anonymous().antMatchers("/ctwing/receive**").anonymous().antMatchers("/ctwing/receive/getDate**").anonymous()//在这里添加想要测试的方法访问URL,后面添加匿名访问的权限permitAll().antMatchers("/system/project/list").permitAll()// 除上面外的所有请求全部需要鉴权认证.anyRequest().authenticated().and().headers().frameOptions().disable();httpSecurity.logout().logoutUrl("/logout").logoutSuccessHandler(logoutSuccessHandler);// 添加JWT filterhttpSecurity.addFilterBefore(authenticationTokenFilter, UsernamePasswordAuthenticationFilter.class);}

完成上面的工作就可以使用postman测试了。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。