use of org.springframework.security.authentication.AnonymousAuthenticationToken in project cia by Hack23.
the class HttpSessionDestroyedEventListener method onApplicationEvent.
@Override
public void onApplicationEvent(final HttpSessionDestroyedEvent event) {
final HttpSession httpSession = event.getSession();
final Collection<SimpleGrantedAuthority> authorities = new ArrayList<>();
authorities.add(new SimpleGrantedAuthority(ROLE_ANONYMOUS));
final DestroyApplicationSessionRequest destroyApplicationSessionRequest = new DestroyApplicationSessionRequest();
destroyApplicationSessionRequest.setSessionId(httpSession.getId());
SecurityContextHolder.getContext().setAuthentication(new AnonymousAuthenticationToken(KEY, PRINCIPAL, authorities));
applicationManager.service(destroyApplicationSessionRequest);
SecurityContextHolder.getContext().setAuthentication(null);
LOGGER.info(LOG_MSG_SESSION_DESTROYED_SESSION_ID, httpSession.getId());
}
use of org.springframework.security.authentication.AnonymousAuthenticationToken in project irida by phac-nml.
the class IridaApiServicesConfig method createAnalysisTaskSecurityContext.
/**
* Creates a security context object for the analysis tasks.
*
* @param userService
* A {@link UserService}.
*
* @return A {@link SecurityContext} for the analysis tasks.
*/
private SecurityContext createAnalysisTaskSecurityContext(UserService userService) {
SecurityContext context = SecurityContextHolder.createEmptyContext();
Authentication anonymousToken = new AnonymousAuthenticationToken("nobody", "nobody", ImmutableList.of(Role.ROLE_ANONYMOUS));
Authentication oldAuthentication = SecurityContextHolder.getContext().getAuthentication();
SecurityContextHolder.getContext().setAuthentication(anonymousToken);
User admin = userService.getUserByUsername("admin");
SecurityContextHolder.getContext().setAuthentication(oldAuthentication);
Authentication adminAuthentication = new PreAuthenticatedAuthenticationToken(admin, null, Lists.newArrayList(Role.ROLE_ADMIN));
context.setAuthentication(adminAuthentication);
return context;
}
use of org.springframework.security.authentication.AnonymousAuthenticationToken in project irida by phac-nml.
the class IridaScheduledTasksConfig method createSchedulerSecurityContext.
/**
* Creates a security context object for the scheduled tasks.
*
* @return A {@link SecurityContext} for the scheduled tasks.
*/
private SecurityContext createSchedulerSecurityContext() {
SecurityContext context = SecurityContextHolder.createEmptyContext();
Authentication anonymousToken = new AnonymousAuthenticationToken("nobody", "nobody", ImmutableList.of(Role.ROLE_ANONYMOUS));
Authentication oldAuthentication = SecurityContextHolder.getContext().getAuthentication();
SecurityContextHolder.getContext().setAuthentication(anonymousToken);
User admin = userService.getUserByUsername("admin");
SecurityContextHolder.getContext().setAuthentication(oldAuthentication);
Authentication adminAuthentication = new PreAuthenticatedAuthenticationToken(admin, null, Lists.newArrayList(Role.ROLE_ADMIN));
context.setAuthentication(adminAuthentication);
return context;
}
use of org.springframework.security.authentication.AnonymousAuthenticationToken in project irida by phac-nml.
the class PasswordResetController method setAuthentication.
/**
* Set an anonymous authentication token
*/
private void setAuthentication() {
AnonymousAuthenticationToken anonymousToken = new AnonymousAuthenticationToken("nobody", "nobody", ImmutableList.of(Role.ROLE_ANONYMOUS));
SecurityContextHolder.getContext().setAuthentication(anonymousToken);
}
use of org.springframework.security.authentication.AnonymousAuthenticationToken in project beetl2.0 by javamonkey.
the class AuthenticationFunction method call.
@Override
public Object call(Object[] paras, Context ctx) {
// 获取安全上下文
SecurityContext securityContext = SecurityContextHolder.getContext();
Authentication authentication = securityContext != null ? securityContext.getAuthentication() : null;
// 获取认证凭证
return ((authentication == null) || (authentication instanceof AnonymousAuthenticationToken)) ? null : authentication;
}
Aggregations