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


Java SecurityContextImpl类代码示例

本文整理汇总了Java中org.springframework.security.core.context.SecurityContextImpl的典型用法代码示例。如果您正苦于以下问题:Java SecurityContextImpl类的具体用法?Java SecurityContextImpl怎么用?Java SecurityContextImpl使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SecurityContextImpl类属于org.springframework.security.core.context包,在下文中一共展示了SecurityContextImpl类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setup

import org.springframework.security.core.context.SecurityContextImpl; //导入依赖的package包/类
@Before
public void setup() {
	resource = new ResourceOwnerPasswordResourceDetails();

	resource.setAccessTokenUri(serverRunning.getUrl("/sparklr2/oauth/token"));
	resource.setClientId("my-trusted-client");
	resource.setId("sparklr");
	resource.setScope(Arrays.asList("trust"));
	resource.setUsername("marissa");
	resource.setPassword("koala");

	OAuth2RestTemplate template = new OAuth2RestTemplate(resource);
	existingToken = template.getAccessToken();
	((DefaultOAuth2AccessToken) existingToken).setExpiration(new Date(0L));

	SecurityContextImpl securityContext = new SecurityContextImpl();
	securityContext.setAuthentication(new TestingAuthenticationToken("marissa", "koala", "ROLE_USER"));
	SecurityContextHolder.setContext(securityContext);

}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:21,代码来源:RefreshTokenGrantTests.java

示例2: shouldExtractPrincipalNameFromAuthentication

import org.springframework.security.core.context.SecurityContextImpl; //导入依赖的package包/类
@Test
public void shouldExtractPrincipalNameFromAuthentication() throws Exception {

	// given
	MongoSession toSerialize = new MongoSession();
	String principalName = "john_the_springer";
	SecurityContextImpl context = new SecurityContextImpl();
	context.setAuthentication(
			new UsernamePasswordAuthenticationToken(principalName, null));
	toSerialize.setAttribute("SPRING_SECURITY_CONTEXT", context);

	// when
	DBObject dbObject = convertToDBObject(toSerialize);

	// then
	assertThat(dbObject.get("principal")).isEqualTo(principalName);
}
 
开发者ID:spring-projects,项目名称:spring-session-data-mongodb,代码行数:18,代码来源:JdkMongoSessionConverterTest.java

示例3: filter

import org.springframework.security.core.context.SecurityContextImpl; //导入依赖的package包/类
@Override
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
	return authenticationConverter.convert(exchange)
		.then( token -> {
			return authenticationManager.authenticate(token)
				.then(authentication -> {
					SecurityContext context = new SecurityContextImpl();
					context.setAuthentication(authentication);
					return securityContextRepository
						.save(exchange, context)
						.then( () ->{
							return chain.filter(exchange);
						});
				})
				.otherwise( AuthenticationException.class, t -> {
					return entryPoint.commence(exchange, t);
				});
		})
		.otherwiseIfEmpty(Mono.defer(() -> {
			return chain.filter(exchange);
		}));
}
 
开发者ID:guilhebl,项目名称:item-shop-reactive-backend,代码行数:23,代码来源:AuthenticationWebFilter.java

示例4: before

import org.springframework.security.core.context.SecurityContextImpl; //导入依赖的package包/类
@Around("execution(org.springframework.web.servlet.ModelAndView org.gra4j.dataMigration.controller..*.*(..)) "
        + " and @annotation(org.springframework.web.bind.annotation.RequestMapping)")
public Object before(ProceedingJoinPoint pjp) throws Throwable {
    // 从切点上获取目标方法
    MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
    Method method = methodSignature.getMethod();
    // 若目标方法忽略了安全性检查,则直接调用目标方法
    if (method.isAnnotationPresent(UnCheck.class))
        return pjp.proceed();

    if (StringUtils.isEmpty(tokenName))
        tokenName = DEFAULT_TOKEN_NAME;

    HttpServletRequest request = WebContext.getRequest();
    HttpServletResponse response = WebContext.getResponse();
    String token = tokenManager.createToken(
            ((SecurityContextImpl) request.getSession()
                                          .getAttribute("SPRING_SECURITY_CONTEXT"))
                                          .getAuthentication()
                                          .getName());
    response.addHeader(tokenName,token);

    return pjp.proceed();
}
 
开发者ID:finefuture,项目名称:data-migration,代码行数:25,代码来源:TokenAspect.java

示例5: materiasImaginie

import org.springframework.security.core.context.SecurityContextImpl; //导入依赖的package包/类
@RequestMapping("/materias/imaginie")
public ModelAndView materiasImaginie(HttpSession session, HttpServletResponse httpServletResponse)
       {

           SecurityContextImpl context = (SecurityContextImpl) session.getAttribute("SPRING_SECURITY_CONTEXT");
           User user = (User) context.getAuthentication().getPrincipal();
           
           ImaginieLogin imaginieLogin = new ImaginieLogin(user);
           String requestURL = imaginieLogin.connect();
           
           if(requestURL != null){
               return new ModelAndView("redirect:" + requestURL);
           } else 
           {
               return new ModelAndView("404");
           }           
           
       }
 
