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


Java Authentication.getPrincipal方法代码示例

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


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

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

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

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

示例4: getUsername

import org.springframework.security.Authentication; //导入方法依赖的package包/类
/**
 * <p>getUsername</p>
 *
 * @return a {@link java.lang.String} object.
 */
protected String getUsername() {
    /*
     * This should never be null, as the strategy should create a
     * SecurityContext if one doesn't exist, but let's check anyway.
     */
    SecurityContext context = SecurityContextHolder.getContext();
    Assert.state(context != null, "No security context found when calling SecurityContextHolder.getContext()");
    
    Authentication auth = context.getAuthentication();
    Assert.state(auth != null, "No Authentication object found when calling getAuthentication on our SecurityContext object");
    
    Object obj = auth.getPrincipal();
    Assert.state(obj != null, "No principal object found when calling getPrinticpal on our Authentication object");
    
    
    if (obj instanceof UserDetails) { 
        return ((UserDetails)obj).getUsername(); 
    } else { 
        return obj.toString(); 
    }
}
 
开发者ID:vishwaabhinav,项目名称:OpenNMS,代码行数:27,代码来源:DefaultSurveillanceService.java

示例5: getLoginAdmin

import org.springframework.security.Authentication; //导入方法依赖的package包/类
public Admin getLoginAdmin() {
	Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
	if (authentication == null) {
		return null;
	}
	Object principal = authentication.getPrincipal();
	if (principal == null || !(principal instanceof Admin)) {
		return null;
	} else {
		return (Admin) principal;
	}
}
 
开发者ID:wangko27,项目名称:SelfSoftShop,代码行数:13,代码来源:AdminServiceImpl.java

示例6: getUserName

import org.springframework.security.Authentication; //导入方法依赖的package包/类
public static Username getUserName(Authentication authentication) {
    Object principal = authentication.getPrincipal();
    if (principal instanceof GoUserPrinciple) {
        GoUserPrinciple userPrincipleDetails = (GoUserPrinciple) principal;
        return new Username(new CaseInsensitiveString(userPrincipleDetails.getUsername()), userPrincipleDetails.getDisplayName());
    }
    if (principal instanceof UserDetails) {
        UserDetails userDetails = (UserDetails) principal;
        return new Username(new CaseInsensitiveString(userDetails.getUsername()));
    }
    return ANONYMOUS;
}
 
开发者ID:gocd,项目名称:gocd,代码行数:13,代码来源:UserHelper.java


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