當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。