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


Java AuthenticationFailureBadCredentialsEvent类代码示例

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


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

示例1: handle

import org.springframework.security.authentication.event.AuthenticationFailureBadCredentialsEvent; //导入依赖的package包/类
@Override
public void handle(Object event) {
    AuthenticationFailureBadCredentialsEvent loginFailureEvent = (AuthenticationFailureBadCredentialsEvent) event;
    Object name = loginFailureEvent.getAuthentication().getPrincipal();
    Users user = usersRepository.loadUserByUsername((String) name);
    eventService.raiseSecurityEvent(new AuthenticationFailedEvent(
            ((WebAuthenticationDetails) loginFailureEvent
                    .getAuthentication().getDetails()).getRemoteAddress(),
            (String) name));
    if (user != null) {
        // update the failed login count
        user.increaseFailedLoginAttempts();
        if (user.getFailedLoginAttempts() >= max_failed_attempts) {
            Calendar cal = Calendar.getInstance();
            user.setLockoutTime(cal);
        }
        // update user
        usersRepository.updateUser(user);
    }
}
 
开发者ID:bhits,项目名称:pcm-api,代码行数:21,代码来源:LoginFailureEventListener.java

示例2: testHandle_when_account_is_not_locked

import org.springframework.security.authentication.event.AuthenticationFailureBadCredentialsEvent; //导入依赖的package包/类
@Test
public void testHandle_when_account_is_not_locked() {
    AuthenticationFailureBadCredentialsEvent loginFailureEvent=mock(AuthenticationFailureBadCredentialsEvent.class);
    Authentication authentication=mock(Authentication.class);
    WebAuthenticationDetails webAuthenticationDetails=mock(WebAuthenticationDetails.class);
    Object name=new String(username);
    when(loginFailureEvent.getAuthentication()).thenReturn(authentication);
    when(authentication.getDetails()).thenReturn(webAuthenticationDetails);
    when(webAuthenticationDetails.getRemoteAddress()).thenReturn("127.0.0.1");
    when(authentication.getPrincipal()).thenReturn(name);
    Users user=mock(Users.class);
    when(user.getFailedLoginAttempts()).thenReturn(0);
    when(usersRepository.loadUserByUsername(username)).thenReturn(user);
    loginFailureEventListener.handle(loginFailureEvent);
    verify(usersRepository).updateUser(user);
}
 
开发者ID:bhits,项目名称:pcm-api,代码行数:17,代码来源:LoginFailureEventListenerTest.java

示例3: testHandle_when_account_is_locked

import org.springframework.security.authentication.event.AuthenticationFailureBadCredentialsEvent; //导入依赖的package包/类
@Test
public void testHandle_when_account_is_locked() {
    AuthenticationFailureBadCredentialsEvent loginFailureEvent=mock(AuthenticationFailureBadCredentialsEvent.class);
    Authentication authentication=mock(Authentication.class);
    WebAuthenticationDetails webAuthenticationDetails=mock(WebAuthenticationDetails.class);
    Object name=new String(username);
    when(loginFailureEvent.getAuthentication()).thenReturn(authentication);
    when(authentication.getPrincipal()).thenReturn(name);
    when(authentication.getDetails()).thenReturn(webAuthenticationDetails);
    when(webAuthenticationDetails.getRemoteAddress()).thenReturn("127.0.0.1");
    Users user=mock(Users.class);
    when(user.getFailedLoginAttempts()).thenReturn(3);
    when(usersRepository.loadUserByUsername(username)).thenReturn(user);
    loginFailureEventListener.handle(loginFailureEvent);
    verify(user).setLockoutTime(any(Calendar.class));
    verify(usersRepository).updateUser(user);
}
 
开发者ID:bhits,项目名称:pcm-api,代码行数:18,代码来源:LoginFailureEventListenerTest.java

示例4: onApplicationEvent

import org.springframework.security.authentication.event.AuthenticationFailureBadCredentialsEvent; //导入依赖的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

示例5: onApplicationEvent

import org.springframework.security.authentication.event.AuthenticationFailureBadCredentialsEvent; //导入依赖的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

示例6: handle

