本文整理汇总了Java中org.springframework.security.core.userdetails.User.getUsername方法的典型用法代码示例。如果您正苦于以下问题:Java User.getUsername方法的具体用法?Java User.getUsername怎么用?Java User.getUsername使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.security.core.userdetails.User
的用法示例。
在下文中一共展示了User.getUsername方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCurrentUser
import org.springframework.security.core.userdetails.User; //导入方法依赖的package包/类
/**
* Get the {@link CalendarUser} by obtaining the currently logged in Spring Security user's
* {@link Authentication#getName()} and using that to find the {@link CalendarUser} by email address (since for our
* application Spring Security usernames are email addresses).
*/
@Override
public CalendarUser getCurrentUser() {
SecurityContext context = SecurityContextHolder.getContext();
Authentication authentication = context.getAuthentication();
if (authentication == null) {
return null;
}
User user = (User)authentication.getPrincipal();
String email = user.getUsername();
// String email = user.getEmail();
if (email == null) {
return null;
}
CalendarUser result = calendarService.findUserByEmail(email);
if (result == null) {
throw new IllegalStateException(
"Spring Security is not in synch with CalendarUsers. Could not find user with email " + email);
}
return result;
}
开发者ID:PacktPublishing,项目名称:Spring-Security-Third-Edition,代码行数:27,代码来源:SpringSecurityUserContext.java
示例2: getCurrentUser
import org.springframework.security.core.userdetails.User; //导入方法依赖的package包/类
/**
* Get the {@link CalendarUser} by obtaining the currently logged in Spring Security user's
* {@link Authentication#getName()} and using that to find the {@link CalendarUser} by email address (since for our
* application Spring Security usernames are email addresses).
*/
@Override
public CalendarUser getCurrentUser() {
SecurityContext context = SecurityContextHolder.getContext();
Authentication authentication = context.getAuthentication();
if (authentication == null) {
return null;
}
User user = (User)authentication.getPrincipal();
String email = user.getUsername();
// String email = user.getEmail();
if (email == null) {
return null;
}
CalendarUser result = calendarService.findUserByEmail(email);
if (result == null) {
throw new IllegalStateException(
"Spring Security is not in synch with CalendarUsers. Could not find user with email " + email);
}
return result;
}
开发者ID:PacktPublishing,项目名称:Spring-Security-Third-Edition,代码行数:28,代码来源:SpringSecurityUserContext.java
示例3: getCurrentUser
import org.springframework.security.core.userdetails.User; //导入方法依赖的package包/类
/**
* Get the {@link CalendarUser} by obtaining the currently logged in Spring Security user's
* {@link Authentication#getName()} and using that to find the {@link CalendarUser} by email address (since for our
* application Spring Security usernames are email addresses).
*/
@Override
public CalendarUser getCurrentUser() {
SecurityContext context = SecurityContextHolder.getContext();
Authentication authentication = context.getAuthentication();
if (authentication == null) {
return null;
}
User user = (User)authentication.getPrincipal();
String email = user.getUsername();
if (email == null) {
return null;
}
CalendarUser result = calendarService.findUserByEmail(email);
if (result == null) {
throw new IllegalStateException(
"Spring Security is not in synch with CalendarUsers. Could not find user with email " + email);
}
return result;
}
开发者ID:PacktPublishing,项目名称:Spring-Security-Third-Edition,代码行数:30,代码来源:SpringSecurityUserContext.java
示例4: myProfile
import org.springframework.security.core.userdetails.User; //导入方法依赖的package包/类
@RequestMapping("/api/profile")
public ResponseEntity<UserProfile> myProfile() {
User user = (User) SecurityContextHolder.getContext()
.getAuthentication().getPrincipal();
String email = user.getUsername() + "@mailinator.com";
UserProfile profile = new UserProfile(user.getUsername(), email);
return ResponseEntity.ok(profile);
}
示例5: hello
import org.springframework.security.core.userdetails.User; //导入方法依赖的package包/类
@RequestMapping("/api/profile")
public ResponseEntity<UserProfile> hello() {
User user = (User) SecurityContextHolder.getContext()
.getAuthentication().getPrincipal();
String email = user.getUsername() + "@mailinator.com";
UserProfile profile = new UserProfile();
profile.setName(user.getUsername());
profile.setEmail(email);
return ResponseEntity.ok(profile);
}
示例6: hello
import org.springframework.security.core.userdetails.User; //导入方法依赖的package包/类
@CrossOrigin
@RequestMapping("/api/profile")
public ResponseEntity<UserProfile> hello() {
User user = (User) SecurityContextHolder.getContext()
.getAuthentication().getPrincipal();
String email = user.getUsername() + "@mailinator.com";
UserProfile profile = new UserProfile();
profile.setName(user.getUsername());
profile.setEmail(email);
return ResponseEntity.ok(profile);
}
示例7: getAccount
import org.springframework.security.core.userdetails.User; //导入方法依赖的package包/类
/**
* GET /account : get the current user.
*
* @return the ResponseEntity with status 200 (OK) and the current user in body, or status 500 (Internal Server
* Error) if the user couldn't be returned
*/
@GetMapping("/account")
@Timed
public ResponseEntity<UserDTO> getAccount() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
User user = (User) authentication.getPrincipal();
UserDTO userDTO = new UserDTO(user.getUsername(),
user.getAuthorities().stream()
.map(authority -> authority.getAuthority()).collect(Collectors.toSet()));
return new ResponseEntity<>(userDTO, HttpStatus.OK);
}