使用activiti7整合swagger2访问拦截跳转了登录页

使用activiti7,发现访问swagger2时被拦截,跳转了登录页。
在这里插入图片描述
看到这个登录界面,就感觉到不对劲了,去翻了一下启动日志,果然是Spring Security导致的。
在这里插入图片描述
因为确定没有主动引入Spring Security的jar包,那肯定就是activiti7的依赖了,翻了翻activiti7,确实存在Spring Security的依赖
在这里插入图片描述
针对这种情况也很无奈,只能是添加些Spring Security的配置了。
第一步:先设置一下自定义登录密码,默认生成的密码用起来很麻烦,这里说一下,默认的密码对应的默认账号是user,密码就是上面那个启动日志里自动生成的。

spring:
	security:
		user:
			name: root
			password: 123456

在application.yml中添加👆🏻这些配置,就可以实现自定义登录账号密码了。

第二步:添加securityConfig配置文件

package com.enjoy.approval.config;

import org.springframework.context.annotation.Bean;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.SecurityFilterChain;

/**
 * security配置
 * @author wangyl
 * @da
 */
@EnableWebSecurity
public class WebSecurityConfigurer {

    @Bean
    public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception {

        return httpSecurity
                .headers().frameOptions().disable()
                .and().authorizeRequests()
                .antMatchers("/swagger-ui.html",
                        "/doc.html"
                ).permitAll()
                .anyRequest().authenticated()
                .and()
                .httpBasic().and()
                .csrf()
                .disable()
                .build();
    }
}

.antMatchers().permitAll() 是用来排除校验的,可以把不需要经过权限校验的接口或者包路径添加到这里面。
.csrf().disable() 是用来解决POST请求跨域403报错问题的。

OK,重新启动一下服务,在启动日志中就看不到Using generated security password这条提示了,此时打开swagger2,弹出登录框,输入预先设定的账号密码,登录成功,就可以看到接口文档啦。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值