开发者ID:ismartonline,项目名称:ismartonline,代码行数:19,代码来源:ModuloController.java

示例6: filter

import org.springframework.security.core.context.SecurityContextImpl; //导入依赖的package包/类
@Override
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
	return authenticationConverter.convert(exchange)
		.flatMap( token -> {
			return authenticationManager.authenticate(token)
				.flatMap(authentication -> {
					SecurityContext context = new SecurityContextImpl();
					context.setAuthentication(authentication);
					return securityContextRepository
						.save(exchange, context)
						.flatMap( value ->{
							return chain.filter(exchange);
						});
				})
				.onErrorResume( AuthenticationException.class, t -> {
					return entryPoint.commence(exchange, t);
				});
		})
		.switchIfEmpty(Mono.defer(() -> {
			return chain.filter(exchange);
		}));
}
 
开发者ID:spring-projects,项目名称:spring-security-reactive,代码行数:23,代码来源:AuthenticationWebFilter.java

示例7: setUp

import org.springframework.security.core.context.SecurityContextImpl; //导入依赖的package包/类
/**
 * JAVADOC Method Level Comments
 *
 * @throws Exception JAVADOC.
 */
@Before
public void setUp()
    throws Exception {
    MockitoAnnotations.initMocks(this);
    interceptor = new CurrentUserChannelInterceptor(systemUserService, userAccessor);

    if (null == SecurityContextHolder.getContext()) {
        SecurityContextHolder.setContext(new SecurityContextImpl());
    }

    SecurityContext context = SecurityContextHolder.getContext();

    user = new User();
    user.setName("user");

    AbstractAuthenticationToken authToken = new UsernamePasswordAuthenticationToken(user, null);

    authToken.setDetails("pipipi");
    context.setAuthentication(authToken);
}
 
开发者ID:cucina,项目名称:opencucina,代码行数:26,代码来源:CurrentUserChannelInterceptorTest.java

示例8: testWithNull

import org.springframework.security.core.context.SecurityContextImpl; //导入依赖的package包/类
/**
 * JAVADOC Method Level Comments
 *
 * @throws Throwable JAVADOC.
 */
@Test
public void testWithNull()
    throws Throwable {
    if (null == SecurityContextHolder.getContext()) {
        SecurityContextHolder.setContext(new SecurityContextImpl());
    }

    //mock systemUserService returns username
    String systemUsername = "ADMIN";

    when(systemUserService.getUsername()).thenReturn(systemUsername);

    SystemUserMethodInterceptor interceptor = new SystemUserMethodInterceptor(userAccessor,
            systemUserService);

    interceptor.invoke(methodInvocation);
    //mock authenticatioNService call
    verify(userAccessor).forceUserToContext(systemUsername);
    verify(methodInvocation).proceed();

    //test it switches back
    assertEquals(CurrentUserAccessor.currentAuthentication(), null);
}
 
开发者ID:cucina,项目名称:opencucina,代码行数:29,代码来源:SystemUserMethodInterceptorTest.java

示例9: setUp

import org.springframework.security.core.context.SecurityContextImpl; //导入依赖的package包/类
@Override
   protected void setUp() throws Exception {
super.setUp();

// store initial security context for later restoration
initialSecurityContext = SecurityContextHolder.getContext();

SecurityContext context = new SecurityContextImpl();
User user = new User("user");
user.setId(1L);
user.setPassword("password");
user.addRole(new Role(Constants.USER_ROLE));

UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(
	user.getUsername(), user.getPassword(), user.getAuthorities());
token.setDetails(user);
context.setAuthentication(token);
SecurityContextHolder.setContext(context);
   }
 
开发者ID:gisgraphy,项目名称:gisgraphy,代码行数:20,代码来源:UserSecurityAdviceTest.java

示例10: testAddUserAsAdmin

import org.springframework.security.core.context.SecurityContextImpl; //导入依赖的package包/类
public void testAddUserAsAdmin() throws Exception {
SecurityContext context = new SecurityContextImpl();
User user = new User("admin");
user.setId(2L);
user.setPassword("password");
user.addRole(new Role(Constants.ADMIN_ROLE));
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(
	user.getUsername(), user.getPassword(), user.getAuthorities());
token.setDetails(user);
context.setAuthentication(token);
SecurityContextHolder.setContext(context);

UserManager userManager = makeInterceptedTarget();
User adminUser = new User("admin");
adminUser.setId(2L);

userDao.expects(once()).method("saveUser");
userManager.saveUser(adminUser);
   }
 
开发者ID:gisgraphy,项目名称:gisgraphy,代码行数:20,代码来源:UserSecurityAdviceTest.java

示例11: testAddUserRoleWhenHasAdminRole

