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


Java TestingAuthenticationToken.setAuthenticated方法代码示例

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


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

示例1: getAuthentication

import org.springframework.security.authentication.TestingAuthenticationToken; //导入方法依赖的package包/类
/**
 * Provide the mock user information to be used
 * 
 * @param withMockOAuth2Token
 * @return
 */
private Authentication getAuthentication(WithMockOAuth2Token withMockOAuth2Token) {
	List<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList(withMockOAuth2Token.authorities());

	User userPrincipal = new User(withMockOAuth2Token.userName(), withMockOAuth2Token.password(), true, true, true,
			true, authorities);

	HashMap<String, String> details = new HashMap<String, String>();
	details.put("user_name", withMockOAuth2Token.userName());
	details.put("email", "[email protected]");
	details.put("name", "Anil Allewar");

	TestingAuthenticationToken token = new TestingAuthenticationToken(userPrincipal, null, authorities);
	token.setAuthenticated(true);
	token.setDetails(details);

	return token;
}
 
开发者ID:anilallewar,项目名称:microservices-basics-spring-boot,代码行数:24,代码来源:WithOAuth2MockAccessTokenSecurityContextFactory.java

示例2: addStreamExtendsOwned

import org.springframework.security.authentication.TestingAuthenticationToken; //导入方法依赖的package包/类
@Test
public void addStreamExtendsOwned()
{
	TestingAuthenticationToken authentication = new TestingAuthenticationToken("username", null);
	authentication.setAuthenticated(false);
	SecurityContextHolder.getContext().setAuthentication(authentication);
	when(entityType.getExtends()).thenReturn(new OwnedEntityType(mock(SecurityPackage.class)));

	Entity entity0 = mock(Entity.class);
	when(entity0.getIdValue()).thenReturn("0");
	Entity entity1 = mock(Entity.class);
	when(entity1.getIdValue()).thenReturn("0");
	Stream<Entity> entities = Stream.of(entity0, entity1);
	ownedEntityRepositoryDecorator.add(entities);

	@SuppressWarnings({ "unchecked", "rawtypes" })
	ArgumentCaptor<Stream<Entity>> captor = ArgumentCaptor.forClass(Stream.class);
	verify(delegateRepository, times(1)).add(captor.capture());
	List<Entity> myEntities = captor.getValue().collect(Collectors.toList());
	assertEquals(myEntities, asList(entity0, entity1));
	verify(entity0, times(1)).set(OwnedEntityType.OWNER_USERNAME, "username");
	verify(entity1, times(1)).set(OwnedEntityType.OWNER_USERNAME, "username");
}
 
开发者ID:molgenis,项目名称:molgenis,代码行数:24,代码来源:OwnedEntityRepositoryDecoratorTest.java

示例3: findAllPermission

import org.springframework.security.authentication.TestingAuthenticationToken; //导入方法依赖的package包/类
@Test
public void findAllPermission()
{
	TestingAuthenticationToken authentication = new TestingAuthenticationToken("username", null,
			"ROLE_ENTITY_READ_" + entityId);
	authentication.setAuthenticated(false);
	SecurityContextHolder.getContext().setAuthentication(authentication);

	Stream<Object> ids = Stream.of(0, 1);
	Fetch fetch = new Fetch();
	Entity entity0 = mock(Entity.class);
	Entity entity1 = mock(Entity.class);
	Stream<Entity> entities = Stream.of(entity0, entity1);
	when(delegateRepository.findAll(ids, fetch)).thenReturn(Stream.of(entity0, entity1));
	assertEquals(entities.collect(toList()), repositorySecurityDecorator.findAll(ids, fetch).collect(toList()));
	verify(delegateRepository, times(1)).findAll(ids, fetch);
}
 
开发者ID:molgenis,项目名称:molgenis,代码行数:18,代码来源:RepositorySecurityDecoratorTest.java

示例4: findAllStreamFetchExtendsOwned

