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


Java SecurityContextHolder.createEmptyContext方法代码示例

本文整理汇总了Java中org.springframework.security.core.context.SecurityContextHolder.createEmptyContext方法的典型用法代码示例。如果您正苦于以下问题:Java SecurityContextHolder.createEmptyContext方法的具体用法?Java SecurityContextHolder.createEmptyContext怎么用?Java SecurityContextHolder.createEmptyContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.security.core.context.SecurityContextHolder的用法示例。


在下文中一共展示了SecurityContextHolder.createEmptyContext方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createSecurityContext

import org.springframework.security.core.context.SecurityContextHolder; //导入方法依赖的package包/类
public SecurityContext createSecurityContext(pingis.entities.User customUser) {
  SecurityContext context = SecurityContextHolder.createEmptyContext();

  TmcUserDto principal = new TmcUserDto(Long.toString(customUser.getId()),
          customUser.getName(),
          TEST_EMAIL,
          customUser.isAdministrator());

  Authentication authentication = new UsernamePasswordAuthenticationToken(principal,
          "password",
          principal.getAuthorities());

  context.setAuthentication(authentication);

  return context;
}
 
开发者ID:tdd-pingis,项目名称:tdd-pingpong,代码行数:17,代码来源:WithMockCustomUserSecurityContextFactory.java

示例2: setup

import org.springframework.security.core.context.SecurityContextHolder; //导入方法依赖的package包/类
@Before
public void setup() {

	if (this.registry != null) {
		this.registry.clear();
	}

	this.context = SecurityContextHolder.createEmptyContext();
	this.context.setAuthentication(
			new UsernamePasswordAuthenticationToken("username-" + UUID.randomUUID(),
					"na", AuthorityUtils.createAuthorityList("ROLE_USER")));

	this.changedContext = SecurityContextHolder.createEmptyContext();
	this.changedContext.setAuthentication(new UsernamePasswordAuthenticationToken(
			"changedContext-" + UUID.randomUUID(), "na",
			AuthorityUtils.createAuthorityList("ROLE_USER")));
}
 
开发者ID:spring-projects,项目名称:spring-session-data-mongodb,代码行数:18,代码来源:AbstractITest.java

示例3: alimenteSecurityUserCptMin

import org.springframework.security.core.context.SecurityContextHolder; //导入方法依赖的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

示例4: testIsAuthenticated

import org.springframework.security.core.context.SecurityContextHolder; //导入方法依赖的package包/类
@Test
public void testIsAuthenticated() {
    SecurityContext securityContext = SecurityContextHolder.createEmptyContext();
    securityContext.setAuthentication(new UsernamePasswordAuthenticationToken("admin", "admin"));
    SecurityContextHolder.setContext(securityContext);
    boolean isAuthenticated = SecurityUtils.isAuthenticated();
    assertThat(isAuthenticated).isTrue();
}
 
开发者ID:asanzdiego,项目名称:codemotion-2017-taller-de-jhipster,代码行数:9,代码来源:SecurityUtilsUnitTest.java

示例5: testAnonymousIsNotAuthenticated

import org.springframework.security.core.context.SecurityContextHolder; //导入方法依赖的package包/类
@Test
public void testAnonymousIsNotAuthenticated() {
    SecurityContext securityContext = SecurityContextHolder.createEmptyContext();
    Collection<GrantedAuthority> authorities = new ArrayList<>();
    authorities.add(new SimpleGrantedAuthority(AuthoritiesConstants.ANONYMOUS));
    securityContext.setAuthentication(new UsernamePasswordAuthenticationToken("anonymous", "anonymous", authorities));
    SecurityContextHolder.setContext(securityContext);
    boolean isAuthenticated = SecurityUtils.isAuthenticated();
    assertThat(isAuthenticated).isFalse();
}
 
开发者ID:xm-online,项目名称:xm-uaa,代码行数:11,代码来源:SecurityUtilsUnitTest.java

示例6: testgetCurrentUserLogin

import org.springframework.security.core.context.SecurityContextHolder; //导入方法依赖的package包/类
@Test
public void testgetCurrentUserLogin() {
    SecurityContext securityContext = SecurityContextHolder.createEmptyContext();
    securityContext.setAuthentication(new UsernamePasswordAuthenticationToken("admin", "admin"));
    SecurityContextHolder.setContext(securityContext);
    String login = SecurityUtils.getCurrentUserLogin();
    assertThat(login).isEqualTo("admin");
}
 
开发者ID:IBM,项目名称:Microservices-with-JHipster-and-Spring-Boot,代码行数:9,代码来源:SecurityUtilsUnitTest.java

示例7: testgetCurrentUserJWT

import org.springframework.security.core.context.SecurityContextHolder; //导入方法依赖的package包/类
@Test
public void testgetCurrentUserJWT() {
    SecurityContext securityContext = SecurityContextHolder.createEmptyContext();
    securityContext.setAuthentication(new UsernamePasswordAuthenticationToken("admin", "token"));
    SecurityContextHolder.setContext(securityContext);
    String jwt = SecurityUtils.getCurrentUserJWT();
    assertThat(jwt).isEqualTo("token");
}
 
开发者ID:deepu105,项目名称:spring-io,代码行数:9,代码来源:SecurityUtilsUnitTest.java

示例8: testIsCurrentUserInRole

import org.springframework.security.core.context.SecurityContextHolder; //导入方法依赖的package包/类
@Test
public void testIsCurrentUserInRole() {
    SecurityContext securityContext = SecurityContextHolder.createEmptyContext();
    Collection<GrantedAuthority> authorities = new ArrayList<>();
    authorities.add(new SimpleGrantedAuthority(AuthoritiesConstants.PATIENT));
    securityContext.setAuthentication(new UsernamePasswordAuthenticationToken("user", "user", authorities));
    SecurityContextHolder.setContext(securityContext);

    assertThat(SecurityUtils.isCurrentUserInRole(AuthoritiesConstants.PATIENT)).isTrue();
    assertThat(SecurityUtils.isCurrentUserInRole(AuthoritiesConstants.ADMIN)).isFalse();
}
 
开发者ID:michaelhoffmantech,项目名称:patient-portal,代码行数:12,代码来源:SecurityUtilsUnitTest.java

示例9: testCurrentUserInRole

import org.springframework.security.core.context.SecurityContextHolder; //导入方法依赖的package包/类
@Test
public void testCurrentUserInRole() {
    SecurityContext securityContext = SecurityContextHolder.createEmptyContext();
    Collection<GrantedAuthority> authorities = new ArrayList<>();
    authorities.add(new SimpleGrantedAuthority(AuthoritiesConstants.USER));
    securityContext.setAuthentication(new UsernamePasswordAuthenticationToken("user", "user", authorities));
    SecurityContextHolder.setContext(securityContext);
    boolean isInRole = SecurityUtils.isCurrentUserInRole(AuthoritiesConstants.USER);
    assertThat(isInRole).isFalse();
}
 
开发者ID:klask-io,项目名称:klask-io,代码行数:11,代码来源:SecurityUtilsUnitTest.java


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