本文整理汇总了Java中org.springframework.security.web.context.HttpSessionSecurityContextRepository类的典型用法代码示例。如果您正苦于以下问题:Java HttpSessionSecurityContextRepository类的具体用法?Java HttpSessionSecurityContextRepository怎么用?Java HttpSessionSecurityContextRepository使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpSessionSecurityContextRepository类属于org.springframework.security.web.context包,在下文中一共展示了HttpSessionSecurityContextRepository类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: inspect
import org.springframework.security.web.context.HttpSessionSecurityContextRepository; //导入依赖的package包/类
/**
* @see org.atmosphere.cpr.AtmosphereInterceptor#inspect(org.atmosphere.cpr.AtmosphereResource)
*/
@Override
public Action inspect(final AtmosphereResource atmosphereResource) {
try {
SecurityContext context = (SecurityContext) atmosphereResource.getRequest().getSession().getAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY);
final Authentication auth = context.getAuthentication();
if (auth instanceof Authentication) {
MDC.put(UserMdcServletFilter.USER_KEY, auth.getName());
logger.trace("Username set in MDC");
}
} catch (final NullPointerException e) {}
return Action.CONTINUE;
}
示例2: alimenteSecurityUserCptMin
import org.springframework.security.web.context.HttpSessionSecurityContextRepository; //导入依赖的package包/类
/**
* Alimente la session pour un compte local
*
* @param cptMin
* le compte a minima a connecter
*/
public void alimenteSecurityUserCptMin(CompteMinima cptMin) {
SecurityUser user = (SecurityUser) getCurrentUser();
if (user != null) {
List<GrantedAuthority> authoritiesListe = new ArrayList<GrantedAuthority>();
SimpleGrantedAuthority sga = new SimpleGrantedAuthority(ConstanteUtils.ROLE_CANDIDAT);
authoritiesListe.add(sga);
SecurityUserCandidat securityUserCandidat = new SecurityUserCandidat(user.getUsername(),
user.getDisplayName(), authoritiesListe, cptMin.getIdCptMin(), cptMin.getNumDossierOpiCptMin(),
cptMin.getTemValidCptMin(), cptMin.getTemValidMailCptMin(), null);
UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(
securityUserCandidat, securityUserCandidat.getUsername(), securityUserCandidat.getAuthorities());
Authentication authentication = authenticationManagerCandidat.authenticate(authRequest);
SecurityContext context = SecurityContextHolder.createEmptyContext();
context.setAuthentication(authentication);
SecurityContextHolder.setContext(context);
UI.getCurrent().getSession().getSession()
.setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY, context);
}
}
示例3: getUser
import org.springframework.security.web.context.HttpSessionSecurityContextRepository; //导入依赖的package包/类
/**
* @param user
* @return un user
*/
public UserDetails getUser(SessionPresentation user){
for (MainUI ui : getUis()){
try{
VaadinSession session = ui.getSession();
if (session == null || session.getSession()==null){
return null;
}
SecurityContext securityContext = (SecurityContext) session.getSession().getAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY);
if (securityContext==null || securityContext.getAuthentication()==null){
return null;
}else{
UserDetails details = (UserDetails) securityContext.getAuthentication().getPrincipal();
if (details!=null && details.getUsername().equals(user.getId())){
return details;
}
}
}catch (Exception e){}
}
return null;
}
示例4: deleteCandidat
import org.springframework.security.web.context.HttpSessionSecurityContextRepository; //导入依赖的package包/类
public void deleteCandidat() {
SecurityUserCandidat cand = userController.getSecurityUserCandidat();
if (cand != null) {
CompteMinima cpt = compteMinimaRepository.findOne(cand.getIdCptMin());
if (cpt != null) {
logger.debug("Delete compte NoDossier = " + cpt.getNumDossierOpiCptMin());
compteMinimaRepository.delete(cpt);
uiController.unregisterUiCandidat(MainUI.getCurrent());
SecurityContext context = SecurityContextHolder.createEmptyContext();
SecurityContextHolder.setContext(context);
UI.getCurrent().getSession().getSession()
.setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY, context);
MainUI current = (MainUI) UI.getCurrent();
uiController.registerUiCandidat(current);
current.navigateToAccueilView();
}
}
}
示例5: authorize
import org.springframework.security.web.context.HttpSessionSecurityContextRepository; //导入依赖的package包/类
@RequestMapping(value = "/authenticate", method = { RequestMethod.POST })
@ResponseBody
public String authorize(
@RequestBody AuthenticationRequest authenticationRequest,
HttpServletRequest request) {
final UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(
authenticationRequest.getUsername(), authenticationRequest.getPassword());
final Authentication authentication = this.authenticationManager.authenticate(token);
SecurityContextHolder.getContext().setAuthentication(authentication);
final HttpSession session = request.getSession(true);
session.setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY,
SecurityContextHolder.getContext());
return session.getId();
}
示例6: doFilter
import org.springframework.security.web.context.HttpSessionSecurityContextRepository; //导入依赖的package包/类
@Override
public void doFilter(final ServletRequest servletRequest,
final ServletResponse servletResponse,
final FilterChain filterChain) throws IOException, ServletException {
// To be consistent with SAML configuration, the `userDetails` is set as `principal` too
final UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(
user,
null,
user.getAuthorities());
// setting user details
authentication.setDetails(user);
// setting `authentication` to security context
final SecurityContext securityContext = SecurityContextHolder.getContext();
securityContext.setAuthentication(authentication);
// setting `authentication` to HTTP session
((HttpServletRequest) servletRequest)
.getSession(true)
.setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY, securityContext);
filterChain.doFilter(servletRequest, servletResponse);
}
示例7: readSecurityContextFromSession
import org.springframework.security.web.context.HttpSessionSecurityContextRepository; //导入依赖的package包/类
protected SecurityContext readSecurityContextFromSession(HttpSession httpSession) {
if (httpSession == null) {
return null;
}
Object ctxFromSession = httpSession.getAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY);
if (ctxFromSession == null) {
return null;
}
if (!(ctxFromSession instanceof SecurityContext)) {
return null;
}
return (SecurityContext) ctxFromSession;
}
示例8: doDispatch
import org.springframework.security.web.context.HttpSessionSecurityContextRepository; //导入依赖的package包/类
private void doDispatch(final List<TenantAwareEvent> events, final WrappedSession wrappedSession) {
final SecurityContext userContext = (SecurityContext) wrappedSession
.getAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY);
final SecurityContext oldContext = SecurityContextHolder.getContext();
try {
SecurityContextHolder.setContext(userContext);
final List<EventContainer<TenantAwareEvent>> groupedEvents = groupEvents(events, userContext,
eventProvider);
vaadinUI.access(() -> {
if (vaadinSession.getState() != State.OPEN) {
return;
}
LOG.debug("UI EventBus aggregator of UI {} got lock on session.", vaadinUI.getUIId());
groupedEvents.forEach(holder -> eventBus.publish(vaadinUI, holder));
LOG.debug("UI EventBus aggregator of UI {} left lock on session.", vaadinUI.getUIId());
}).get();
} catch (InterruptedException | ExecutionException e) {
LOG.warn("Wait for Vaadin session for UI {} interrupted!", vaadinUI.getUIId(), e);
} finally {
SecurityContextHolder.setContext(oldContext);
}
}
示例9: validateTokenAndLoginUser
import org.springframework.security.web.context.HttpSessionSecurityContextRepository; //导入依赖的package包/类
@Override
@Transactional
public void validateTokenAndLoginUser(String token, HttpServletRequest request, HttpServletResponse response) throws IOException {
PasswordRecovery recovery = findForToken(token);
if (validateRecovery(recovery)) {
MotechUser user = motechUsersDao.findUserByEmail(recovery.getEmail());
OpenIDAuthenticationToken openIDToken = new OpenIDAuthenticationToken(OpenIDAuthenticationStatus.SUCCESS, user.getOpenId(), "one time login ", new ArrayList<>());
Authentication authentication = authenticationManager.authenticate(openIDToken);
SecurityContextHolder.getContext().setAuthentication(authentication);
request.getSession(true).setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY, SecurityContextHolder.getContext());
passwordRecoveriesDataService.delete(recovery);
redirectStrategy.sendRedirect(request, response, "/server/home");
} else {
redirectStrategy.sendRedirect(request, response, "/server/login");
}
}
示例10: addFilters
import org.springframework.security.web.context.HttpSessionSecurityContextRepository; //导入依赖的package包/类
private List<Filter> addFilters(MotechURLSecurityRule securityRule) throws ServletException {
List<Filter> filters = new ArrayList<>();
SecurityContextRepository contextRepository = new HttpSessionSecurityContextRepository();
RequestCache requestCache = new HttpSessionRequestCache();
addSecureChannel(filters, securityRule.getProtocol());
addSecurityContextPersistenceFilter(filters, contextRepository);
addLogoutFilter(filters, securityRule);
addAuthenticationFilters(filters, securityRule);
addRequestCacheFilter(filters, requestCache);
addSecurityContextHolderAwareRequestFilter(filters);
addAnonymousAuthenticationFilter(filters);
addSessionManagementFilter(filters, contextRepository);
addExceptionTranslationFilter(filters, requestCache, securityRule.isRest());
addFilterSecurityInterceptor(filters, securityRule);
return filters;
}
示例11: login
import org.springframework.security.web.context.HttpSessionSecurityContextRepository; //导入依赖的package包/类
protected MockHttpSession login() throws Exception {
MockHttpSession httpSession = new MockHttpSession();
String principal = "a";
String credentials = "a";
List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
authorities.add(new SimpleGrantedAuthority("ROLE_ANONYMOUS"));
authorities.add(new SimpleGrantedAuthority("ROLE_USER"));
authorities.add(new SimpleGrantedAuthority("ROLE_ADMIN"));
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(principal, credentials, authorities);
httpSession.setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY, SecurityContextHolder.getContext());
SecurityContextHolder.getContext().setAuthentication(authentication);
logger.debug("===========================================================");
logger.debug(""+SecurityContextHolder.getContext().getAuthentication());
logger.debug("===========================================================");
return httpSession;
}
示例12: setup
import org.springframework.security.web.context.HttpSessionSecurityContextRepository; //导入依赖的package包/类
@Before
public void setup() {
controller = new PictureController();
controller.userUtil = userUtil;
controller.factory = factory;
controller.fileUtil = fileUtil;
controller.latestPictureLimit = 10;
controller.hookHandler = hookHandler;
mvc = MockMvcBuilders.standaloneSetup(controller).setMessageConverters(new EntityConverter(factory),
new StringHttpMessageConverter(), new ResourceHttpMessageConverter()).build();
setAuthentication(owner);
// TODO this information should be pulled out from somewhere else
factory.create(User.class).setUsername(ownr).setPassword("1").setMemberSince(DateTime.now()).setPictureCount(
new AtomicInteger(0)).save();
session = new MockHttpSession();
session.setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY,
SecurityContextHolder.getContext());
}
示例13: mockHttpSession
import org.springframework.security.web.context.HttpSessionSecurityContextRepository; //导入依赖的package包/类
public MockHttpSession mockHttpSession(boolean secured) {
MockHttpSession mockSession = new MockHttpSession();
SecurityContext mockSecurityContext = mock(SecurityContext.class);
if (secured) {
ExpiringUsernameAuthenticationToken principal =
new ExpiringUsernameAuthenticationToken(null, USER_DETAILS, USER_NAME, AUTHORITIES);
principal.setDetails(USER_DETAILS);
when(mockSecurityContext.getAuthentication()).thenReturn(principal);
}
SecurityContextHolder.setContext(mockSecurityContext);
mockSession.setAttribute(
HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY,
mockSecurityContext);
return mockSession;
}
示例14: mockAnonymousHttpSession
import org.springframework.security.web.context.HttpSessionSecurityContextRepository; //导入依赖的package包/类
public MockHttpSession mockAnonymousHttpSession() {
MockHttpSession mockSession = new MockHttpSession();
SecurityContext mockSecurityContext = mock(SecurityContext.class);
AnonymousAuthenticationToken principal =
new AnonymousAuthenticationToken(
ANONYMOUS_USER_KEY,
ANONYMOUS_USER_PRINCIPAL,
AUTHORITIES);
when(mockSecurityContext.getAuthentication()).thenReturn(principal);
SecurityContextHolder.setContext(mockSecurityContext);
mockSession.setAttribute(
HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY,
mockSecurityContext);
return mockSession;
}
示例15: authenticate
import org.springframework.security.web.context.HttpSessionSecurityContextRepository; //导入依赖的package包/类
@Override
public boolean authenticate(String username, String password) {
boolean authenticated;
try {
Authentication authentication = authenticationManager.authenticate(
new UsernamePasswordAuthenticationToken(username, password));
SecurityContextHolder.getContext().setAuthentication(authentication);
httpSession.setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY,
SecurityContextHolder.getContext());
authenticated = authentication.isAuthenticated();
} catch (AuthenticationException e) {
log.warn("User '{}' failed to login. Reason: {}", username, e.getMessage());
authenticated = false;
}
return authenticated;
}
开发者ID:mpostelnicu,项目名称:wicket-spring-jpa-bootstrap-boilerplate,代码行数:17,代码来源:SSAuthenticatedWebSession.java