import org.springframework.security.authentication.event.AuthenticationFailureBadCredentialsEvent; //导入依赖的package包/类
@Override
public void handle(Object event) {
    AuthenticationFailureBadCredentialsEvent loginFailureEvent
         = (AuthenticationFailureBadCredentialsEvent) event;
    Object name = loginFailureEvent.getAuthentication()
              .getPrincipal();
    Users user=usersRepository.loadUserByUsername((String)name);
    if (user != null) {
        // update the failed login count
    	user.increaseFailedLoginAttempts();
    	if (user.getFailedLoginAttempts()>=max_failed_attempts){
    		Calendar cal = Calendar.getInstance();
    		user.setLockoutTime(cal);
    	}
        // update user
    	usersRepository.updateUser(user);
    }
}
 
开发者ID:tlin-fei,项目名称:ds4p,代码行数:19,代码来源:LoginFailureEventListener.java

示例7: onApplicationEvent

import org.springframework.security.authentication.event.AuthenticationFailureBadCredentialsEvent; //导入依赖的package包/类
@Override
@Transactional
public void onApplicationEvent(AuthenticationFailureBadCredentialsEvent event) {
	Object principal = event.getAuthentication().getPrincipal();
	if (principal instanceof String) {
		User user = this.userRepository.findByUserName((String) principal);
		if (user != null) {
			if (user.getFailedLogins() == null) {
				user.setFailedLogins(1);
			}
			else {
				user.setFailedLogins(user.getFailedLogins() + 1);
			}

			if (user.getFailedLogins() > 10) {
				user.setLockedOut(LocalDateTime.now().plusMinutes(10));
			}

		}
		else {
			LoggerFactory.getLogger(UserAuthenticationErrorHandler.class)
					.error("Unknown user login attempt: {}", principal);
		}
	}
}
 
开发者ID:ralscha,项目名称:springsecuritytotp,代码行数:26,代码来源:UserAuthenticationErrorHandler.java

示例8: onApplicationEvent

import org.springframework.security.authentication.event.AuthenticationFailureBadCredentialsEvent; //导入依赖的package包/类
@Override
@Transactional
public void onApplicationEvent(AuthenticationFailureBadCredentialsEvent ev) {

    try {
	String username = ev.getAuthentication().getName();

	TypedQuery<User> query = User.findUsersByEmailAddress(username, null, null);
	User targetUser = (User) query.getSingleResult();

    if (targetUser != null) { // only for existing users
    	targetUser.reportLoginFailure();
    	targetUser.persist();
    }

    } catch(Exception e) { }    

}
 
开发者ID:EsupPortail,项目名称:esup-dematec,代码行数:19,代码来源:AuthenticationFailureListener.java

示例9: onApplicationEvent

import org.springframework.security.authentication.event.AuthenticationFailureBadCredentialsEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(final AuthenticationFailureBadCredentialsEvent e) {
    final WebAuthenticationDetails auth = (WebAuthenticationDetails) e.getAuthentication().getDetails();
    if (auth != null) {
        loginAttemptService.loginFailed(auth.getRemoteAddress());
    }
}
 
开发者ID:h819,项目名称:spring-boot,代码行数:8,代码来源:AuthenticationFailureListener.java

示例10: authenticate

import org.springframework.security.authentication.event.AuthenticationFailureBadCredentialsEvent; //导入依赖的package包/类
private SubsonicRESTController.ErrorCode authenticate(HttpServletRequest httpRequest, String username, String password, String salt, String token, Authentication previousAuth) {

        // Previously authenticated and username not overridden?
        if (username == null && previousAuth != null) {
            return null;
        }

        if (salt != null && token != null) {
            User user = securityService.getUserByName(username);
            if (user == null) {
                return SubsonicRESTController.ErrorCode.NOT_AUTHENTICATED;
            }
            String expectedToken = DigestUtils.md5Hex(user.getPassword() + salt);
            if (!expectedToken.equals(token)) {
                return SubsonicRESTController.ErrorCode.NOT_AUTHENTICATED;
            }

            password = user.getPassword();
        }

        if (password != null) {
            UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username, password);
            authRequest.setDetails(authenticationDetailsSource.buildDetails(httpRequest));
            try {
                Authentication authResult = authenticationManager.authenticate(authRequest);
                SecurityContextHolder.getContext().setAuthentication(authResult);
                return null;
            } catch (AuthenticationException x) {
                eventPublisher.publishEvent(new AuthenticationFailureBadCredentialsEvent(authRequest, x));
                return SubsonicRESTController.ErrorCode.NOT_AUTHENTICATED;
            }
        }

        return SubsonicRESTController.ErrorCode.MISSING_PARAMETER;
    }
 
开发者ID:airsonic,项目名称:airsonic,代码行数:36,代码来源:RESTRequestParameterProcessingFilter.java

示例11: onApplicationEvent