import org.springframework.security.authentication.TestingAuthenticationToken; //导入方法依赖的package包/类
@Test
public void findAllStreamFetchExtendsOwned()
{
	TestingAuthenticationToken authentication = new TestingAuthenticationToken("username", null);
	authentication.setAuthenticated(false);
	SecurityContextHolder.getContext().setAuthentication(authentication);
	when(entityType.getExtends()).thenReturn(new OwnedEntityType(mock(SecurityPackage.class)));

	Fetch fetch = new Fetch();
	Object id0 = "id0";
	Object id1 = "id1";
	Entity entity0 = when(mock(Entity.class).getString(OWNER_USERNAME)).thenReturn("username").getMock();
	Entity entity1 = when(mock(Entity.class).getString(OWNER_USERNAME)).thenReturn("username").getMock();
	Stream<Object> entityIds = Stream.of(id0, id1);
	Fetch decoratedFetch = new Fetch().field(OWNER_USERNAME);
	when(delegateRepository.findAll(entityIds, decoratedFetch)).thenReturn(Stream.of(entity0, entity1));
	Stream<Entity> expectedEntities = ownedEntityRepositoryDecorator.findAll(entityIds, fetch);
	assertEquals(expectedEntities.collect(Collectors.toList()), asList(entity0, entity1));
}
 
开发者ID:molgenis,项目名称:molgenis,代码行数:20,代码来源:OwnedEntityRepositoryDecoratorTest.java

示例5: consumeBatchedExtendsOwned

import org.springframework.security.authentication.TestingAuthenticationToken; //导入方法依赖的package包/类
@Test
public void consumeBatchedExtendsOwned()
{
	TestingAuthenticationToken authentication = new TestingAuthenticationToken("username", null);
	authentication.setAuthenticated(false);
	SecurityContextHolder.getContext().setAuthentication(authentication);
	when(entityType.getExtends()).thenReturn(new OwnedEntityType(mock(SecurityPackage.class)));

	Fetch fetch = new Fetch();
	Entity entity0 = when(mock(Entity.class).getString(OWNER_USERNAME)).thenReturn("username").getMock();
	Entity entity1 = when(mock(Entity.class).getString(OWNER_USERNAME)).thenReturn("username").getMock();
	Fetch decoratedFetch = new Fetch().field(OWNER_USERNAME);

	@SuppressWarnings("unchecked")
	Consumer<List<Entity>> consumer = mock(Consumer.class);
	ownedEntityRepositoryDecorator.forEachBatched(fetch, consumer, 123);

	verify(delegateRepository).forEachBatched(eq(decoratedFetch), consumerCaptor.capture(), eq(123));

	consumerCaptor.getValue().accept(asList(entity0, entity1));

	verify(consumer).accept(asList(entity0, entity1));
}
 
开发者ID:molgenis,项目名称:molgenis,代码行数:24,代码来源:OwnedEntityRepositoryDecoratorTest.java

示例6: updateStreamNoPermission

import org.springframework.security.authentication.TestingAuthenticationToken; //导入方法依赖的package包/类
@Test(expectedExceptions = MolgenisDataAccessException.class)
public void updateStreamNoPermission()
{
	TestingAuthenticationToken authentication = new TestingAuthenticationToken("username", null,
			"ROLE_ENTITY_READ_" + entityId);
	authentication.setAuthenticated(false);
	SecurityContextHolder.getContext().setAuthentication(authentication);

	Stream<Entity> entities = Stream.empty();
	try
	{
		repositorySecurityDecorator.update(entities);
	}
	catch (MolgenisDataAccessException e)
	{
		verify(delegateRepository, times(1)).getEntityType();
		verifyNoMoreInteractions(delegateRepository);
		throw e;
	}
}
 
开发者ID:molgenis,项目名称:molgenis,代码行数:21,代码来源:RepositorySecurityDecoratorTest.java

示例7: deleteStreamEntityExtendsOwned

import org.springframework.security.authentication.TestingAuthenticationToken; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
@Test
public void deleteStreamEntityExtendsOwned()
{
	TestingAuthenticationToken authentication = new TestingAuthenticationToken("username", null);
	authentication.setAuthenticated(false);
	SecurityContextHolder.getContext().setAuthentication(authentication);
	when(entityType.getExtends()).thenReturn(new OwnedEntityType(mock(SecurityPackage.class)));

	Entity myEntity = when(mock(Entity.class).getString(OWNER_USERNAME)).thenReturn("username").getMock();
	Entity notMyEntity = when(mock(Entity.class).getString(OWNER_USERNAME)).thenReturn("notme").getMock();
	ownedEntityRepositoryDecorator.delete(Stream.of(myEntity, notMyEntity));

	@SuppressWarnings("unchecked")
	ArgumentCaptor<Stream<Entity>> captor = ArgumentCaptor.forClass(Stream.class);
	verify(delegateRepository, times(1)).delete(captor.capture());
	List<Entity> myEntities = captor.getValue().collect(Collectors.toList());
	assertEquals(myEntities, asList(myEntity));
}
 
