本文整理汇总了Java中org.springframework.security.core.context.SecurityContextImpl.setAuthentication方法的典型用法代码示例。如果您正苦于以下问题:Java SecurityContextImpl.setAuthentication方法的具体用法?Java SecurityContextImpl.setAuthentication怎么用?Java SecurityContextImpl.setAuthentication使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.security.core.context.SecurityContextImpl
的用法示例。
在下文中一共展示了SecurityContextImpl.setAuthentication方法的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);
}
示例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: setUpMockAuthenticationContext
import org.springframework.security.core.context.SecurityContextImpl; //导入方法依赖的package包/类
private void setUpMockAuthenticationContext(){
// initialise the context with the user identified by the email
// "[email protected]" seen as authenticated
Collection<GrantedAuthority> gac = new ArrayList<GrantedAuthority>();
TgolUserDetails tud = new TgolUserDetails("[email protected]", "", true, false, true, true, gac, mockUser);
mockAuthentication = createMock(Authentication.class);
SecurityContextImpl securityContextImpl = new SecurityContextImpl();
securityContextImpl.setAuthentication(mockAuthentication);
SecurityContextHolder.setContext(securityContextImpl);
expect(mockAuthentication.getName()).andReturn("[email protected]").anyTimes();
expect(mockAuthentication.getPrincipal()).andReturn(tud).anyTimes();
expect(mockAuthentication.getAuthorities()).andReturn(null).anyTimes();
replay(mockAuthentication);
mockAuthenticationDetails = createMock(AuthenticationDetails.class);
expect(mockAuthenticationDetails.getContext()).andReturn("[email protected]").anyTimes();
replay(mockAuthenticationDetails);
}
示例4: setUpMockAuthenticationContext
import org.springframework.security.core.context.SecurityContextImpl; //导入方法依赖的package包/类
private void setUpMockAuthenticationContext(){
// initialise the context with the user identified by the email
// "[email protected]" seen as authenticated
Collection<GrantedAuthority> gac = new ArrayList<GrantedAuthority>();
TgolUserDetails tud = new TgolUserDetails("[email protected]", "", true, false, true, true, gac, mockUser);
mockAuthentication = createMock(Authentication.class);
SecurityContextImpl securityContextImpl = new SecurityContextImpl();
securityContextImpl.setAuthentication(mockAuthentication);
SecurityContextHolder.setContext(securityContextImpl);
expect(mockAuthentication.getName()).andReturn("[email protected]").anyTimes();
expect(mockAuthentication.getPrincipal()).andReturn(tud).anyTimes();
expect(mockAuthentication.getAuthorities()).andReturn(null).anyTimes();
replay(mockAuthentication);
mockAuthenticationDetails = createMock(AuthenticationDetails.class);
expect(mockAuthenticationDetails.getContext()).andReturn("[email protected]").anyTimes();
replay(mockAuthenticationDetails);
}
示例5: setUpMockAuthenticationContext
import org.springframework.security.core.context.SecurityContextImpl; //导入方法依赖的package包/类
private void setUpMockAuthenticationContext(){
// initialise the context with the user identified by the email
// "[email protected]" seen as authenticated
Collection<GrantedAuthority> gac = new ArrayList();
TgolUserDetails tud = new TgolUserDetails("[email protected]", "", true, false, true, true, gac, mockUser);
mockAuthentication = createMock(Authentication.class);
SecurityContextImpl securityContextImpl = new SecurityContextImpl();
securityContextImpl.setAuthentication(mockAuthentication);
SecurityContextHolder.setContext(securityContextImpl);
expect(mockAuthentication.getName()).andReturn("[email protected]").anyTimes();
expect(mockAuthentication.getPrincipal()).andReturn(tud).anyTimes();
expect(mockAuthentication.getAuthorities()).andReturn(null).anyTimes();
replay(mockAuthentication);
mockAuthenticationDetails = createMock(AuthenticationDetails.class);
expect(mockAuthenticationDetails.getContext()).andReturn("[email protected]").anyTimes();
replay(mockAuthenticationDetails);
}
示例6: setUpMockAuthenticationContext
import org.springframework.security.core.context.SecurityContextImpl; //导入方法依赖的package包/类
private void setUpMockAuthenticationContext(){
// initialise the context with the user identified by the email
// "[email protected]" seen as authenticated
Collection<GrantedAuthority> gac = new ArrayList<GrantedAuthority>();
TgolUserDetails tud = new TgolUserDetails("[email protected]", "", true, false, true, true, gac, mockAdminUser);
mockAuthentication = createMock(Authentication.class);
SecurityContextImpl securityContextImpl = new SecurityContextImpl();
securityContextImpl.setAuthentication(mockAuthentication);
SecurityContextHolder.setContext(securityContextImpl);
expect(mockAuthentication.getName()).andReturn("[email protected]").anyTimes();
expect(mockAuthentication.getPrincipal()).andReturn(tud).anyTimes();
expect(mockAuthentication.getAuthorities()).andReturn(null).anyTimes();
replay(mockAuthentication);
}
示例7: setUpMockAuthenticationContext
import org.springframework.security.core.context.SecurityContextImpl; //导入方法依赖的package包/类
/**
*
*/
private void setUpMockAuthenticationContext(){
// initialise the context with the user identified by the email
// "[email protected]" seen as authenticated
Collection<GrantedAuthority> gac = new ArrayList();
TgolUserDetails tud = new TgolUserDetails("[email protected]", "", true, false, true, true, gac, mockUser);
mockAuthentication = createMock(Authentication.class);
SecurityContextImpl securityContextImpl = new SecurityContextImpl();
securityContextImpl.setAuthentication(mockAuthentication);
SecurityContextHolder.setContext(securityContextImpl);
expect(mockAuthentication.getName()).andReturn("[email protected]").anyTimes();
expect(mockAuthentication.getPrincipal()).andReturn(tud).anyTimes();
expect(mockAuthentication.getAuthorities()).andReturn(null).anyTimes();
replay(mockAuthentication);
mockAuthenticationDetails = createMock(AuthenticationDetails.class);
expect(mockAuthenticationDetails.getContext()).andReturn("[email protected]").anyTimes();
replay(mockAuthenticationDetails);
}
示例8: shouldExtractName
import org.springframework.security.core.context.SecurityContextImpl; //导入方法依赖的package包/类
@Test
public void shouldExtractName() {
// given
String principalName = "john_the_springer";
SecurityContextImpl context = new SecurityContextImpl();
context.setAuthentication(new UsernamePasswordAuthenticationToken(principalName, null));
// when
String extractedName = AuthenticationParser.extractName(context);
// then
assertThat(extractedName).isEqualTo(principalName);
}
示例9: replaceContext
import org.springframework.security.core.context.SecurityContextImpl; //导入方法依赖的package包/类
/**
* Put new information in SecurityContextHolder.
*
* @param context
* the security context to update.
* @param newPrincipal
* the new principal to place.
*/
private void replaceContext(final SecurityContext context, final UserDetails newPrincipal) {
final PreAuthenticatedAuthenticationToken authentication = new PreAuthenticatedAuthenticationToken(newPrincipal, null);
authentication.setDetails(newPrincipal);
context.setAuthentication(authentication);
final SecurityContextImpl securityContextImpl = new SecurityContextImpl();
securityContextImpl.setAuthentication(authentication);
// Replace the old context
SecurityContextHolder.setContext(securityContextImpl);
}
示例10: successfulAuthentication
import org.springframework.security.core.context.SecurityContextImpl; //导入方法依赖的package包/类
@Override
protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response, FilterChain chain, Authentication authResult)
throws IOException, ServletException {
System.err.println("successfulAuthentication");
final SecurityContextImpl sCtx = new SecurityContextImpl();
sCtx.setAuthentication(authResult);
// SecurityContextHolder.getContext().setAuthentication(authResult);
final String sessionToken = sessionToken();
hazelcastInstance.getMap("userTokenMap").put(sessionToken, sCtx);
try (PrintWriter out = response.getWriter()) {
final LoginResponse loginResponse = new LoginResponse();
loginResponse.setAccessToken(sessionToken);
if (authResult.getPrincipal() instanceof User) {
final User user = (User) authResult.getPrincipal();
loginResponse.setName(user.getUsername());
loginResponse.setName(user.getUsername());
}
out.write(jacksonObjectMapper.writeValueAsString(loginResponse));
}
System.err.println("############ SUCCESSS ################");
}
示例11: init
import org.springframework.security.core.context.SecurityContextImpl; //导入方法依赖的package包/类
@Before
public void init() {
context = new SecurityContextImpl();
User principal = new User("USER1", "USER1", Arrays.asList(new SimpleGrantedAuthority(ROLE_MAX_WORDS + 100)));
Authentication authentication = new TestingAuthenticationToken(principal , null,ROLE_MAX_WORDS + 100);
context.setAuthentication(authentication);
SecurityContextHolder.setContext(context);
}
示例12: testRangeNoInfo
import org.springframework.security.core.context.SecurityContextImpl; //导入方法依赖的package包/类
@Test
public void testRangeNoInfo() {
context = new SecurityContextImpl();
User principal = new User("USER1", "USER1", new ArrayList<GrantedAuthority>());
Authentication authentication = new TestingAuthenticationToken(principal , null);
context.setAuthentication(authentication);
SecurityContextHolder.setContext(context);
String queryString = "?from=101&to=150";
String result = enforcer.enrichQueryString(queryString);
assertThat(result).isEqualTo("?from=101&to=150");
}
示例13: createSession
import org.springframework.security.core.context.SecurityContextImpl; //导入方法依赖的package包/类
private Session createSession(String sessionId, String userName,
Instant lastAccessed) {
MapSession session = new MapSession(sessionId);
session.setLastAccessedTime(lastAccessed);
Authentication authentication = mock(Authentication.class);
when(authentication.getName()).thenReturn(userName);
SecurityContextImpl securityContext = new SecurityContextImpl();
securityContext.setAuthentication(authentication);
session.setAttribute("SPRING_SECURITY_CONTEXT", securityContext);
return session;
}
示例14: runAsAdmin
import org.springframework.security.core.context.SecurityContextImpl; //导入方法依赖的package包/类
@Override
public <T> Supplier<T> runAsAdmin(Supplier<T> supplier) {
// Gets the current account (if any)
Account account = getCurrentAccount();
// Creates a temporary admin context
SecurityContextImpl adminContext = new SecurityContextImpl();
adminContext.setAuthentication(new RunAsAdminAuthentication(account));
// Returns a callable that sets the context before running the target callable
return withSecurityContext(supplier, adminContext);
}
示例15: setUp
import org.springframework.security.core.context.SecurityContextImpl; //导入方法依赖的package包/类
@Before
public void setUp() {
m_databasePopulator.populateDatabase();
m_context = new SecurityContextImpl();
validAdmin = new User(USERNAME, PASS, true, true, true, true,
Arrays.asList(new GrantedAuthority[] { ROLE_ADMIN }));
/*
invalidAdmin = new User(USERNAME, PASS, true, true, true, true,
new GrantedAuthority[] { ROLE_ADMIN });
validProvision = new User(USERNAME, PASS, true, true, true, true,
new GrantedAuthority[] { ROLE_PROVISION });
invalidProvision = new User(USERNAME, PASS, true, true, true, true,
new GrantedAuthority[] { ROLE_PROVISION });
validUser = new User(USERNAME, PASS, true, true, true, true,
new GrantedAuthority[] { ROLE_USER });
invalidUser = new User(USERNAME, PASS, true, true, true, true,
new GrantedAuthority[] { ROLE_USER });
validPower = new User(USERNAME, PASS, true, true, true, true,
new GrantedAuthority[] { ROLE_ADMIN, ROLE_PROVISION });
invalidPower = new User(USERNAME, PASS, true, true, true, true,
new GrantedAuthority[] { ROLE_USER, ROLE_PROVISION });
*/
m_auth = new PreAuthenticatedAuthenticationToken(validAdmin, new Object());
m_context.setAuthentication(m_auth);
SecurityContextHolder.setContext(m_context);
// m_securityContextService = new SpringSecurityContextService();
}