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


Java Authentication.setAuthenticated方法代码示例

本文整理汇总了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);
}
 
开发者ID:gocd,项目名称:gocd,代码行数:22,代码来源:ReAuthenticationFilter.java

示例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);
}
 
开发者ID:gocd,项目名称:gocd,代码行数:19,代码来源:RemoveAdminPermissionFilter.java

示例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;
}
 
开发者ID:gocd,项目名称:gocd,代码行数:8,代码来源:RemoveAdminPermissionFilterIntegrationTest.java

示例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);
}
 
开发者ID:gocd,项目名称:gocd,代码行数:14,代码来源:ReAuthenticationFilterTest.java

示例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;
}
 
开发者ID:gocd,项目名称:gocd,代码行数:10,代码来源:ReAuthenticationFilterTest.java

示例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));
}
 
开发者ID:gocd,项目名称:gocd,代码行数:27,代码来源:RemoveAdminPermissionFilterIntegrationTest.java

示例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));
}
 
开发者ID:gocd,项目名称:gocd,代码行数:30,代码来源:RemoveAdminPermissionFilterIntegrationTest.java

示例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));
}
 
开发者ID:gocd,项目名称:gocd,代码行数:28,代码来源:RemoveAdminPermissionFilterIntegrationTest.java


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