当前位置: 首页>>代码示例>>Java>>正文


Java AuthenticationSuccessEvent类代码示例

本文整理汇总了Java中org.springframework.security.authentication.event.AuthenticationSuccessEvent的典型用法代码示例。如果您正苦于以下问题:Java AuthenticationSuccessEvent类的具体用法?Java AuthenticationSuccessEvent怎么用?Java AuthenticationSuccessEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AuthenticationSuccessEvent类属于org.springframework.security.authentication.event包,在下文中一共展示了AuthenticationSuccessEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onApplicationEvent

import org.springframework.security.authentication.event.AuthenticationSuccessEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(AbstractAuthenticationEvent event) {
	if (event instanceof AuthenticationSuccessEvent) {
		log.debug("Authentication OK: {}", event.getAuthentication().getName());

		// Activity log
		Object details = event.getAuthentication().getDetails();
		String params = null;

		if (details instanceof WebAuthenticationDetails) {
			WebAuthenticationDetails wad = (WebAuthenticationDetails) details;
			params = wad.getRemoteAddress();
		} else if (GenericHolder.get() != null) {
			params = (String) GenericHolder.get();
		}

		UserActivity.log(event.getAuthentication().getName(), "LOGIN", null, null, params);
	} else if (event instanceof AuthenticationFailureBadCredentialsEvent) {
		log.info("Authentication ERROR: {}", event.getAuthentication().getName());
	}
}
 
开发者ID:openkm,项目名称:document-management-system,代码行数:22,代码来源:LoggerListener.java

示例2: onApplicationEvent

import org.springframework.security.authentication.event.AuthenticationSuccessEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(AbstractAuthenticationEvent appEvent) {
    String currentUserName = extractUserName(appEvent);
    if (currentUserName == null || isLockMechanismDisabled()) {
        return;
    }

    if (appEvent instanceof AuthenticationSuccessEvent &&
            accessCounter.containsKey(currentUserName) &&
            accessCounter.get(currentUserName) < maxLoginFailures) {

        accessCounter.remove(currentUserName);
        lastFailedLogin.remove(currentUserName);
    }

    if (appEvent instanceof AuthenticationFailureBadCredentialsEvent) {
        if (accessCounter.containsKey(currentUserName)) {
            accessCounter.put(currentUserName, accessCounter.get(currentUserName) + 1);
        } else {
            accessCounter.put(currentUserName, 1);
        }
        lastFailedLogin.put(currentUserName, new Date());
    }
}
 
开发者ID:osiam,项目名称:auth-server,代码行数:25,代码来源:InternalAuthenticationProvider.java

示例3: attemptAuthentication

import org.springframework.security.authentication.event.AuthenticationSuccessEvent; //导入依赖的package包/类
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response)
    throws AuthenticationException, IOException, ServletException {

    try {
        OAuth2AccessToken accessToken = restTemplate.getAccessToken();
        FacebookUser facebookUser = userIdentity.findOrCreateFrom(accessToken);

        repository.save(facebookUser);

        Authentication authentication = new UsernamePasswordAuthenticationToken(
                facebookUser, null, Arrays.asList(new SimpleGrantedAuthority("ROLE_USER")));
        publish(new AuthenticationSuccessEvent(authentication));
        return authentication;
    } catch (OAuth2Exception e) {
        BadCredentialsException error = new BadCredentialsException(
                "Cannot retrieve the access token", e);
        publish(new OAuth2AuthenticationFailureEvent(error));
        throw error;
    }
}
 
开发者ID:PacktPublishing,项目名称:OAuth-2.0-Cookbook,代码行数:21,代码来源:FacebookLoginFilter.java

示例4: attemptAuthentication

import org.springframework.security.authentication.event.AuthenticationSuccessEvent; //导入依赖的package包/类
@Override
public Authentication attemptAuthentication(
    HttpServletRequest request, HttpServletResponse response)
    throws AuthenticationException, IOException, ServletException {

    try {
        OAuth2AccessToken accessToken = restTemplate.getAccessToken();

        Claims claims = Claims.createFrom(jsonMapper, accessToken);
        GoogleUser googleUser = userIdentity.findOrCreateFrom(claims);
        repository.save(googleUser);

        Authentication authentication = new UsernamePasswordAuthenticationToken(
            googleUser, null, googleUser.getAuthorities());
        publish(new AuthenticationSuccessEvent(authentication));
        return authentication;
    } catch (OAuth2Exception e) {
        BadCredentialsException error = new BadCredentialsException(
                "Cannot retrieve the access token", e);
        publish(new OAuth2AuthenticationFailureEvent(error));
        throw error;
    }
}
 
开发者ID:PacktPublishing,项目名称:OAuth-2.0-Cookbook,代码行数:24,代码来源:OpenIdConnectFilter.java

