本文整理匯總了Java中java.security.Principal.toString方法的典型用法代碼示例。如果您正苦於以下問題:Java Principal.toString方法的具體用法?Java Principal.toString怎麽用?Java Principal.toString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.security.Principal
的用法示例。
在下文中一共展示了Principal.toString方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getUsername
import java.security.Principal; //導入方法依賴的package包/類
/**
* TODO default proper exception at lams level to replace RuntimeException TODO isTesting should be removed when
* login is done properly.
*
* @param req
* -
* @return username from principal object
*/
public static String getUsername(HttpServletRequest req, boolean isTesting) throws RuntimeException {
if (isTesting) {
return "test";
}
Principal prin = req.getUserPrincipal();
if (prin == null) {
throw new RuntimeException(
"Trying to get username but principal object missing. Request is " + req.toString());
}
String username = prin.getName();
if (username == null) {
throw new RuntimeException("Name missing from principal object. Request is " + req.toString()
+ " Principal object is " + prin.toString());
}
return username;
}