org.springframework.security.web.authentication.AuthenticationSuccessHandler Java Examples

The following examples show how to use org.springframework.security.web.authentication.AuthenticationSuccessHandler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IdolSecurityCustomizerImpl.java    From find with MIT License 6 votes vote down vote up
@SuppressWarnings("ProhibitedExceptionDeclared")
@Override
public void customize(final HttpSecurity http, final AuthenticationManager authenticationManager) throws Exception {
    final AuthenticationSuccessHandler successHandler = new IdolLoginSuccessHandler(
            FindController.CONFIG_PATH,
            FindController.APP_PATH,
            FindRole.CONFIG.toString(),
            authenticationInformationRetriever
    );

    http.formLogin()
            .loginPage(FindController.DEFAULT_LOGIN_PAGE)
            .loginProcessingUrl("/authenticate")
            .successHandler(successHandler)
            .failureUrl(FindController.DEFAULT_LOGIN_PAGE + "?error=auth");
}
 
Example #2
Source File: WebSecurityConfig.java    From jeesupport with MIT License 6 votes vote down vote up
/**
 * 登陆成功后的处理
 *
 * @return
 */
@Bean
public AuthenticationSuccessHandler successHandler(){
    return new AuthenticationSuccessHandler(){
        @Override
        public void onAuthenticationSuccess( HttpServletRequest _request, HttpServletResponse _response, Authentication _auth ) throws IOException, ServletException{
            log.debug( "--登陆成功" );

            _request.getSession().setAttribute( ISupportEL.Session_User_EL, _auth.getPrincipal() );
            sessionRegistry().registerNewSession( _request.getSession().getId(), _auth.getPrincipal() );

            RequestCache requestCache = new HttpSessionRequestCache();

            SavedRequest savedRequest = requestCache.getRequest( _request, _response );
            String       url          = null;
            if( savedRequest != null ) url = savedRequest.getRedirectUrl();
            log.debug( "--登陆后转向:" + url );

            if( url == null ) redirectStrategy().sendRedirect( _request, _response, "/" );
            else _response.sendRedirect( url );
        }
    };
}
 
Example #3
Source File: SecurityHandlerConfig.java    From open-capacity-platform with Apache License 2.0 6 votes vote down vote up
/**
 * 登陆成功,返回Token 装配此bean不支持授权码模式
 * 
 * @return
 */
@Bean
public AuthenticationSuccessHandler loginSuccessHandler() {
	return new SavedRequestAwareAuthenticationSuccessHandler() {

		private RequestCache requestCache = new HttpSessionRequestCache();

		@Override
		public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
				Authentication authentication) throws IOException, ServletException {

			super.onAuthenticationSuccess(request, response, authentication);
			return;

		}
	};
}
 
Example #4
Source File: SmsSecurityConfig.java    From oauth-boot with MIT License 6 votes vote down vote up
public SmsSecurityConfig(BootSmsUserDetailService userDetailsService,
                         StringRedisTemplate redisTemplate,
                         @Autowired(required = false)
                                 BootLoginFailureHandler failureHandler,
                         @Autowired(required = false)
                                 AuthenticationSuccessHandler successHandler,
                         BootSecurityProperties properties) {


    this.authenticationFilter = new SmsCodeAuthenticationFilter(properties.getSmsLogin().getLoginProcessUrl());
    this.authenticationFilter.setAuthenticationFailureHandler(failureHandler);
    if (successHandler!=null) {
        this.authenticationFilter.setAuthenticationSuccessHandler(successHandler);
    }

    this.authenticationProvider = new SmsAuthenticationProvider();
    this.authenticationProvider.setUserDetailsService(userDetailsService);

    this.codeCheckFilter = new SmsCodeCheckFilter(properties);
    this.codeCheckFilter.setFailureHandler(failureHandler);
    this.codeCheckFilter.setTemplate(redisTemplate);
    this.codeCheckFilter.setSuccessHandler(successHandler);


}
 