开发者ID:molgenis,项目名称:molgenis,代码行数:20,代码来源:OwnedEntityRepositoryDecoratorTest.java

示例8: findAllStreamFetchNoPermission

import org.springframework.security.authentication.TestingAuthenticationToken; //导入方法依赖的package包/类
@Test(expectedExceptions = MolgenisDataAccessException.class)
public void findAllStreamFetchNoPermission()
{
	TestingAuthenticationToken authentication = new TestingAuthenticationToken("username", null);
	authentication.setAuthenticated(false);
	SecurityContextHolder.getContext().setAuthentication(authentication);

	Fetch fetch = new Fetch();
	Object id0 = "id0";
	Object id1 = "id1";
	Entity entity0 = mock(Entity.class);
	Entity entity1 = mock(Entity.class);
	Stream<Object> entityIds = Stream.of(id0, id1);
	when(delegateRepository.findAll(entityIds, fetch)).thenReturn(Stream.of(entity0, entity1));
	repositorySecurityDecorator.findAll(entityIds, fetch);
}
 
开发者ID:molgenis,项目名称:molgenis,代码行数:17,代码来源:RepositorySecurityDecoratorTest.java

示例9: findAllStreamExtendsOwned

import org.springframework.security.authentication.TestingAuthenticationToken; //导入方法依赖的package包/类
@Test
public void findAllStreamExtendsOwned()
{
	TestingAuthenticationToken authentication = new TestingAuthenticationToken("username", null);
	authentication.setAuthenticated(false);
	SecurityContextHolder.getContext().setAuthentication(authentication);
	when(entityType.getExtends()).thenReturn(new OwnedEntityType(mock(SecurityPackage.class)));

	Object id0 = "id0";
	Object id1 = "id1";
	Entity entity0 = when(mock(Entity.class).getString(OWNER_USERNAME)).thenReturn("username").getMock();
	Entity entity1 = when(mock(Entity.class).getString(OWNER_USERNAME)).thenReturn("username").getMock();
	Stream<Object> entityIds = Stream.of(id0, id1);
	when(delegateRepository.findAll(entityIds)).thenReturn(Stream.of(entity0, entity1));
	Stream<Entity> expectedEntities = ownedEntityRepositoryDecorator.findAll(entityIds);
	assertEquals(expectedEntities.collect(Collectors.toList()), asList(entity0, entity1));
}
 
开发者ID:molgenis,项目名称:molgenis,代码行数:18,代码来源:OwnedEntityRepositoryDecoratorTest.java

示例10: findAllStreamExtendsOwnedBySomeoneElse

import org.springframework.security.authentication.TestingAuthenticationToken; //导入方法依赖的package包/类
@Test
public void findAllStreamExtendsOwnedBySomeoneElse()
{
	TestingAuthenticationToken authentication = new TestingAuthenticationToken("username", null);
	authentication.setAuthenticated(false);
	SecurityContextHolder.getContext().setAuthentication(authentication);
	when(entityType.getExtends()).thenReturn(new OwnedEntityType(mock(SecurityPackage.class)));

	Object id0 = "id0";
	Object id1 = "id1";
	Entity entity0 = when(mock(Entity.class).getString(OWNER_USERNAME)).thenReturn("notme").getMock();
	Entity entity1 = when(mock(Entity.class).getString(OWNER_USERNAME)).thenReturn("notme").getMock();
	Stream<Object> entityIds = Stream.of(id0, id1);
	when(delegateRepository.findAll(entityIds)).thenReturn(Stream.of(entity0, entity1));
	Stream<Entity> expectedEntities = ownedEntityRepositoryDecorator.findAll(entityIds);
	assertEquals(expectedEntities.collect(Collectors.toList()), emptyList());
}
 
开发者ID:molgenis,项目名称:molgenis,代码行数:18,代码来源:OwnedEntityRepositoryDecoratorTest.java

示例11: findAllStreamFetchExtendsOwnedBySomeoneElse

