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


Java Authentication类代码示例

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


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

示例1: mustIgnore

import org.springframework.security.Authentication; //导入依赖的package包/类
private boolean mustIgnore(HttpServletRequest request)
{
	Authentication currentAuthentication = SecurityContextHolder.getContext().getAuthentication();
	if (currentAuthentication != null && currentAuthentication.isAuthenticated())
	{
		return true;
	}

	String autologinParam = request.getParameter(AUTOLOGIN_PARAM_NAME);
	if (!"true".equals(autologinParam))
	{
		return true;
	}

	// TODO: implement other conditions if appropriate.
	return false;
}
 
开发者ID:Rospaccio,项目名称:pentaho-transparent-authentication,代码行数:18,代码来源:AuthenticationExtensionFilter.java

示例2: authenticate

import org.springframework.security.Authentication; //导入依赖的package包/类
@Override
public Authentication authenticate(Authentication authenticationRequest)
		throws AuthenticationException {
	GrantedAuthority[] authorities = new GrantedAuthorityImpl[authenticationRequest.getAuthorities().length + 1];
	authorities[0] = new GrantedAuthorityImpl(AUTHENTICATED_AUTHORITY_NAME);
	int i = 1;
	for(GrantedAuthority originalAuth : authenticationRequest.getAuthorities()){
		authorities[i] = new GrantedAuthorityImpl(originalAuth.getAuthority());
		i += 1;
	}
	
	UsernamePasswordAuthenticationToken authenticationOutcome = new UsernamePasswordAuthenticationToken(authenticationRequest.getPrincipal(), 
			authenticationRequest.getCredentials(), authorities);
	authenticationOutcome.setDetails(authenticationRequest.getDetails());
	return authenticationOutcome;
}
 
开发者ID:Rospaccio,项目名称:pentaho-authentication-ext,代码行数:17,代码来源:ExtensionAuthenticationProvider.java

示例3: testDoFilter

import org.springframework.security.Authentication; //导入依赖的package包/类
@Test
public void testDoFilter() throws IOException, ServletException, ExternalAppNotMappedException
{
	assertNotNull(loginTicketManager);
	
	//makes the ticket manager issue a ticket
	LoginTicket ticket = loginTicketManager.generateNewTicket("test", "externalTestUser");
	String ticketId = ticket.getIdAsString();
	
	MockHttpServletRequest request = new MockHttpServletRequest();
	MockHttpServletResponse response = new MockHttpServletResponse();
	MockFilterChain chain = new MockFilterChain();
	
	request.addParameter(AuthenticationExtensionFilter.AUTOLOGIN_PARAM_NAME, "true");
	request.addParameter(AuthenticationExtensionFilter.TICKET_PARAM_NAME, ticketId);
	
	authFilter.doFilter(request, response, chain);
	String content = response.getContentAsString();
	assertNotNull(content);
	
	Authentication auth = SecurityContextHolder.getContext().getAuthentication();
	assertNotNull(auth);
}
 
开发者ID:Rospaccio,项目名称:pentaho-authentication-ext,代码行数:24,代码来源:AuthenticationExtensionFilterTest.java

示例4: shouldAuthorize

import org.springframework.security.Authentication; //导入依赖的package包/类
/**
 * Determine if our controlled objects should be authorized based on the provided
 * authentication token.
 * @param authentication token
 * @return true if should authorize
 */
protected boolean shouldAuthorize(Authentication authentication) {
    Assert.state( getAccessDecisionManager() != null, "The AccessDecisionManager can not be null!" );
    boolean authorize = false;
    try {
        if( authentication != null ) {
            Object securedObject = getSecuredObject();
            ConfigAttributeDefinition cad = getConfigAttributeDefinition( securedObject );
            getAccessDecisionManager().decide( authentication, getSecuredObject(), cad );
            authorize = true;
        }
    } catch( AccessDeniedException e ) {
        // This means the secured objects should not be authorized
    }
    return authorize;
}
 
开发者ID:shevek,项目名称:spring-rich-client,代码行数:22,代码来源:AbstractSecurityController.java

示例5: isUserInRole

import org.springframework.security.Authentication; //导入依赖的package包/类
/**
 * Determine if the currently authenticated user has the role provided. Note that role
 * comparisons are case sensitive.
 * 
 * @param role to check
 * @return true if the user has the role requested
 */
public boolean isUserInRole(String role) {
    boolean inRole = false;

    Authentication authentication = getAuthentication();
    if( authentication != null ) {
        GrantedAuthority[] authorities = authentication.getAuthorities();
        for( int i = 0; i < authorities.length; i++ ) {
            if( role.equals( authorities[i].getAuthority() ) ) {
                inRole = true;
                break;
            }
        }
    }
    return inRole;
}
 