Example #5
Source File: WebSecurityConfig.java    From spring-security with Apache License 2.0 6 votes vote down vote up
@Bean
public AuthenticationSuccessHandler authenticationSuccessHandler() {
    return new AuthenticationSuccessHandler() {
        /**
         * 处理登入成功的请求
         *
         * @param httpServletRequest
         * @param httpServletResponse
         * @param authentication
         * @throws IOException
         * @throws ServletException
         */
        @Override
        public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
            httpServletResponse.setContentType("application/json;charset=utf-8");
            PrintWriter out = httpServletResponse.getWriter();
            out.write("{\"status\":\"success\",\"msg\":\"登录成功\"}");
            out.flush();
            out.close();
        }
    };
}
 
Example #6
Source File: WebSecurityConfig.java    From spring-security with Apache License 2.0 6 votes vote down vote up
@Bean
public AuthenticationSuccessHandler authenticationSuccessHandler() {
    return new AuthenticationSuccessHandler() {
        /**
         * 处理登入成功的请求
         *
         * @param httpServletRequest
         * @param httpServletResponse
         * @param authentication
         * @throws IOException
         * @throws ServletException
         */
        @Override
        public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
            httpServletResponse.setContentType("application/json;charset=utf-8");
            PrintWriter out = httpServletResponse.getWriter();
            out.write("{\"status\":\"success\",\"msg\":\"登录成功\"}");
            out.flush();
            out.close();
        }
    };
}
 
Example #7
Source File: QueryFilter.java    From api-layer with Eclipse Public License 2.0 6 votes vote down vote up
public QueryFilter(
    String authEndpoint,
    AuthenticationSuccessHandler successHandler,
    AuthenticationFailureHandler failureHandler,
    AuthenticationService authenticationService,
    HttpMethod httpMethod,
    boolean protectedByCertificate,
    AuthenticationManager authenticationManager) {
    super(authEndpoint);
    this.successHandler = successHandler;
    this.failureHandler = failureHandler;
    this.authenticationService = authenticationService;
    this.httpMethod = httpMethod;
    this.protectedByCertificate = protectedByCertificate;
    this.setAuthenticationManager(authenticationManager);
}
 
Example #8
Source File: LoginFilter.java    From api-layer with Eclipse Public License 2.0 5 votes vote down vote up
public LoginFilter(
    String authEndpoint,
    AuthenticationSuccessHandler successHandler,
    AuthenticationFailureHandler failureHandler,
    ObjectMapper mapper,
    AuthenticationManager authenticationManager,
    ResourceAccessExceptionHandler resourceAccessExceptionHandler) {
    super(authEndpoint);
    this.successHandler = successHandler;
    this.failureHandler = failureHandler;
    this.mapper = mapper;
    this.resourceAccessExceptionHandler = resourceAccessExceptionHandler;
    this.setAuthenticationManager(authenticationManager);
}
 
Example #9
Source File: WechatAuthenticationConfigurer.java    From fast-family-master with Apache License 2.0 5 votes vote down vote up
public WechatAuthenticationConfigurer(WxMpService wxMpService, UserDetailsService userDetailsService,
                                      AuthenticationFailureHandler authenticationFailureHandler,
                                      AuthenticationSuccessHandler authenticationSuccessHandler) {
    this.wxMpService = wxMpService;
    this.userDetailsService = userDetailsService;
    this.authenticationFailureHandler = authenticationFailureHandler;
    this.authenticationSuccessHandler = authenticationSuccessHandler;
}
 
Example #10
Source File: CrowdSecurityConfiguration.java    From ods-provisioning-app with Apache License 2.0 5 votes vote down vote up
/**
 * Define a success handler to proceed after a crowd authentication, if it has been successful
 *
 * @return
 */
@Bean
public AuthenticationSuccessHandler authenticationSuccessHandler() {
  SavedRequestAwareAuthenticationSuccessHandler successHandler =
      new SavedRequestAwareAuthenticationSuccessHandler();
  successHandler.setDefaultTargetUrl("/home");
  successHandler.setUseReferer(true);
  successHandler.setAlwaysUseDefaultTargetUrl(true);
  return successHandler;
}
 
