本文整理匯總了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);
}
示例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);
}