1 Star 7 Fork 0

luoqiz / justauth-spring-security-starter

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

#justauth-spring-security-starter

##简介 spring security 认证实质是添加了一系列的Filter进行认证。所以此项目也是开发了一个Filter,并放在了认证链上的匿名用户过滤器前的位置。
此项目基于 justauth开发的认证并嫁接到 spring security 的认证上。
功能:

  • 未认证用户经第三方认证后走认证流程
  • 已认证用户经第三方认证后走注册流程
  • 查看用户绑定记录
  • 解绑用户
注意:目前系统内只实现了github、gitee、google ###使用

自定义服务

自定义 JustauthAuthenticationService
@Slf4j
public class WjwJustauthAuthenticationService<A> extends AbstractJustauthAuthenticationService<AuthUser> {

    public WjwJustauthAuthenticationService(String providerId, AuthRequestFactory factory) {
        super(providerId, factory);
    }
}
AuthenticationFailureHandler 配置
@Component
public class AuthenticationFailureHandlerImpl implements AuthenticationFailureHandler {

    @Override
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException {
        if (exception instanceof JustauthAuthenticationRedirectException) {
            response.sendRedirect(((JustauthAuthenticationRedirectException) exception).getRedirectUrl());
            return;
        }
        response.setContentType("application/json;charset=UTF-8");
        Result result = Result.error(new BusinessException(BusinessExCodeEnum.LOGIN_ERROR));
        JSONObject json = new JSONObject(result);
        response.getWriter().write(json.toJSONString(0));
    }
}
WebSecurityConfigurer 配置
public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter {
    @Autowired
    AuthRequestFactory factory;

    @Autowired
    DataSource dataSource;

    @Autowired(required = false)
    private TextEncryptor encryptor;
    
    @Bean
    protected UsersConnectionRepository jdbcUsersConnectionRepository() {
        return new JdbcUsersConnectionRepository(dataSource, encryptor);
    }
     @Override
     protected void configure(HttpSecurity http) throws Exception {
        http...;
           JustAuthSocialConfigurer justauth = new JustAuthSocialConfigurer(factory, jdbcUsersConnectionRepository());
        //        justauth.setUsersConnectionRepository(jdbcUsersConnectionRepository());
                justauth.setUserDetailsService(sysUserService);
                justauth.setAuthenticationFailureHandler(authenticationFailureHandler);
                justauth.setAuthenticationSuccessHandler(authenticationSuccessHandler);
                justauth.addJustauthAuthenticationService("wjw", new WjwJustauthAuthenticationService("wjw", factory));
                http.apply(justauth);
     }
}
application.yml 配置
justauth:
  enabled: true
  type:
    github:
      client-id: 323a5*********297b
      client-secret: 380************32f33
      redirect-uri: http://********/justauth/github
    google:
      client-id: 15330************.apps.googleusercontent.com
      client-secret: gCzAl*************9sH
      redirect-uri: http://********/justauth/google
    gitee:
      client-id: 12f1d90************431db5c65d850d
      client-secret: ac29e60632*************be25cfc6d6e5ae2811e
      redirect-uri: http://********/justauth/gitee
  extend:
    enumClass: com.luoqiz.test.justauth.AuthCustomSource
    config:
      wjw:
        request-class: com.luoqiz.test.justauth.AuthWjwRequest
        client-id: Y***********A
        client-secret: d00955f*************3005fcd109
        redirect-uri: http://test.luoqiz.top/justauth/wjw

引用使用

目前尚未完善,所以未将其上传到maven仓库中心。
本地导入方法将项目下载下来后,执行 maven install 命令,打包到本地。项目中引入

        <dependency>
            <groupId>com.luoqiz.oauth2</groupId>
            <artifactId>justauth-spring-security-starter</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

空文件

简介

justauth-spring-security-starter 基于 justauth开发的认证并嫁接到 spring security 的认证上 展开 收起
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/luoqiz/justauth-spring-security-starter.git
git@gitee.com:luoqiz/justauth-spring-security-starter.git
luoqiz
justauth-spring-security-starter
justauth-spring-security-starter
master

搜索帮助