本文整理汇总了Java中org.springframework.security.event.authentication.AuthenticationSuccessEvent类的典型用法代码示例。如果您正苦于以下问题:Java AuthenticationSuccessEvent类的具体用法?Java AuthenticationSuccessEvent怎么用?Java AuthenticationSuccessEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AuthenticationSuccessEvent类属于org.springframework.security.event.authentication包,在下文中一共展示了AuthenticationSuccessEvent类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onApplicationEvent
import org.springframework.security.event.authentication.AuthenticationSuccessEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(ApplicationEvent event) {
if (event instanceof AbstractAuthenticationFailureEvent) {
onAuthenticationFailure((AbstractAuthenticationFailureEvent) event);
}
if (event instanceof AuthenticationSuccessEvent) {
onAuthenticationSuccess((AuthenticationSuccessEvent) event);
}
}
示例2: onAuthenticationSuccess
import org.springframework.security.event.authentication.AuthenticationSuccessEvent; //导入依赖的package包/类
protected void onAuthenticationSuccess(AuthenticationSuccessEvent event) {
// on success - principal is a UserDetails
UserDetails details = (UserDetails) event.getAuthentication().getPrincipal();
String username = details.getUsername();
if (!StringUtils.isBlank(username)) {
Long orgId = organizationManager.getOrganization().getId();
User user = userDao.findUserByOrganizationAndUsername(orgId, username);
if (user != null) {
user.setLoginFailureCount(0);
userDao.persist(user);
}
}
}
示例3: testAuthenticationSuccessEventWithEverything
import org.springframework.security.event.authentication.AuthenticationSuccessEvent; //导入依赖的package包/类
public void testAuthenticationSuccessEventWithEverything() throws Exception {
String userName = "bar";
String ip = "1.2.3.4";
String sessionId = "it tastes just like our regular coffee";
HttpServletRequest request = createMock(HttpServletRequest.class);
HttpSession session = createMock(HttpSession.class);
expect(request.getRemoteAddr()).andReturn(ip);
expect(request.getSession(false)).andReturn(session);
expect(session.getId()).andReturn(sessionId);
replay(request, session);
WebAuthenticationDetails details = new WebAuthenticationDetails(request);
verify(request, session);
Authentication authentication = new TestingDetailsAuthenticationToken(userName, "cheesiness", new GrantedAuthority[0], details);
AuthenticationSuccessEvent authEvent = new AuthenticationSuccessEvent(authentication);
SecurityAuthenticationEventOnmsEventBuilder builder = new SecurityAuthenticationEventOnmsEventBuilder();
builder.setEventProxy(m_eventProxy);
builder.afterPropertiesSet();
EventBuilder eventBuilder = new EventBuilder(SecurityAuthenticationEventOnmsEventBuilder.SUCCESS_UEI, "OpenNMS.WebUI");
eventBuilder.addParam("user", userName);
eventBuilder.addParam("ip", ip);
m_eventProxy.send(EventEquals.eqEvent(eventBuilder.getEvent()));
m_mocks.replayAll();
builder.onApplicationEvent(authEvent);
m_mocks.verifyAll();
}