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

The following examples show how to use org.springframework.security.web.authentication.AuthenticationSuccessHandler. These examples are extracted from open source projects. 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
/**
 * 登陆成功,返回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 2
Source Project: spring-security   Source File: WebSecurityConfig.java    License: 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 3
Source Project: spring-security   Source File: WebSecurityConfig.java    License: 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 4
Source Project: api-layer   Source File: QueryFilter.java    License: 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 5
Source Project: oauth-boot   Source File: SmsSecurityConfig.java    License: 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 6
Source Project: jeesupport   Source File: WebSecurityConfig.java    License: 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 7
Source Project: find   Source File: IdolSecurityCustomizerImpl.java    License: 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 8
@Bean
public AuthenticationSuccessHandler mobileLoginSuccessHandler() {
	return MobileLoginSuccessHandler.builder()
		.objectMapper(objectMapper)
		.clientDetailsService(clientDetailsService)
		.passwordEncoder(passwordEncoder())
		.defaultAuthorizationServerTokenServices(defaultAuthorizationServerTokenServices).build();
}
 
Example 9
public RefreshTokenProcessingFilter(String defaultProcessUrl, AuthenticationSuccessHandler successHandler,
                                    AuthenticationFailureHandler failureHandler, ObjectMapper mapper) {
    super(defaultProcessUrl);
    this.successHandler = successHandler;
    this.failureHandler = failureHandler;
    this.objectMapper = mapper;
}
 
Example 10
public RestPublicLoginProcessingFilter(String defaultProcessUrl, AuthenticationSuccessHandler successHandler,
                                       AuthenticationFailureHandler failureHandler, ObjectMapper mapper) {
    super(defaultProcessUrl);
    this.successHandler = successHandler;
    this.failureHandler = failureHandler;
    this.objectMapper = mapper;
}
 
Example 11
public RestLoginProcessingFilter(String defaultProcessUrl, AuthenticationSuccessHandler successHandler,
                                 AuthenticationFailureHandler failureHandler, ObjectMapper mapper) {
    super(defaultProcessUrl);
    this.successHandler = successHandler;
    this.failureHandler = failureHandler;
    this.objectMapper = mapper;
}
 
Example 12
/**
 * 登陆成功
 */
@Bean
public AuthenticationSuccessHandler loginSuccessHandler() {
    return new SavedRequestAwareAuthenticationSuccessHandler() {
        @Override
        public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
                                            Authentication authentication) throws IOException, ServletException {
            super.onAuthenticationSuccess(request, response, authentication);
        }
    };
}
 
Example 13
Source Project: spring-microservice-exam   Source File: WxLoginConfig.java    License: MIT License 5 votes vote down vote up
/**
 * 微信登录成功后的处理
 *
 * @return AuthenticationSuccessHandler
 */
@Bean
public AuthenticationSuccessHandler wxLoginSuccessHandler(PasswordEncoder encoder, ClientDetailsService clientDetailsService, ObjectMapper objectMapper,
                                                          AuthorizationServerTokenServices defaultAuthorizationServerTokenServices) {
    return WxLoginSuccessHandler.builder()
            .objectMapper(objectMapper)
            .clientDetailsService(clientDetailsService)
            .passwordEncoder(encoder)
            .defaultAuthorizationServerTokenServices(defaultAuthorizationServerTokenServices).build();
}
 
Example 14
Source Project: spring-microservice-exam   Source File: MobileLoginConfig.java    License: 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();
}
 
Example 15
Source Project: spring-security   Source File: WebSecurityConfig.java    License: 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 16
Source Project: cola   Source File: OpenIdJwtConfiguration.java    License: 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 17
Source Project: cola   Source File: AuthorizationCodeJwtConfiguration.java    License: 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 18
Source Project: cola   Source File: SmsJwtConfiguration.java    License: 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 19
public MiniAppAuthenticationConfigurer(UserDetailsService userDetailsService,
                                       AuthenticationFailureHandler authenticationFailureHandler,
                                       AuthenticationSuccessHandler authenticationSuccessHandler) {
    this.userDetailsService = userDetailsService;
    this.authenticationFailureHandler = authenticationFailureHandler;
    this.authenticationSuccessHandler = authenticationSuccessHandler;
}
 
Example 20
public WechatAuthenticationConfigurer(WxMpService wxMpService, UserDetailsService userDetailsService,
                                      AuthenticationFailureHandler authenticationFailureHandler,
                                      AuthenticationSuccessHandler authenticationSuccessHandler) {
    this.wxMpService = wxMpService;
    this.userDetailsService = userDetailsService;
    this.authenticationFailureHandler = authenticationFailureHandler;
    this.authenticationSuccessHandler = authenticationSuccessHandler;
}
 
Example 21
/**
 * 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 22
Source Project: Groza   Source File: RefreshTokenProcessingFilter.java    License: 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 23
Source Project: Groza   Source File: RestPublicLoginProcessingFilter.java    License: 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 24
Source Project: Groza   Source File: RestLoginProcessingFilter.java    License: 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 25
Source Project: api-layer   Source File: LoginFilter.java    License: 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 26
@Autowired
public OpenIdAuthenticationSecurityConfig(AuthenticationSuccessHandler pcAuthenticationSuccessHandler, AuthenticationFailureHandler pcAuthenticationFailureHandler, SocialUserDetailsService userDetailsService, UsersConnectionRepository usersConnectionRepository) {
	this.pcAuthenticationSuccessHandler = pcAuthenticationSuccessHandler;
	this.pcAuthenticationFailureHandler = pcAuthenticationFailureHandler;
	this.userDetailsService = userDetailsService;
	this.usersConnectionRepository = usersConnectionRepository;
}
 
Example 27
public AjaxLoginProcessingFilter(String defaultProcessUrl, AuthenticationSuccessHandler successHandler, 
        AuthenticationFailureHandler failureHandler, ObjectMapper mapper) {
    super(defaultProcessUrl);
    this.successHandler = successHandler;
    this.failureHandler = failureHandler;
    this.objectMapper = mapper;
}
 
Example 28
public AdminUserProcessingFilter(String defaultProcessUrl, AuthenticationSuccessHandler successHandler,
    AuthenticationFailureHandler failureHandler, ObjectMapper mapper) {
  super(defaultProcessUrl);
  this.successHandler = successHandler;
  this.failureHandler = failureHandler;
  this.objectMapper = mapper;
}
 
Example 29
Source Project: secrets-proxy   Source File: LoginProcessingFilter.java    License: 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 30
Source Project: iotplatform   Source File: RefreshTokenProcessingFilter.java    License: 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;
}