示例5: onApplicationEvent

import org.springframework.security.authentication.event.AuthenticationSuccessEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent( final AuthenticationSuccessEvent authenticationSuccessEvent )
{
    final String username = authenticationSuccessEvent.getAuthentication().getName();

    UserCredentials credentials = userService.getUserCredentialsByUsername( username );

    boolean readOnly = config.isReadOnlyMode();

    if ( Objects.nonNull( credentials ) && !readOnly )
    {
        credentials.updateLastLogin();
        userService.updateUserCredentials( credentials );
    }

    if ( credentials != null )
    {
        securityService.registerSuccessfulLogin( username );
    }
}
 
开发者ID:dhis2,项目名称:dhis2-core,代码行数:21,代码来源:AuthenticationListener.java

示例6: handleAuthenticationSuccessEvent

import org.springframework.security.authentication.event.AuthenticationSuccessEvent; //导入依赖的package包/类
/**
 * Обрабатывает событие успешной аутентификации
 *
 * @param event событие
 */
private void handleAuthenticationSuccessEvent(AuthenticationSuccessEvent event) {
    if (LOG.isInfoEnabled()) {
        Authentication authentication = event.getAuthentication();

        String commonMessage = String.format(
                SUCCESS_TEMPLATE,
                DateUtil.formatDateTime(new Date(event.getTimestamp())),
                extractPrincipal(authentication),
                StringUtils.collectionToCommaDelimitedString(authentication.getAuthorities())
        );
        String detailsMessage = (authentication.getDetails() != null) ? OBJECT_HEX_PATTERN.matcher(authentication.getDetails().toString()).replaceAll("") : null;
        String resultMessage = StringUtils.hasText(detailsMessage) ? String.format(DETAILS_TEMPLATE, commonMessage, detailsMessage) : commonMessage;

        LOG.info(resultMessage);
    }
}
 
开发者ID:hflabs,项目名称:perecoder,代码行数:22,代码来源:AuthenticationEventListener.java

示例7: onApplicationEvent

import org.springframework.security.authentication.event.AuthenticationSuccessEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(AuthenticationSuccessEvent event) {
	try {
		User user = userService.findByLogin(((UserDetails) event.getAuthentication().getPrincipal()).getUsername());
		user.setLastConnection(new Date());
		userService.update(user);
	} catch (ServiceException e) {
		e.printStackTrace();
	}
}
 
开发者ID:oncecloud,项目名称:devops-cstack,代码行数:11,代码来源:UserAuthenticationSuccess.java

示例8: attemptAuthentication

import org.springframework.security.authentication.event.AuthenticationSuccessEvent; //导入依赖的package包/类
@Override
public Authentication attemptAuthentication(
    HttpServletRequest request, HttpServletResponse response)
    throws AuthenticationException, IOException, ServletException {

    try {
        OAuth2AccessToken accessToken = restTemplate.getAccessToken();

        Claims claims = Claims.createFrom(jsonMapper, accessToken);
        GoogleUser googleUser = userIdentity.findOrCreateFrom(claims);

        String userName = getUserNameFromUserInfo(accessToken,
            googleUser.getOpenIDAuthentication().getSubject());
        googleUser.getOpenIDAuthentication().setName(userName);

        repository.save(googleUser);

        Authentication authentication = new UsernamePasswordAuthenticationToken(
                googleUser, null, googleUser.getAuthorities());
        publish(new AuthenticationSuccessEvent(authentication));
        return authentication;
    } catch (OAuth2Exception e) {
        BadCredentialsException error = new BadCredentialsException(
                "Cannot retrieve the access token", e);
        publish(new OAuth2AuthenticationFailureEvent(error));
        throw error;
    }
}
 
开发者ID:PacktPublishing,项目名称:OAuth-2.0-Cookbook,代码行数:29,代码来源:OpenIdConnectFilter.java

示例9: onApplicationEvent

import org.springframework.security.authentication.event.AuthenticationSuccessEvent; //导入依赖的package包/类
/**
 * record successful login attempt
 *
 * @param e authentication success event
 */
@Override
public void onApplicationEvent(final AuthenticationSuccessEvent e) {
    final WebAuthenticationDetails auth = (WebAuthenticationDetails)
            e.getAuthentication().getDetails();

    final String email = e.getAuthentication().getPrincipal().toString();

    loginAttemptService.loginSucceeded(email, auth.getRemoteAddress());
}
 
开发者ID:mhaddon,项目名称:Sound.je,代码行数:15,代码来源:AuthenticationSuccessEventListener.java

示例10: storeLogMessage