开发者ID:shevek,项目名称:spring-rich-client,代码行数:23,代码来源:DefaultApplicationSecurityManager.java

示例6: handleLoginEvent

import org.springframework.security.Authentication; //导入依赖的package包/类
/**
 * When a correct login occurs, read all relevant userinformation into
 * session.
 *
 * @param event
 *            the loginEvent that triggered this handler.
 */
protected void handleLoginEvent(LoginEvent event)
{
    ApplicationSessionInitializer asi = getApplicationSessionInitializer();
    if (asi != null)
    {
        asi.initializeUser();
        Map<String, Object> userAttributes = asi.getUserAttributes();
        if (userAttributes != null)
        {
            setUserAttributes(userAttributes);
        }
    }
    Authentication auth = (Authentication) event.getSource();
    propertyChangeSupport.firePropertyChange(USER, null, auth);
}
 
开发者ID:shevek,项目名称:spring-rich-client,代码行数:23,代码来源:ApplicationSession.java

示例7: isAuthenticated

import org.springframework.security.Authentication; //导入依赖的package包/类
/**
 * 인증된 사용자 여부를 체크한다.
 * @return 인증된 사용자 여부(TRUE / FALSE)
 */
public static Boolean isAuthenticated() {
    SecurityContext context = SecurityContextHolder.getContext();
    Authentication authentication = context.getAuthentication();

    if (EgovObjectUtil.isNull(authentication)) {
        log.debug("## authentication object is null!!");
        return Boolean.FALSE;
    }

    String username = authentication.getName();
    if (username.equals("roleAnonymous")) {
        log.debug("## username is " + username);
        return Boolean.FALSE;
    }

    Object principal = authentication.getPrincipal();

    return (Boolean.valueOf(!EgovObjectUtil.isNull(principal)));
}
 
开发者ID:eGovFrame,项目名称:egovframework.rte.root,代码行数:24,代码来源:EgovUserDetailsHelper.java

示例8: getAuthenticatedUser

import org.springframework.security.Authentication; //导入依赖的package包/类
/**
 * 인증된 사용자객체를 VO형식으로 가져온다.
 * @return 사용자 ValueObject
 */
public static Object getAuthenticatedUser() {
    SecurityContext context = SecurityContextHolder.getContext();
    Authentication authentication = context.getAuthentication();

    if (EgovObjectUtil.isNull(authentication)) {
        log.debug("## authentication object is null!!");
        return null;
    }

    EgovUserDetails details =
        (EgovUserDetails) authentication.getPrincipal();

    log
        .debug("## EgovUserDetailsHelper.getAuthenticatedUser : AuthenticatedUser is "
            + details.getUsername());
    return details.getEgovUserVO();
}
 
开发者ID:eGovFrame,项目名称:egovframework.rte.root,代码行数:22,代码来源:EgovUserDetailsHelper.java

示例9: shouldConvey_itsBasicProcessingFilter

import org.springframework.security.Authentication; //导入依赖的package包/类
@Test
public void shouldConvey_itsBasicProcessingFilter() throws IOException, ServletException {
    BasicAuthenticationFilter filter = new BasicAuthenticationFilter(localizer);
    final Boolean[] hadBasicMarkOnInsideAuthenticationManager = new Boolean[]{false};

    filter.setAuthenticationManager(new AuthenticationManager() {
        public Authentication authenticate(Authentication authentication) throws AuthenticationException {
            hadBasicMarkOnInsideAuthenticationManager[0] = BasicAuthenticationFilter.isProcessingBasicAuth();
            return new UsernamePasswordAuthenticationToken("school-principal", "u can be principal if you know this!");
        }
    });
    assertThat(BasicAuthenticationFilter.isProcessingBasicAuth(), is(false));
    MockHttpServletRequest httpRequest = new MockHttpServletRequest();
    httpRequest.addHeader("Authorization", "Basic " + Base64.getEncoder().encodeToString("loser:boozer".getBytes()));
    filter.doFilterHttp(httpRequest, new MockHttpServletResponse(), new FilterChain() {
        public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse) throws IOException, ServletException {

        }
    });
    assertThat(BasicAuthenticationFilter.isProcessingBasicAuth(), is(false));

    assertThat(hadBasicMarkOnInsideAuthenticationManager[0], is(true));
}
 
开发者ID:gocd,项目名称:gocd,代码行数:24,代码来源:BasicAuthenticationFilterTest.java

示例10: testGetUsernameNoPrincipalObject

