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


Java AbstractAuthenticationEvent类代码示例

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


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

示例1: onApplicationEvent

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

import org.springframework.security.authentication.event.AbstractAuthenticationEvent; //导入依赖的package包/类
private String extractUserName(AbstractAuthenticationEvent appEvent) {
    if (appEvent.getSource() != null && appEvent.getSource() instanceof InternalAuthentication) {
        InternalAuthentication internalAuth = (InternalAuthentication) appEvent.getSource();

        if (internalAuth.getPrincipal() != null) {

            if (internalAuth.getPrincipal() instanceof User) {
                User user = (User) internalAuth.getPrincipal();
                return user.getUserName();
            }
            if (internalAuth.getPrincipal() instanceof String) {
                return (String) internalAuth.getPrincipal();
            }
        }
    }

    return null;
}
 
开发者ID:osiam,项目名称:auth-server,代码行数:19,代码来源:InternalAuthenticationProvider.java

示例4: onApplicationEvent

import org.springframework.security.authentication.event.AbstractAuthenticationEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(AbstractAuthenticationEvent event) {
  final StringBuilder builder = new StringBuilder();
  builder.append("Authentication event ");
  builder.append(event.getClass().getSimpleName());
  builder.append(": ");
  builder.append(event.getAuthentication().getName());
  builder.append("; details: ");
  builder.append(event.getAuthentication().getDetails());

  if (event instanceof AbstractAuthenticationFailureEvent) {
    builder.append("; exception: ");
    builder.append(((AbstractAuthenticationFailureEvent) event)
        .getException().getMessage());
  }
  LOG.warn(builder.toString());
}
 
开发者ID:kaaproject,项目名称:kaa,代码行数:18,代码来源:KaaAdminAuthListener.java

示例5: onApplicationEvent

