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


Java HttpSessionSecurityContextRepository类代码示例

本文整理汇总了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;
}
 
开发者ID:EsupPortail,项目名称:esup-ecandidat,代码行数:16,代码来源:RecoverSecurityContextAtmosphereInterceptor.java

示例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);
	}
}
 
开发者ID:EsupPortail,项目名称:esup-ecandidat,代码行数:27,代码来源:UserController.java

示例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;
}
 
开发者ID:EsupPortail,项目名称:esup-ecandidat,代码行数:26,代码来源:UiController.java

示例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();
		}
	}
}
 
开发者ID:EsupPortail,项目名称:esup-ecandidat,代码行数:19,代码来源:TestController.java

示例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();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-dashboard,代码行数:17,代码来源:LoginController.java

示例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);
}
 
开发者ID:choonchernlim,项目名称:spring-security-adfs-saml2,代码行数:26,代码来源:MockFilterSecurityInterceptor.java

示例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;
}
 
开发者ID:akdasari,项目名称:SparkCommerce,代码行数:17,代码来源:SparkResourceHttpRequestHandler.java

示例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);
    }
}
 
开发者ID:eclipse,项目名称:hawkbit,代码行数:25,代码来源:DelayedEventBusPushStrategy.java

示例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");
    }
}
 
开发者ID:motech,项目名称:motech,代码行数:17,代码来源:PasswordRecoveryServiceImpl.java

示例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;
}
 
开发者ID:motech,项目名称:motech,代码行数:20,代码来源:SecurityRuleBuilder.java

示例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;
}
 
开发者ID:u2ware,项目名称:springfield,代码行数:21,代码来源:AbstractContextWebmvcSecurityTestRoot.java

示例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());
}
 
开发者ID:cherimojava,项目名称:orchidae,代码行数:23,代码来源:_PictureController.java

示例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;
}
 
开发者ID:vdenotaris,项目名称:spring-boot-security-saml-sample,代码行数:20,代码来源:CommonTestSupport.java

示例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;
}
 
开发者ID:vdenotaris,项目名称:spring-boot-security-saml-sample,代码行数:21,代码来源:CommonTestSupport.java

示例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


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