本文整理汇总了Java中org.springframework.security.Authentication.setAuthenticated方法的典型用法代码示例。如果您正苦于以下问题:Java Authentication.setAuthenticated方法的具体用法?Java Authentication.setAuthenticated怎么用?Java Authentication.setAuthenticated使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.security.Authentication
的用法示例。
在下文中一共展示了Authentication.setAuthenticated方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doFilterHttp
import org.springframework.security.Authentication; //导入方法依赖的package包/类
@Override
protected void doFilterHttp(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (!systemEnvironment.isReAuthenticationEnabled() || authentication == null) {
chain.doFilter(request, response);
return;
}
synchronized (request.getSession().getId().intern()) {
Long lastAuthenticationTime = (Long) request.getSession().getAttribute(LAST_REAUTHENICATION_CHECK_TIME);
if (lastAuthenticationTime == null) {
request.getSession().setAttribute(LAST_REAUTHENICATION_CHECK_TIME, timeProvider.currentTimeMillis());
} else if (forceReAuthentication(lastAuthenticationTime)) {
request.getSession().setAttribute(LAST_REAUTHENICATION_CHECK_TIME, timeProvider.currentTimeMillis());
authentication.setAuthenticated(false);
}
}
chain.doFilter(request, response);
}
示例2: doFilterHttp
import org.springframework.security.Authentication; //导入方法依赖的package包/类
public void doFilterHttp(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication == null) {
chain.doFilter(request, response);
return;
}
synchronized (request.getRequestedSessionId().intern()) {
long localCopyOfLastChangedTime = lastChangedTime;//This is so that the volatile variable is accessed only once.
Long previousLastChangedTime = (Long) request.getSession().getAttribute(SECURITY_CONFIG_LAST_CHANGE);
if (previousLastChangedTime == null) {
request.getSession().setAttribute(SECURITY_CONFIG_LAST_CHANGE, localCopyOfLastChangedTime);
} else if (previousLastChangedTime < localCopyOfLastChangedTime) {
request.getSession().setAttribute(SECURITY_CONFIG_LAST_CHANGE, localCopyOfLastChangedTime);
authentication.setAuthenticated(false);
}
}
chain.doFilter(request, response);
}
示例3: setupAuthentication
import org.springframework.security.Authentication; //导入方法依赖的package包/类
private Authentication setupAuthentication() {
GrantedAuthority[] authorities = {};
Authentication authentication = new TestingAuthenticationToken(new User("loser", "secret", true, true, true, true, authorities), null, authorities);
SecurityContextHolder.getContext().setAuthentication(authentication);
authentication.setAuthenticated(true);
return authentication;
}
示例4: shouldContinueWithChainAndReturnIfAuthenticationDoesNotHavePrincipalDefined
import org.springframework.security.Authentication; //导入方法依赖的package包/类
@Test
public void shouldContinueWithChainAndReturnIfAuthenticationDoesNotHavePrincipalDefined() throws IOException, ServletException {
Authentication authentication = new TestingAuthenticationToken(null, null, new GrantedAuthority[]{});
SecurityContextHolder.getContext().setAuthentication(authentication);
authentication.setAuthenticated(true);
when(systemEnvironment.isReAuthenticationEnabled()).thenReturn(true);
when(systemEnvironment.isReAuthenticationEnabled()).thenReturn(true);
filter.doFilterHttp(request, response, filterChain);
verify(filterChain).doFilter(request, response);
verifyNoMoreInteractions(filterChain);
}
示例5: setupAuthentication
import org.springframework.security.Authentication; //导入方法依赖的package包/类
private Authentication setupAuthentication(boolean authenticatedUsingAuthorizationPlugin) {
GrantedAuthority[] authorities = {};
Authentication authentication = new TestingAuthenticationToken(new GoUserPrinciple("user", "displayName", "password",
true, true, true, true, authorities, "loginName"), null, authorities);
SecurityContextHolder.getContext().setAuthentication(authentication);
authentication.setAuthenticated(true);
return authentication;
}
示例6: testShouldReAuthenticateIffSecurityConfigChange
import org.springframework.security.Authentication; //导入方法依赖的package包/类
@Test
public void testShouldReAuthenticateIffSecurityConfigChange() throws IOException, ServletException {
Authentication authentication = setupAuthentication();
when(session.getAttribute(RemoveAdminPermissionFilter.SECURITY_CONFIG_LAST_CHANGE)).thenReturn(0L).thenReturn(0L).thenReturn(100L);
RemoveAdminPermissionFilter filter = new RemoveAdminPermissionFilter(goConfigService, timeProvider, pluginRoleService);
filter.initialize();
filter.doFilterHttp(request, response, chain);
assertThat(authentication.isAuthenticated(), is(true));
turnOnSecurity("pavan");//This changes the security config
filter.doFilterHttp(request, response, chain);
assertThat(authentication.isAuthenticated(), is(false));
authentication.setAuthenticated(true);
modifyArtifactRoot();//This changes something else
filter.doFilterHttp(request, response, chain);
assertThat(authentication.isAuthenticated(), is(true));
}
示例7: testShouldReAuthenticateOnlyOnceAfterConfigChange
import org.springframework.security.Authentication; //导入方法依赖的package包/类
@Test
public void testShouldReAuthenticateOnlyOnceAfterConfigChange() throws IOException, ServletException {
goConfigService.security().securityAuthConfigs().add(new SecurityAuthConfig("github", "cd.go.authorization.github"));
goConfigService.security().addRole(new PluginRoleConfig("spacetiger", "github"));
Authentication authentication = setupAuthentication();
when(session.getAttribute(SECURITY_CONFIG_LAST_CHANGE)).thenReturn(0L).thenReturn(0L).thenReturn(100L);
RemoveAdminPermissionFilter filter = new RemoveAdminPermissionFilter(goConfigService, timeProvider, pluginRoleService);
filter.initialize();
assertThat(authentication.isAuthenticated(), is(true));//good initial state
filter.doFilterHttp(request, response, chain);
pluginRoleService.invalidateRolesFor("cd.go.authorization.github");
assertThat(authentication.isAuthenticated(), is(true));
filter.doFilterHttp(request, response, chain);
assertThat(authentication.isAuthenticated(), is(false));
authentication.setAuthenticated(true);
filter.doFilterHttp(request, response, chain);
assertThat(authentication.isAuthenticated(), is(true));
}
示例8: testShouldReAuthenticateOnlyOnceAfterAuthorizationPluginUnloaded
import org.springframework.security.Authentication; //导入方法依赖的package包/类
@Test
public void testShouldReAuthenticateOnlyOnceAfterAuthorizationPluginUnloaded() throws IOException, ServletException {
Authentication authentication = setupAuthentication();
when(session.getAttribute(SECURITY_CONFIG_LAST_CHANGE)).thenReturn(0L).thenReturn(0L).thenReturn(100L);
RemoveAdminPermissionFilter filter = new RemoveAdminPermissionFilter(goConfigService, timeProvider, pluginRoleService);
filter.initialize();
assertThat(authentication.isAuthenticated(), is(true));//good initial state
filter.doFilterHttp(request, response, chain);
turnOnSecurity("pavan");
assertThat(authentication.isAuthenticated(), is(true));
filter.doFilterHttp(request, response, chain);
assertThat(authentication.isAuthenticated(), is(false));
authentication.setAuthenticated(true);
filter.doFilterHttp(request, response, chain);
assertThat(authentication.isAuthenticated(), is(true));
}