import org.springframework.security.core.context.SecurityContextImpl; //导入依赖的package包/类
public void testAddUserRoleWhenHasAdminRole() throws Exception {
SecurityContext context = new SecurityContextImpl();
User user1 = new User("user");
user1.setId(1L);
user1.setPassword("password");
user1.addRole(new Role(Constants.ADMIN_ROLE));
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(
	user1.getUsername(), user1.getPassword(), user1
		.getAuthorities());
token.setDetails(user1);
context.setAuthentication(token);
SecurityContextHolder.setContext(context);

UserManager userManager = makeInterceptedTarget();
User user = new User("user");
user.setId(1L);
user.getRoles().add(new Role(Constants.ADMIN_ROLE));
user.getRoles().add(new Role(Constants.USER_ROLE));

userDao.expects(once()).method("saveUser");
userManager.saveUser(user);
   }
 
开发者ID:gisgraphy,项目名称:gisgraphy,代码行数:23,代码来源:UserSecurityAdviceTest.java

示例12: setUp

import org.springframework.security.core.context.SecurityContextImpl; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    // store initial security context for later restoration
    initialSecurityContext = SecurityContextHolder.getContext();

    SecurityContext context = new SecurityContextImpl();
    User user = new User("user");
    user.setId(1L);
    user.setPassword("password");
    user.addRole(new Role(Constants.USER_ROLE));

    UsernamePasswordAuthenticationToken token =
            new UsernamePasswordAuthenticationToken(user.getUsername(), user.getPassword(), user.getAuthorities());
    token.setDetails(user);
    context.setAuthentication(token);
    SecurityContextHolder.setContext(context);
}
 
开发者ID:SMVBE,项目名称:ldadmin,代码行数:18,代码来源:UserSecurityAdviceTest.java

示例13: testAddUserAsAdmin

import org.springframework.security.core.context.SecurityContextImpl; //导入依赖的package包/类
@Test
public void testAddUserAsAdmin() throws Exception {
    SecurityContext securityContext = new SecurityContextImpl();
    User user = new User("admin");
    user.setId(2L);
    user.setPassword("password");
    user.addRole(new Role(Constants.ADMIN_ROLE));
    UsernamePasswordAuthenticationToken token =
            new UsernamePasswordAuthenticationToken(user.getUsername(), user.getPassword(), user.getAuthorities());
    token.setDetails(user);
    securityContext.setAuthentication(token);
    SecurityContextHolder.setContext(securityContext);

    UserManager userManager = makeInterceptedTarget();
    final User adminUser = new User("admin");
    adminUser.setId(2L);

    given(userDao.saveUser(adminUser)).willReturn(adminUser);
    given(passwordEncoder.encode(adminUser.getPassword())).willReturn(adminUser.getPassword());

    userManager.saveUser(adminUser);
}
 
开发者ID:SMVBE,项目名称:ldadmin,代码行数:23,代码来源:UserSecurityAdviceTest.java

示例14: testAddUserRoleWhenHasAdminRole

import org.springframework.security.core.context.SecurityContextImpl; //导入依赖的package包/类
@Test
public void testAddUserRoleWhenHasAdminRole() throws Exception {
    SecurityContext securityContext = new SecurityContextImpl();
    User user1 = new User("user");
    user1.setId(1L);
    user1.setPassword("password");
    user1.addRole(new Role(Constants.ADMIN_ROLE));
    UsernamePasswordAuthenticationToken token =
            new UsernamePasswordAuthenticationToken(user1.getUsername(), user1.getPassword(), user1.getAuthorities());
    token.setDetails(user1);
    securityContext.setAuthentication(token);
    SecurityContextHolder.setContext(securityContext);

    UserManager userManager = makeInterceptedTarget();
    final User user = new User("user");
    user.setId(1L);
    user.getRoles().add(new Role(Constants.ADMIN_ROLE));
    user.getRoles().add(new Role(Constants.USER_ROLE));

    given(userDao.saveUser(user)).willReturn(user);
    given(passwordEncoder.encode(user.getPassword())).willReturn(user.getPassword());

    userManager.saveUser(user);
}
 
开发者ID:SMVBE,项目名称:ldadmin,代码行数:25,代码来源:UserSecurityAdviceTest.java

示例15: setUp

import org.springframework.security.core.context.SecurityContextImpl; //导入依赖的package包/类
@BeforeMethod
public void setUp() {
    // create new security context
    securityContext = new SecurityContextImpl();
    SecurityContextHolder.setContext(securityContext);

    // new service instance
    service = new SecurityServiceImpl();
    // set the aclManager mock on the security service
    ReflectionTestUtils.setField(service, "userGroupStoreService", userGroupStoreService);
    ReflectionTestUtils.setField(service, "aclStoreService", aclStoreServiceMock);
    ReflectionTestUtils.setField(service, "repositoryService", repositoryServiceMock);
    ReflectionTestUtils.setField(service, "centralConfig", centralConfigServiceMock);

    // reset mocks
    reset(aclStoreServiceMock, repositoryServiceMock, centralConfigServiceMock);
}
 
开发者ID:alancnet,项目名称:artifactory,代码行数:18,代码来源:SecurityServiceImplTest.java


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