本文整理汇总了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;
}
示例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();
}
示例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)));
}
示例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();
}
}
示例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;
}
}
示例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;
}