Example #11
Source File: InMemoryHodSecurity.java    From find with MIT License 5 votes vote down vote up
@SuppressWarnings("ProhibitedExceptionDeclared")
@Override
protected void configure(final HttpSecurity http) throws Exception {
    final AuthenticationSuccessHandler loginSuccessHandler = new LoginSuccessHandler(FindRole.CONFIG.toString(), FindController.CONFIG_PATH, "/p/");
    final HttpSessionRequestCache requestCache = new HttpSessionRequestCache();

    requestCache.setRequestMatcher(new OrRequestMatcher(
            new AntPathRequestMatcher("/p/**"),
            new AntPathRequestMatcher(FindController.CONFIG_PATH)
    ));

    http.regexMatcher("/p/.*|/config/.*|/authenticate|/logout")
        .authorizeRequests()
            .antMatchers("/p/**").hasRole(FindRole.ADMIN.name())
            .antMatchers(FindController.CONFIG_PATH).hasRole(FindRole.CONFIG.name())
            .and()
        .requestCache()
            .requestCache(requestCache)
            .and()
        .formLogin()
            .loginPage(FindController.DEFAULT_LOGIN_PAGE)
            .loginProcessingUrl("/authenticate")
            .successHandler(loginSuccessHandler)
            .failureUrl(FindController.DEFAULT_LOGIN_PAGE + "?error=auth")
            .and()
        .logout()
            .logoutSuccessHandler(new HodLogoutSuccessHandler(new HodTokenLogoutSuccessHandler(SsoController.SSO_LOGOUT_PAGE, tokenRepository), FindController.APP_PATH))
            .and()
        .csrf()
            .disable();
}
 
Example #12
Source File: AjaxLoginProcessingFilter.java    From springboot-security-jwt with MIT License 5 votes vote down vote up
public AjaxLoginProcessingFilter(String defaultProcessUrl, AuthenticationSuccessHandler successHandler, 
        AuthenticationFailureHandler failureHandler, ObjectMapper mapper) {
    super(defaultProcessUrl);
    this.successHandler = successHandler;
    this.failureHandler = failureHandler;
    this.objectMapper = mapper;
}
 
Example #13
Source File: RefreshTokenProcessingFilter.java    From Groza with Apache License 2.0 5 votes vote down vote up
public RefreshTokenProcessingFilter(String defaultProcessUrl, AuthenticationSuccessHandler successHandler,
                                    AuthenticationFailureHandler failureHandler, ObjectMapper mapper) {
    super(defaultProcessUrl);
    this.successHandler = successHandler;
    this.failureHandler = failureHandler;
    this.objectMapper = mapper;
}
 
Example #14
Source File: RestPublicLoginProcessingFilter.java    From Groza with Apache License 2.0 5 votes vote down vote up
public RestPublicLoginProcessingFilter(String defaultProcessUrl, AuthenticationSuccessHandler successHandler,
                                       AuthenticationFailureHandler failureHandler, ObjectMapper mapper) {
    super(defaultProcessUrl);
    this.successHandler = successHandler;
    this.failureHandler = failureHandler;
    this.objectMapper = mapper;
}
 
Example #15
Source File: RestLoginProcessingFilter.java    From Groza with Apache License 2.0 5 votes vote down vote up
public RestLoginProcessingFilter(String defaultProcessUrl, AuthenticationSuccessHandler successHandler,
                                 AuthenticationFailureHandler failureHandler, ObjectMapper mapper) {
    super(defaultProcessUrl);
    this.successHandler = successHandler;
    this.failureHandler = failureHandler;
    this.objectMapper = mapper;
}
 
Example #16
Source File: WebSecurityConfigurer.java    From smaker with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Bean
public AuthenticationSuccessHandler mobileLoginSuccessHandler() {
	return MobileLoginSuccessHandler.builder()
		.objectMapper(objectMapper)
		.clientDetailsService(clientDetailsService)
		.passwordEncoder(passwordEncoder())
		.defaultAuthorizationServerTokenServices(defaultAuthorizationServerTokenServices).build();
}
 