import org.springframework.security.authentication.event.AbstractAuthenticationEvent; //导入依赖的package包/类
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void onApplicationEvent(AbstractAuthenticationEvent event) {
    logToAuditService(event);

    emitLogMessage(event);
    storeLogMessage(event);
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:9,代码来源:AuthenticationAuditEventListener.java

示例6: emitLogMessage

import org.springframework.security.authentication.event.AbstractAuthenticationEvent; //导入依赖的package包/类
private static void emitLogMessage(AbstractAuthenticationEvent event) {
    final StringBuilder builder = new StringBuilder();
    builder.append("Authentication event ");
    builder.append(ClassUtils.getShortName(event.getClass()));
    builder.append(": ");
    builder.append(event.getAuthentication().getName());

    if (event instanceof AbstractAuthenticationFailureEvent) {
        builder.append("; exception: ");
        builder.append(((AbstractAuthenticationFailureEvent) event).getException().getMessage());
    }

    LOG.warn(builder.toString());
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:15,代码来源:AuthenticationAuditEventListener.java

示例7: storeLogMessage

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

示例8: logToAuditService

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

示例9: onApplicationEvent

import org.springframework.security.authentication.event.AbstractAuthenticationEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(AbstractAuthenticationEvent event) {
	if (event instanceof AbstractAuthenticationFailureEvent) {
		onAuthenticationFailureEvent((AbstractAuthenticationFailureEvent) event);
	}
	else if (this.webListener != null && this.webListener.accepts(event)) {
		this.webListener.process(this, event);
	}
	else if (event instanceof AuthenticationSuccessEvent) {
		onAuthenticationSuccessEvent((AuthenticationSuccessEvent) event);
	}
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:13,代码来源:AuthenticationAuditListener.java

示例10: process

import org.springframework.security.authentication.event.AbstractAuthenticationEvent; //导入依赖的package包/类
public void process(AuthenticationAuditListener listener,
		AbstractAuthenticationEvent input) {
	if (listener != null) {
		AuthenticationSwitchUserEvent event = (AuthenticationSwitchUserEvent) input;
		Map<String, Object> data = new HashMap<String, Object>();
		if (event.getAuthentication().getDetails() != null) {
			data.put("details", event.getAuthentication().getDetails());
		}
		data.put("target", event.getTargetUser().getUsername());
		listener.publish(new AuditEvent(event.getAuthentication().getName(),
				"AUTHENTICATION_SWITCH", data));
	}

}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:15,代码来源:AuthenticationAuditListener.java

示例11: onApplicationEvent

import org.springframework.security.authentication.event.AbstractAuthenticationEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(AbstractAuthenticationEvent event) {
	Authentication source = event.getAuthentication();
	if (event instanceof AbstractAuthenticationFailureEvent) {
		Exception e = ((AbstractAuthenticationFailureEvent) event).getException();
		log.info(String.format("Authentication failure [user: %s] [error: %s]", source.getName(), e.getMessage()));
	} else if (event instanceof AuthenticationSuccessEvent) {
		String userName = source.getName();
		log.info(String.format("User logged in [user: %s]", userName));
		eventService.post(EventType.Login.toString(), userName, null);
	}
}
 
开发者ID:openanalytics,项目名称:shinyproxy,代码行数:13,代码来源:UserService.java

示例12: onApplicationEvent

import org.springframework.security.authentication.event.AbstractAuthenticationEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(AbstractAuthenticationEvent event) {
	if (event instanceof AbstractAuthenticationFailureEvent) {
		onAuthenticationFailureEvent((AbstractAuthenticationFailureEvent) event);
	}
	else if (this.webListener != null && this.webListener.accepts(event)) {
		this.webListener.process(this, event);
	}
	else {
		onAuthenticationEvent(event);
	}
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:13,代码来源:AuthenticationAuditListener.java

示例13: onAuthenticationEvent

import org.springframework.security.authentication.event.AbstractAuthenticationEvent; //导入依赖的package包/类
private void onAuthenticationEvent(AbstractAuthenticationEvent event) {
	Map<String, Object> data = new HashMap<String, Object>();
	if (event.getAuthentication().getDetails() != null) {
		data.put("details", event.getAuthentication().getDetails());
	}
	publish(new AuditEvent(event.getAuthentication().getName(),
			"AUTHENTICATION_SUCCESS", data));
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:9,代码来源:AuthenticationAuditListener.java

示例14: onApplicationEvent

import org.springframework.security.authentication.event.AbstractAuthenticationEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(AbstractAuthenticationEvent event) {
    // Authentication success
    if (event instanceof AuthenticationSuccessEvent) {
        handleAuthenticationSuccessEvent((AuthenticationSuccessEvent) event);
    }
    // Authentication failure
    if (event instanceof AbstractAuthenticationFailureEvent) {
        handleAuthenticationFailureEvent((AbstractAuthenticationFailureEvent) event);
    }
    // Authentication clear
    if (event instanceof AuthenticationCleanedEvent) {
        handleAuthenticationCleanedEvent((AuthenticationCleanedEvent) event);
    }
}
 
开发者ID:hflabs,项目名称:perecoder,代码行数:16,代码来源:AuthenticationEventListener.java

示例15: onApplicationEvent

import org.springframework.security.authentication.event.AbstractAuthenticationEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(AbstractAuthenticationEvent event) {
	Authentication authentication = event.getAuthentication();

	if (event instanceof AuthenticationSuccessEvent) {
	  ResourceOwnerPasswordResourceDetails resource = getResourceOwnerPasswordResourceDetails();
	  resource.setScope(Arrays.asList("words"));
	  resource.setUsername(authentication.getName());
	  resource.setPassword(authentication.getCredentials().toString());

	  try {
		  OAuth2AccessToken accessToken = accessTokenProvider.obtainAccessToken(resource, new DefaultAccessTokenRequest());
		  log.debug("Access token request succeeded for user: '{}', new token is '{}'"
				  , resource.getUsername() 
				  , accessToken.getValue());
		  if (authentication instanceof AbstractAuthenticationToken && authentication.getDetails() instanceof CustomAuthenticationDetails) {
			  ((CustomAuthenticationDetails) ((AbstractAuthenticationToken) authentication).getDetails())
			  	.setBearer(accessToken.getValue());
			  log.debug("Access token was added to authentication as details");
		  } else if (log.isDebugEnabled()) {
			  log.debug("Access token could not be added to authentication as details");
		  }
	  } catch (Exception e) {
		  log.error("Access token request failed for user: '" + resource.getUsername() + "'", e);
	  }
	}
	if (authentication instanceof CredentialsContainer) {
           // Authentication is complete. Remove credentials and other secret data from authentication
           ((CredentialsContainer)authentication).eraseCredentials();
       }
	
}
 
开发者ID:ishaigor,项目名称:rest-retro-sample,代码行数:33,代码来源:OAuthPostAuthListener.java


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