import org.springframework.security.authentication.event.AuthenticationFailureBadCredentialsEvent; //导入依赖的package包/类
public void onApplicationEvent(ApplicationEvent event) {
    try {
        if (event instanceof InteractiveAuthenticationSuccessEvent) {
            this.logLoginSuccess(event);
        }

        if (event instanceof AuthenticationFailureBadCredentialsEvent) {
            this.logBadCredential(event);
        }

        if (event instanceof AuthenticationFailureLockedEvent) {
            this.logLocked(event);
        }

        if (event instanceof AuthenticationFailureDisabledEvent) {
            this.logDisabled(event);
        }

        if (event instanceof AuthenticationFailureExpiredEvent) {
            this.logAccountExpired(event);
        }

        if (event instanceof AuthenticationFailureCredentialsExpiredEvent) {
            this.logCredentialExpired(event);
        }
    } catch (Exception ex) {
        logger.error(ex.getMessage(), ex);
    }
}
 
开发者ID:zhaojunfei,项目名称:lemon,代码行数:30,代码来源:SpringSecurityListener.java

示例12: logBadCredential

import org.springframework.security.authentication.event.AuthenticationFailureBadCredentialsEvent; //导入依赖的package包/类
public void logBadCredential(ApplicationEvent event) throws Exception {
    AuthenticationFailureBadCredentialsEvent authenticationFailureBadCredentialsEvent = (AuthenticationFailureBadCredentialsEvent) event;
    Authentication authentication = authenticationFailureBadCredentialsEvent
            .getAuthentication();
    logger.info("{}", authentication);

    String tenantId = this.getTenantId(authentication);
    Object principal = authentication.getPrincipal();
    String userId = null;

    if (principal instanceof SpringSecurityUserAuth) {
        userId = ((SpringSecurityUserAuth) principal).getId();
    } else {
        userId = authentication.getName();
    }

    AuditDTO auditDto = new AuditDTO();
    auditDto.setUserId(userId);
    auditDto.setAuditTime(new Date());
    auditDto.setAction("login");
    auditDto.setResult("failure");
    auditDto.setApplication("lemon");
    auditDto.setClient(getUserIp(authentication));
    auditDto.setServer(InetAddress.getLocalHost().getHostAddress());
    auditDto.setDescription(authenticationFailureBadCredentialsEvent
            .getException().getMessage());
    auditDto.setTenantId(tenantId);
    auditConnector.log(auditDto);

    ctx.publishEvent(new LoginEvent(authentication, userId, this
            .getSessionId(authentication), "badCredentials", "default",
            tenantId));
}
 
开发者ID:zhaojunfei,项目名称:lemon,代码行数:34,代码来源:SpringSecurityListener.java

示例13: onApplicationEvent

import org.springframework.security.authentication.event.AuthenticationFailureBadCredentialsEvent; //导入依赖的package包/类
/**
 * On login failure we record the failing email address and ip address
 *
 * @param e bad credentials event
 */
@Override
public void onApplicationEvent(final AuthenticationFailureBadCredentialsEvent e) {
    final WebAuthenticationDetails auth = (WebAuthenticationDetails)
            e.getAuthentication().getDetails();

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

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

示例14: testAuditLogin_failure

import org.springframework.security.authentication.event.AuthenticationFailureBadCredentialsEvent; //导入依赖的package包/类
@Test
public void testAuditLogin_failure() {
    final String error = "exception message";
    final AbstractAuthenticationFailureEvent event = new AuthenticationFailureBadCredentialsEvent(
            authMock, new BadCredentialsException(error));

    auditService.auditLoginFailureEvent(event);

    verify(accountActivityMessageRepository, times(1))
            .save(argThat(matches(false, username, error)));

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

示例15: pingAuthenticationListener

import org.springframework.security.authentication.event.AuthenticationFailureBadCredentialsEvent; //导入依赖的package包/类
private void pingAuthenticationListener() {
	AuthenticationListener listener = new AuthenticationListener();
	this.context.addApplicationListener(listener);
	AuthenticationManager manager = this.context.getBean(AuthenticationManager.class);
	try {
		manager.authenticate(new UsernamePasswordAuthenticationToken("foo", "wrong"));
		fail("Expected BadCredentialsException");
	}
	catch (BadCredentialsException e) {
		// expected
	}
	assertThat(listener.event)
			.isInstanceOf(AuthenticationFailureBadCredentialsEvent.class);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:15,代码来源:SecurityAutoConfigurationTests.java


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