3 files modified
2 files added
| New file |
| | |
| | | package org.springblade.auth.config; |
| | | |
| | | import org.apache.logging.log4j.util.Strings; |
| | | import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint; |
| | | import org.springframework.security.core.AuthenticationException; |
| | | import javax.servlet.ServletException; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.nio.charset.StandardCharsets; |
| | | |
| | | public class CustomAuthenticationEntryPoint extends LoginUrlAuthenticationEntryPoint { |
| | | |
| | | public CustomAuthenticationEntryPoint(String loginFormUrl) { |
| | | super(loginFormUrl); |
| | | } |
| | | |
| | | @Override |
| | | public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { |
| | | String queryString = request.getQueryString(); |
| | | String query = !Strings.isBlank(queryString)?"?"+queryString:""; |
| | | String redirectUrl = getLoginFormUrl() + query; |
| | | response.sendRedirect(redirectUrl); |
| | | } |
| | | } |
| New file |
| | |
| | | package org.springblade.auth.config; |
| | | |
| | | import org.apache.logging.log4j.util.Strings; |
| | | import org.springframework.security.core.Authentication; |
| | | import org.springframework.security.web.authentication.AuthenticationSuccessHandler; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.util.Map; |
| | | |
| | | public class CustomAuthenticationSuccessHandler implements AuthenticationSuccessHandler { |
| | | |
| | | private String redirectUrl; |
| | | |
| | | public CustomAuthenticationSuccessHandler(String redirectUrl) { |
| | | this.redirectUrl = redirectUrl; |
| | | } |
| | | |
| | | @Override |
| | | public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException { |
| | | // String requestURI = request.getRequestURI(); |
| | | Map<String, String[]> parameterMap = request.getParameterMap(); |
| | | StringBuilder builder = new StringBuilder(); |
| | | if (parameterMap.size()>0){ |
| | | builder.append("?"); |
| | | } |
| | | String client_id = request.getHeader("client_id"); |
| | | String response_type = request.getHeader("response_type"); |
| | | String redirect_uri = request.getHeader("redirect_uri"); |
| | | // 拼接 |
| | | if (!Strings.isBlank(client_id)){ |
| | | builder.append("client_id=").append(client_id) |
| | | .append("&") |
| | | .append("response_type=").append(response_type) |
| | | .append("&") |
| | | .append("redirect_uri=").append(redirect_uri); |
| | | } |
| | | // 跳转 |
| | | response.sendRedirect(redirectUrl + builder.toString()); |
| | | } |
| | | } |
| | |
| | | protected void configure(HttpSecurity http) { |
| | | http.headers().frameOptions().disable(); |
| | | http.csrf().disable(); |
| | | http.formLogin().loginPage("/oauth/login").loginProcessingUrl("/oauth/form"); |
| | | http.formLogin() |
| | | //自定义认证成功跳转 |
| | | .successHandler(new CustomAuthenticationSuccessHandler("http://192.168.1.50:1888/api/oauth/authorize")) |
| | | .loginPage("http://192.168.1.50:1888/#/login") |
| | | // .loginPage("/oauth/login") |
| | | .loginProcessingUrl("/oauth/form"); |
| | | // 认证失败自定义登录页跳转 |
| | | http.exceptionHandling() |
| | | .authenticationEntryPoint(new CustomAuthenticationEntryPoint("http://192.168.1.50:1888/#/login")); |
| | | |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | import com.wf.captcha.SpecCaptcha; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.SneakyThrows; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springblade.common.cache.CacheNames; |
| | | import org.springblade.core.cache.utils.CacheUtil; |
| | |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.servlet.ModelAndView; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import javax.servlet.http.HttpSession; |
| | | import java.time.Duration; |
| | | |
| | | import static org.springblade.core.cache.constant.CacheConstant.*; |
| | | |
| | | /** |
| | |
| | | Properties props = System.getProperties(); |
| | | // 通用注册 |
| | | PropsUtil.setProperty(props, "spring.cloud.nacos.discovery.enabled", "false"); |
| | | PropsUtil.setProperty(props, "spring.cloud.nacos.discovery.server-addr", LauncherConstant.nacosAddr(profile)); |
| | | PropsUtil.setProperty(props, "spring.cloud.nacos.config.server-addr", LauncherConstant.nacosAddr(profile)); |
| | | PropsUtil.setProperty(props, "spring.cloud.nacos.username", LauncherConstant.NACOS_USERNAME); |
| | | PropsUtil.setProperty(props, "spring.cloud.nacos.password", LauncherConstant.NACOS_PASSWORD); |
| | | // PropsUtil.setProperty(props, "spring.cloud.nacos.discovery.server-addr", LauncherConstant.nacosAddr(profile)); |
| | | // PropsUtil.setProperty(props, "spring.cloud.nacos.config.server-addr", LauncherConstant.nacosAddr(profile)); |
| | | // PropsUtil.setProperty(props, "spring.cloud.nacos.username", LauncherConstant.NACOS_USERNAME); |
| | | // PropsUtil.setProperty(props, "spring.cloud.nacos.password", LauncherConstant.NACOS_PASSWORD); |
| | | // PropsUtil.setProperty(props, "spring.cloud.sentinel.transport.dashboard", LauncherConstant.sentinelAddr(profile)); |
| | | // PropsUtil.setProperty(props, "spring.zipkin.base-url", LauncherConstant.zipkinAddr(profile)); |
| | | // 多数据源 |
| | | PropsUtil.setProperty(props, "spring.datasource.dynamic.enabled", "false"); |
| | | // 开启鉴权 |
| | | // PropsUtil.setProperty(props, "blade.secure.enabled", "true"); |
| | | |
| | | // 开启elk日志 |
| | | // PropsUtil.setProperty(props, "blade.log.elk.destination", LauncherConstant.elkAddr(profile)); |