Example #17
Source File: OpenIdAuthenticationSecurityConfig.java    From paascloud-master with Apache License 2.0 5 votes vote down vote up
@Autowired
public OpenIdAuthenticationSecurityConfig(AuthenticationSuccessHandler pcAuthenticationSuccessHandler, AuthenticationFailureHandler pcAuthenticationFailureHandler, SocialUserDetailsService userDetailsService, UsersConnectionRepository usersConnectionRepository) {
	this.pcAuthenticationSuccessHandler = pcAuthenticationSuccessHandler;
	this.pcAuthenticationFailureHandler = pcAuthenticationFailureHandler;
	this.userDetailsService = userDetailsService;
	this.usersConnectionRepository = usersConnectionRepository;
}
 
Example #18
Source File: RestLoginProcessingFilter.java    From iotplatform with Apache License 2.0 5 votes vote down vote up
public RestLoginProcessingFilter(String defaultProcessUrl, AuthenticationSuccessHandler successHandler,
    AuthenticationFailureHandler failureHandler, ObjectMapper mapper) {
  super(defaultProcessUrl);
  this.successHandler = successHandler;
  this.failureHandler = failureHandler;
  this.objectMapper = mapper;
}
 
Example #19
Source File: RestPublicLoginProcessingFilter.java    From iotplatform with Apache License 2.0 5 votes vote down vote up
public RestPublicLoginProcessingFilter(String defaultProcessUrl, AuthenticationSuccessHandler successHandler,
    AuthenticationFailureHandler failureHandler, ObjectMapper mapper) {
  super(defaultProcessUrl);
  this.successHandler = successHandler;
  this.failureHandler = failureHandler;
  this.objectMapper = mapper;
}
 
Example #20
Source File: RefreshTokenProcessingFilter.java    From iotplatform with Apache License 2.0 5 votes vote down vote up
public RefreshTokenProcessingFilter(String defaultProcessUrl, AuthenticationSuccessHandler successHandler,
    AuthenticationFailureHandler failureHandler, ObjectMapper mapper) {
  super(defaultProcessUrl);
  this.successHandler = successHandler;
  this.failureHandler = failureHandler;
  this.objectMapper = mapper;
}
 
Example #21
Source File: LoginProcessingFilter.java    From secrets-proxy with Apache License 2.0 5 votes vote down vote up
public LoginProcessingFilter(
    String loginUrl,
    AuthenticationSuccessHandler successHandler,
    AuthenticationFailureHandler failureHandler,
    ObjectMapper mapper) {
  super(loginUrl);
  log.info("Initializing Login processing filter for " + loginUrl);
  this.successHandler = successHandler;
  this.failureHandler = failureHandler;
  this.mapper = mapper;
}
 
Example #22
Source File: AjaxLoginProcessingFilter.java    From OpenLRW with Educational Community License v2.0 5 votes vote down vote up
public AjaxLoginProcessingFilter(String defaultProcessUrl, AuthenticationSuccessHandler successHandler, 
        AuthenticationFailureHandler failureHandler, ObjectMapper mapper) {
    super(defaultProcessUrl);
    this.successHandler = successHandler;
    this.failureHandler = failureHandler;
    this.objectMapper = mapper;
}
 
Example #23
Source File: AdminUserProcessingFilter.java    From OpenLRW with Educational Community License v2.0 5 votes vote down vote up
public AdminUserProcessingFilter(String defaultProcessUrl, AuthenticationSuccessHandler successHandler,
    AuthenticationFailureHandler failureHandler, ObjectMapper mapper) {
  super(defaultProcessUrl);
  this.successHandler = successHandler;
  this.failureHandler = failureHandler;
  this.objectMapper = mapper;
}
 
Example #24
Source File: MiniAppAuthenticationConfigurer.java    From fast-family-master with Apache License 2.0 5 votes vote down vote up
public MiniAppAuthenticationConfigurer(UserDetailsService userDetailsService,
                                       AuthenticationFailureHandler authenticationFailureHandler,
                                       AuthenticationSuccessHandler authenticationSuccessHandler) {
    this.userDetailsService = userDetailsService;
    this.authenticationFailureHandler = authenticationFailureHandler;
    this.authenticationSuccessHandler = authenticationSuccessHandler;
}
 
