# justauth-spring-security-starter **Repository Path**: luoqiz/justauth-spring-security-starter ## Basic Information - **Project Name**: justauth-spring-security-starter - **Description**: justauth-spring-security-starter 基于 justauth开发的认证并嫁接到 spring security 的认证上 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 7 - **Forks**: 0 - **Created**: 2019-11-26 - **Last Updated**: 2022-11-25 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README #justauth-spring-security-starter ##简介 spring security 认证实质是添加了一系列的Filter进行认证。所以此项目也是开发了一个Filter,并放在了认证链上的匿名用户过滤器前的位置。
此项目基于 justauth开发的认证并嫁接到 spring security 的认证上。
功能: 注意:目前系统内只实现了github、gitee、google ###使用 #### 自定义服务 ##### 自定义 JustauthAuthenticationService ``` @Slf4j public class WjwJustauthAuthenticationService extends AbstractJustauthAuthenticationService { 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 命令,打包到本地。项目中引入 ``` com.luoqiz.oauth2 justauth-spring-security-starter 0.0.1-SNAPSHOT ```