當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。