Example #25
Source File: SmsJwtConfiguration.java    From cola with MIT License 5 votes vote down vote up
@Bean
public SmsLoginConfigurer<HttpSecurity> smsLoginConfigurer(AuthenticationSuccessHandler successHandler,
														   AuthenticationFailureHandler failureHandler) {
	SmsLoginConfigurer<HttpSecurity> configurer = new SmsLoginConfigurer<>();
	configurer.successHandler(successHandler)
			.failureHandler(failureHandler)
			.eventPublisher(applicationEventPublisher)
			.permitAll();
	return configurer;
}
 
Example #26
Source File: AuthorizationCodeJwtConfiguration.java    From cola with MIT License 5 votes vote down vote up
@Bean
public AcLoginConfigurer<HttpSecurity> acLoginConfigurer(AuthenticationSuccessHandler successHandler,
														 AuthenticationFailureHandler failureHandler) {
	AcLoginConfigurer<HttpSecurity> configurer = new AcLoginConfigurer<>();
	configurer.successHandler(successHandler)
			.failureHandler(failureHandler)
			.eventPublisher(applicationEventPublisher)
			.permitAll();
	return configurer;
}
 
Example #27
Source File: OpenIdJwtConfiguration.java    From cola with MIT License 5 votes vote down vote up
@Bean
public OpenIdLoginConfigurer<HttpSecurity> openIDLoginConfigurer(AuthenticationSuccessHandler successHandler,
																 AuthenticationFailureHandler failureHandler) {
	OpenIdLoginConfigurer<HttpSecurity> configurer = new OpenIdLoginConfigurer<>();
	configurer.successHandler(successHandler)
			.failureHandler(failureHandler)
			.eventPublisher(applicationEventPublisher)
			.permitAll();
	return configurer;
}
 
Example #28
Source File: RecaptchaAuthenticationFilter.java    From recaptcha-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
@Override
public void setAuthenticationSuccessHandler(AuthenticationSuccessHandler successHandler) {
    if (!LoginFailuresClearingHandler.class.isAssignableFrom(successHandler.getClass())) {
        throw new IllegalArgumentException("Invalid login success handler. Handler must be an instance of " + LoginFailuresClearingHandler.class.getName() + " but is " + successHandler);
    }
    super.setAuthenticationSuccessHandler(successHandler);
}
 
Example #29
Source File: WebSecurityConfig.java    From spring-security with Apache License 2.0 5 votes vote down vote up
@Bean
public AuthenticationSuccessHandler authenticationSuccessHandler() {
    return new AuthenticationSuccessHandler() {
        /**
         * 处理登入成功的请求
         *
         * @param httpServletRequest
         * @param httpServletResponse
         * @param authentication
         * @throws IOException
         * @throws ServletException
         */
        @Override
        public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
            Response result = new Response();
            CustomUserDetails userDetails = (CustomUserDetails) authentication.getPrincipal();
            //将用户信息存入 SecurityContext
            SecurityContextHolder.getContext().setAuthentication(authentication);
            //生成token
            String token = jwtTokenUtil.generateToken(userDetails);
            //将 token 保存到redis
            redisUtil.hset(userDetails.getUsername(), token, JSON.toJSONString(userDetails), jwtProperties.getExpiration());
            //处理登录结果
            result.buildSuccessResponse("已登录");
            result.setData(token);
            httpServletResponse.setContentType("application/json;charset=utf-8");
            PrintWriter out = httpServletResponse.getWriter();
            out.write(JSON.toJSONString(result));
            out.flush();
            out.close();
        }
    };
}
 
Example #30
Source File: MobileLoginConfig.java    From spring-microservice-exam with MIT License 5 votes vote down vote up
/**
 * 手机登录成功后的处理
 *
 * @return AuthenticationSuccessHandler
 */
@Bean
public AuthenticationSuccessHandler mobileLoginSuccessHandler(PasswordEncoder encoder, ClientDetailsService clientDetailsService, ObjectMapper objectMapper,
                                                              AuthorizationServerTokenServices defaultAuthorizationServerTokenServices) {
    return MobileLoginSuccessHandler.builder()
            .objectMapper(objectMapper)
            .clientDetailsService(clientDetailsService)
            .passwordEncoder(encoder)
            .defaultAuthorizationServerTokenServices(defaultAuthorizationServerTokenServices).build();
}