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