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


Java UserDetails.getUsername方法代码示例

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


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

示例1: targetUrl

import org.springframework.security.core.userdetails.UserDetails; //导入方法依赖的package包/类
protected String targetUrl(Authentication authentication) {
UserDetails p = (UserDetails )authentication.getPrincipal();
String username = p.getUsername();
      String password = p.getPassword();
  
      String url = "";
      Collection<? extends GrantedAuthority> authorities = p.getAuthorities();
      List<String> roles = new ArrayList<String>();
      for (GrantedAuthority a : authorities) {
          roles.add(a.getAuthority());
      }
      System.out.println("logout handler" + roles);
             
      if (isUser(roles)) {
          url = "/after_logout.html?message="+"Thank your, "+ username +" with password " + password +" and role(s): " + roles;
      } else if (isAdmin(roles)){
      	 url = "/after_logout.html?message="+"Thank your, "+ username +" with password " + password +" and role(s): " + roles;
      } else if (isHrAdmin(roles)){
      	 url = "/after_logout.html?message="+"Thank your, "+ username +" with password " + password +" and role(s): " + roles;
      } else{   	
    url = "/after_logout.html?message="+"Thank you, friend!";
      }
      return url;
  }
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:25,代码来源:CustomLogoutHandler.java

示例2: handleMessage

import org.springframework.security.core.userdetails.UserDetails; //导入方法依赖的package包/类
/**
 * 消息处理,js客户端send()的消息会到这里
 * 不用
 */
public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {
    if(message.getPayloadLength()==0)return;

    UserDetails userDetails = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    String username = userDetails.getUsername();
    UserInfo userInfo = userInfoDao.getUserInfoByUsername(username);
    int userId = userInfo.getUserId();

    Message msg=new Gson().fromJson(message.getPayload().toString(),Message.class);
    msg.setFrom(userId);
    msg.setFromName(username);
    msg.setDate(new Date());

    sendMessageToGroup(userId, msg.getNotebookId(), new TextMessage(new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create().toJson(msg)));
}
 
开发者ID:qinjr,项目名称:TeamNote,代码行数:20,代码来源:WebsocketHandler.java

示例3: getGroupChat

import org.springframework.security.core.userdetails.UserDetails; //导入方法依赖的package包/类
@RequestMapping("/getGroupChat")
@ResponseBody
public String getGroupChat(@RequestParam("notebookId") int notebookId, @RequestParam("lastChat") int lastChat) {
    UserDetails userDetails = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    String username = userDetails.getUsername();
    UserInfo userInfo = userBasicService.getUserInfoByUsername(username);
    int userId = userInfo.getUserId();

    int length = cooperateService.getGroupChat(notebookId).size();
    if(lastChat == -1) lastChat = length - 1;
    String resultList = cooperateService.getGroupChatChunk(notebookId, lastChat);
    lastChat = lastChat >= 10 ? lastChat - 10 : -2;
    JsonObject json = new JsonObject();
    json.addProperty("result", resultList);
    json.addProperty("currentUser", userId);
    json.addProperty("lastChat", lastChat);
    return json.toString();
}
 
开发者ID:qinjr,项目名称:TeamNote,代码行数:19,代码来源:CooperateController.java

示例4: getCurrentUserLogin

import org.springframework.security.core.userdetails.UserDetails; //导入方法依赖的package包/类
/**
 * Get the login of the current user.
 *
 * @return the login of the current user
 */
public static String getCurrentUserLogin() {
    SecurityContext securityContext = SecurityContextHolder.getContext();
    Authentication authentication = securityContext.getAuthentication();
    String userName = null;
    if (authentication != null) {
        if (authentication.getPrincipal() instanceof UserDetails) {
            UserDetails springSecurityUser = (UserDetails) authentication.getPrincipal();
            userName = springSecurityUser.getUsername();
        } else if (authentication.getPrincipal() instanceof String) {
            userName = (String) authentication.getPrincipal();
        }
    }
    return userName;
}
 
开发者ID:xm-online,项目名称:xm-uaa,代码行数:20,代码来源:SecurityUtils.java

示例5: beforeHandshake

import org.springframework.security.core.userdetails.UserDetails; //导入方法依赖的package包/类
@Override
public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String, Object> attributes) throws Exception {
    System.out.println("Before Handshake");
    //get userId
    UserDetails userDetails = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    String username = userDetails.getUsername();
    UserInfo userInfo = userInfoDao.getUserInfoByUsername(username);
    int userId = userInfo.getUserId();
    //put into websocketSession
    attributes.put("userId", userId);
    return true;
}
 
开发者ID:qinjr,项目名称:TeamNote,代码行数:13,代码来源:WebsocketInterceptorImpl.java

示例6: getCurrentUserLogin

import org.springframework.security.core.userdetails.UserDetails; //导入方法依赖的package包/类
/**
 * Get the login of the current user.
 */
public static String getCurrentUserLogin() {
    SecurityContext securityContext = SecurityContextHolder.getContext();
    Authentication authentication = securityContext.getAuthentication();
    String userName = null;
    if (authentication != null) {
        if (authentication.getPrincipal() instanceof UserDetails) {
            UserDetails springSecurityUser = (UserDetails) authentication.getPrincipal();
            userName = springSecurityUser.getUsername();
        } else if (authentication.getPrincipal() instanceof String) {
            userName = (String) authentication.getPrincipal();
        }
    }
    return userName;
}
 
开发者ID:GastonMauroDiaz,项目名称:buenojo,代码行数:18,代码来源:SecurityUtils.java

示例7: sendMsg

import org.springframework.security.core.userdetails.UserDetails; //导入方法依赖的package包/类
@RequestMapping("/sendMsg")
@ResponseBody
public String sendMsg(@RequestParam("notebookId") int notebookId, @RequestParam("text") String text) {
    UserDetails userDetails = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    String username = userDetails.getUsername();
    UserInfo userInfo = userBasicService.getUserInfoByUsername(username);
    int userId = userInfo.getUserId();

    cooperateService.sendGroupChat(userId, notebookId, new Date(), text);

    JsonObject json = new JsonObject();
    json.addProperty("result", "success");
    json.addProperty("sender", username);
    return json.toString();
}
 
开发者ID:qinjr,项目名称:TeamNote,代码行数:16,代码来源:CooperateController.java

示例8: User

import org.springframework.security.core.userdetails.UserDetails; //导入方法依赖的package包/类
public User(UserDetails userDetails){
    this(userDetails.getUsername(),userDetails.getPassword());
}
 
开发者ID:damingerdai,项目名称:web-qq,代码行数:4,代码来源:User.java

示例9: getUserId

import org.springframework.security.core.userdetails.UserDetails; //导入方法依赖的package包/类
private int getUserId() {
    UserDetails userDetails = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    String username = userDetails.getUsername();
    UserInfo userInfo = userBasicService.getUserInfoByUsername(username);
    return userInfo.getUserId();
}
 
开发者ID:qinjr,项目名称:TeamNote,代码行数:7,代码来源:NoteController.java


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