import org.springframework.security.Authentication; //导入依赖的package包/类
@Test
public void testGetUsernameNoPrincipalObject() {
    Authentication auth = new UsernamePasswordAuthenticationToken(null, null, new GrantedAuthority[0]);
    SecurityContextHolder.getContext().setAuthentication(auth);
    
    ThrowableAnticipator ta = new ThrowableAnticipator();
    ta.anticipate(new IllegalStateException("No principal object found when calling getPrinticpal on our Authentication object"));
    
    try {
        m_service.getUsername();
    } catch (Throwable t) {
        ta.throwableReceived(t);
    }
    
    ta.verifyAnticipated();
}
 
开发者ID:vishwaabhinav,项目名称:OpenNMS,代码行数:17,代码来源:DefaultSurveillanceServiceTest.java

示例11: shouldAuthenticateUsersWithCredentials

import org.springframework.security.Authentication; //导入依赖的package包/类
@Test
public void shouldAuthenticateUsersWithCredentials() throws IOException, ServletException {
    PreAuthenticatedAuthenticationToken token = mock(PreAuthenticatedAuthenticationToken.class);
    HashMap<String, String[]> params = new HashMap<>();
    params.put("code", new String[]{"some_auth_code"});
    SecurityAuthConfig githubAuthConfig = new SecurityAuthConfig("github", "github.oauth");
    securityConfig.securityAuthConfigs().add(githubAuthConfig);

    when(request.getRequestURI()).thenReturn("/go/plugin/github.oauth/authenticate");
    when(request.getHeaderNames()).thenReturn(Collections.enumeration(Arrays.asList("Authorization")));
    when(request.getHeader("Authorization")).thenReturn("qwe123");
    when(request.getParameterMap()).thenReturn(params);
    when(authorizationExtension.fetchAccessToken("github.oauth", Collections.singletonMap("Authorization", "qwe123"),
            Collections.singletonMap("code", "some_auth_code"), Collections.singletonList(githubAuthConfig))).
            thenReturn(Collections.singletonMap("access_token", "token"));
    when(authenticationManager.authenticate(any(PreAuthenticatedAuthenticationToken.class))).thenReturn(token);
    filter.setDefaultTargetUrl("/");

    filter.doFilter(request, response, filterChain);

    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    assertThat(authentication, is(token));
}
 
开发者ID:gocd,项目名称:gocd,代码行数:24,代码来源:PreAuthenticatedRequestsProcessingFilterTest.java

示例12: 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

示例13: 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

示例14: doFilterHttp

import org.springframework.security.Authentication; //导入依赖的package包/类
protected void doFilterHttp(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
    String header = request.getHeader(AUTHORIZATION);//Token token="ACCESS_TOKEN"

    if (header != null) {
        logger.debug("Oauth authorization header: " + header);
        Matcher matcher = OAUTH_TOKEN_PATTERN.matcher(header);
        if (matcher.matches()) {
            String token = matcher.group(1);
            OauthAuthenticationToken authenticationToken = new OauthAuthenticationToken(token);
            try {
                Authentication authResult = authenticationManager.authenticate(authenticationToken);
                SecurityContextHolder.getContext().setAuthentication(authResult);
            } catch (AuthenticationException e) {
                logger.debug("Oauth authentication request for token: " + token, e);
                SecurityContextHolder.getContext().setAuthentication(null);
            }
        }
    }
    chain.doFilter(request, response);
}
 
开发者ID:gocd,项目名称:gocd,代码行数:21,代码来源:OauthAuthenticationFilter.java

示例15: getAuthorities

import org.springframework.security.Authentication; //导入依赖的package包/类
/**
 * 인증된 사용자의 권한 정보를 가져온다. 예) [ROLE_ADMIN, ROLE_USER,
 * ROLE_A, ROLE_B, ROLE_RESTRICTED,
 * IS_AUTHENTICATED_FULLY,
 * IS_AUTHENTICATED_REMEMBERED,
 * IS_AUTHENTICATED_ANONYMOUSLY]
 * @return 사용자 권한정보 목록
 */
public static List<String> getAuthorities() {
    List<String> listAuth = new ArrayList<String>();

    SecurityContext context = SecurityContextHolder.getContext();
    Authentication authentication = context.getAuthentication();

    if (EgovObjectUtil.isNull(authentication)) {
        log.debug("## authentication object is null!!");
        return null;
    }

    GrantedAuthority[] authorities = authentication.getAuthorities();

    for (int i = 0; i < authorities.length; i++) {
        listAuth.add(authorities[i].getAuthority());

        log.debug("## EgovUserDetailsHelper.getAuthorities : Authority is "
            + authorities[i].getAuthority());
    }

    return listAuth;
}
 
开发者ID:eGovFrame,项目名称:egovframework.rte.root,代码行数:31,代码来源:EgovUserDetailsHelper.java


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