import org.springframework.security.authentication.TestingAuthenticationToken; //导入方法依赖的package包/类
@Test
public void findAllStreamFetchExtendsOwnedBySomeoneElse()
{
	TestingAuthenticationToken authentication = new TestingAuthenticationToken("username", null);
	authentication.setAuthenticated(false);
	SecurityContextHolder.getContext().setAuthentication(authentication);
	when(entityType.getExtends()).thenReturn(new OwnedEntityType(mock(SecurityPackage.class)));

	Fetch fetch = new Fetch();
	Object id0 = "id0";
	Object id1 = "id1";
	Entity entity0 = when(mock(Entity.class).getString(OWNER_USERNAME)).thenReturn("notme").getMock();
	Entity entity1 = when(mock(Entity.class).getString(OWNER_USERNAME)).thenReturn("notme").getMock();
	Stream<Object> entityIds = Stream.of(id0, id1);
	Fetch decoratedFetch = new Fetch().field(OWNER_USERNAME);
	when(delegateRepository.findAll(entityIds, decoratedFetch)).thenReturn(Stream.of(entity0, entity1));
	Stream<Entity> expectedEntities = ownedEntityRepositoryDecorator.findAll(entityIds, fetch);
	assertEquals(expectedEntities.collect(Collectors.toList()), emptyList());
}
 
开发者ID:molgenis,项目名称:molgenis,代码行数:20,代码来源:OwnedEntityRepositoryDecoratorTest.java

示例12: createAuthentication

import org.springframework.security.authentication.TestingAuthenticationToken; //导入方法依赖的package包/类
public static Authentication createAuthentication(final String username,
                                                  final String plaintextPassword,
                                                  final Long userId,
                                                  final SystemUser.Role role,
                                                  final boolean authenticated) {
    final SystemUser user = new SystemUser();
    user.setUsername(username);
    user.setId(userId);
    user.setRole(role);
    user.setPasswordAsPlaintext(plaintextPassword, NoOpPasswordEncoder.getInstance());

    final List<GrantedAuthority> grantedAuthorities = (role != null)
            ? AuthorityUtils.createAuthorityList(role.name())
            : new LinkedList<>();

    final UserInfo.UserInfoBuilder builder =
            new UserInfo.UserInfoBuilder(user);

    final UserInfo principal = builder.createUserInfo();

    final TestingAuthenticationToken authenticationToken =
            new TestingAuthenticationToken(principal, plaintextPassword, grantedAuthorities);

    authenticationToken.setAuthenticated(authenticated);

    return authenticationToken;
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:28,代码来源:TestAuthenticationTokenUtil.java

示例13: shouldGetIfCurrentUserIsLoggedIn

import org.springframework.security.authentication.TestingAuthenticationToken; //导入方法依赖的package包/类
@Test
public void shouldGetIfCurrentUserIsLoggedIn() {
    //given
    TestingAuthenticationToken token = new TestingAuthenticationToken("1", "2");
    token.setAuthenticated(true);
    SecurityContextHolder.getContext().setAuthentication(token);

    //when
    boolean loggedIn = new CurrentUserWidget().isLoggedIn();

    //then
    assertTrue(loggedIn);
}
 
开发者ID:sdl,项目名称:dxa-modules,代码行数:14,代码来源:CurrentUserWidgetTest.java

示例14: shouldReturnCurrentUserName

import org.springframework.security.authentication.TestingAuthenticationToken; //导入方法依赖的package包/类
@Test
public void shouldReturnCurrentUserName() {
    //given
    TestingAuthenticationToken token = new TestingAuthenticationToken("test", "2");
    token.setAuthenticated(true);
    SecurityContextHolder.getContext().setAuthentication(token);

    //when
    String name = new CurrentUserWidget().getUserName();

    //then
    assertEquals("test", name);
}
 
开发者ID:sdl,项目名称:dxa-modules,代码行数:14,代码来源:CurrentUserWidgetTest.java

示例15: shouldReturnCurrentUserNameIfUserProfilePrincipalIsSet

import org.springframework.security.authentication.TestingAuthenticationToken; //导入方法依赖的package包/类
@Test
public void shouldReturnCurrentUserNameIfUserProfilePrincipalIsSet() {
    //given
    UserProfile userProfile = mock(UserProfile.class);
    when(userProfile.getDisplayUsername()).thenReturn("test_simple");
    TestingAuthenticationToken token = new TestingAuthenticationToken(userProfile, "2");
    token.setAuthenticated(true);
    SecurityContextHolder.getContext().setAuthentication(token);

    //when
    String name = new CurrentUserWidget().getUserName();

    //then
    assertEquals("test_simple", name);
}
 
开发者ID:sdl,项目名称:dxa-modules,代码行数:16,代码来源:CurrentUserWidgetTest.java


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