當前位置: 首頁>>代碼示例>>Java>>正文


Java NativeWebRequest.getUserPrincipal方法代碼示例

本文整理匯總了Java中org.springframework.web.context.request.NativeWebRequest.getUserPrincipal方法的典型用法代碼示例。如果您正苦於以下問題:Java NativeWebRequest.getUserPrincipal方法的具體用法?Java NativeWebRequest.getUserPrincipal怎麽用?Java NativeWebRequest.getUserPrincipal使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.web.context.request.NativeWebRequest的用法示例。


在下文中一共展示了NativeWebRequest.getUserPrincipal方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: resolveArgument

import org.springframework.web.context.request.NativeWebRequest; //導入方法依賴的package包/類
/**
 * Construct new {@link AppSecret} object from the given Web request.
 * The authenticated user is available in the web request principal.
 */
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webReq, WebDataBinderFactory binderFactory) throws Exception {
    Authentication auth = (Authentication) webReq.getUserPrincipal();
    OneOpsUser user = (OneOpsUser) auth.getPrincipal();

    // Get the path variable.
    @SuppressWarnings("unchecked")
    Map<String, String> pathVars = (Map<String, String>) webReq.getAttribute(URI_TEMPLATE_VARIABLES_ATTRIBUTE, SCOPE_REQUEST);
    String group = pathVars != null ? pathVars.get(APP_NAME_PARAM) : "";
    String secret = pathVars != null ? pathVars.get(APP_SECRET_PARAM) : "";

    AppGroup appGroup = new AppGroup(user.getDomain(), group);
    return new AppSecret(secret, appGroup);
}
 
開發者ID:oneops,項目名稱:secrets-proxy,代碼行數:19,代碼來源:AppSecretArgResolver.java

示例2: resolveArgument

import org.springframework.web.context.request.NativeWebRequest; //導入方法依賴的package包/類
/**
 * Construct new {@link AppGroup} object from the given Web request.
 * The authenticated user is available in the web request principal.
 */
@Override
public AppGroup resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webReq, WebDataBinderFactory binderFactory) throws Exception {
    Authentication auth = (Authentication) webReq.getUserPrincipal();
    OneOpsUser user = (OneOpsUser) auth.getPrincipal();

    // Get the path variable.
    @SuppressWarnings("unchecked")
    Map<String, String> pathVars = (Map<String, String>) webReq.getAttribute(URI_TEMPLATE_VARIABLES_ATTRIBUTE, SCOPE_REQUEST);
    String group = pathVars != null ? pathVars.get(APP_NAME_PARAM) : "";
    return AppGroup.from(user.getDomain(), group);
}
 
開發者ID:oneops,項目名稱:secrets-proxy,代碼行數:16,代碼來源:AppGroupArgResolver.java


注:本文中的org.springframework.web.context.request.NativeWebRequest.getUserPrincipal方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。