import org.springframework.security.authentication.event.AuthenticationSuccessEvent; //导入依赖的package包/类
private void storeLogMessage(final AbstractAuthenticationEvent event) {
    try {
        if (event instanceof InteractiveAuthenticationSuccessEvent) {
            accountAuditService.auditLoginSuccessEvent(InteractiveAuthenticationSuccessEvent.class.cast(event));
        } else if (event instanceof AuthenticationSuccessEvent) {
            accountAuditService.auditLoginSuccessEvent(AuthenticationSuccessEvent.class.cast(event));
        } else if (event instanceof AbstractAuthenticationFailureEvent) {
            accountAuditService.auditLoginFailureEvent(AbstractAuthenticationFailureEvent.class.cast(event));
        }
    } catch (Exception ex) {
        LOG.error("Failed to audit authentication event in database", ex);
    }
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:14,代码来源:AuthenticationAuditEventListener.java

示例11: logToAuditService

import org.springframework.security.authentication.event.AuthenticationSuccessEvent; //导入依赖的package包/类
private void logToAuditService(AbstractAuthenticationEvent event) {
    if (event instanceof AuthenticationSuccessEvent) {
        final Authentication authentication = event.getAuthentication();

        final ImmutableMap.Builder<String, Object> extra = auditService.extra("remoteAddress",
                getRemoteAddress(authentication));
        addGrantedAuthorities(authentication, extra);
        addSource(event, extra);
        auditService.log("loginSuccess", authentication.getName(), extra.build());
    }
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:12,代码来源:AuthenticationAuditEventListener.java

示例12: auditLoginSuccessEvent

import org.springframework.security.authentication.event.AuthenticationSuccessEvent; //导入依赖的package包/类
@Transactional
public void auditLoginSuccessEvent(AuthenticationSuccessEvent successEvent) {
    final AccountActivityMessage message = createLogMessage(
            null, successEvent.getAuthentication(),
            AccountActivityMessage.ActivityType.LOGIN_SUCCESS);

    logMessageRepository.save(message);
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:9,代码来源:AccountAuditService.java

示例13: testAuditLogin_success

import org.springframework.security.authentication.event.AuthenticationSuccessEvent; //导入依赖的package包/类
@Test
public void testAuditLogin_success() {
    final AuthenticationSuccessEvent event = new AuthenticationSuccessEvent(authMock);

    auditService.auditLoginSuccessEvent(event);

    verify(accountActivityMessageRepository, times(1))
            .save(argThat(matches(true, username, null)));

    verifyNoMoreInteractions(accountActivityMessageRepository);
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:12,代码来源:AccountAuditServiceTest.java

示例14: onApplicationEvent

import org.springframework.security.authentication.event.AuthenticationSuccessEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(AuthenticationSuccessEvent event) {
    final User principal = (User) event.getAuthentication().getPrincipal();
    Map<String, String> details = (Map<String, String>) event.getAuthentication().getDetails();

    try {
        io.gravitee.am.model.User user = userService.loadUserByUsernameAndDomain(domain.getId(), principal.getUsername());
        UpdateUser updateUser = new UpdateUser();
        if (details != null) {
            updateUser.setSource(details.get(RepositoryProviderUtils.SOURCE));
            updateUser.setClient(details.get(OAuth2Utils.CLIENT_ID));
        }
        updateUser.setLoggedAt(new Date());
        updateUser.setLoginsCount(user.getLoginsCount() + 1);
        updateUser.setAdditionalInformation(principal.getAdditionalInformation());
        userService.update(domain.getId(), user.getId(), updateUser);
    } catch (UserNotFoundException unfe) {
        final NewUser newUser = new NewUser();
        newUser.setUsername(principal.getUsername());
        if (details != null) {
            newUser.setSource(details.get(RepositoryProviderUtils.SOURCE));
            newUser.setClient(details.get(OAuth2Utils.CLIENT_ID));
        }
        newUser.setLoggedAt(new Date());
        newUser.setLoginsCount(1l);
        newUser.setAdditionalInformation(principal.getAdditionalInformation());
        userService.create(domain.getId(), newUser);
    }
}
 
开发者ID:gravitee-io,项目名称:graviteeio-access-management,代码行数:30,代码来源:AuthenticationSuccessListener.java

示例15: handle

import org.springframework.security.authentication.event.AuthenticationSuccessEvent; //导入依赖的package包/类
@Override
public void handle(Object event) {
    AuthenticationSuccessEvent loginSuccessEvent = (AuthenticationSuccessEvent) event;
    Object name = loginSuccessEvent.getAuthentication().getPrincipal();
    if (name != null) {
        Users user = (Users) name;
        user.setFailedLoginAttemptsToZero();
        usersRepository.updateUser(user);
    }
}
 
开发者ID:bhits,项目名称:pcm-api,代码行数:11,代码来源:LoginSuccessEventListener.java


注:本文中的org.springframework.security.authentication.event.AuthenticationSuccessEvent类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。