本文整理匯總了Java中org.apache.shiro.subject.Subject.getPrincipals方法的典型用法代碼示例。如果您正苦於以下問題:Java Subject.getPrincipals方法的具體用法?Java Subject.getPrincipals怎麽用?Java Subject.getPrincipals使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.shiro.subject.Subject
的用法示例。
在下文中一共展示了Subject.getPrincipals方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: user
import org.apache.shiro.subject.Subject; //導入方法依賴的package包/類
@RequiresPermissions(value = { "user:edit" })
@GetMapping("/user/{id}")
public Object user(@PathVariable(value = "id") String id,HttpServletRequest request) {
Subject subject = SecurityUtils.getSubject();
//gonson解析
PrincipalCollection att = subject.getPrincipals();
LOGGER.info(">>>>>>>>>>>>>>>>>>>>>>>> {}",att);
// JSONArray ja = JSON.parseArray(subject.getPrincipals().toString());
// LOGGER.info(">>>>>>>>>>>>>>>>>>>>>>>> {}",ja);
return SecurityUtils.getSubject().getPrincipals();
}
示例2: recordSysLog
import org.apache.shiro.subject.Subject; //導入方法依賴的package包/類
@Around("cutController()")
public Object recordSysLog(ProceedingJoinPoint point) throws Throwable {
String strMethodName = point.getSignature().getName();
String strClassName = point.getTarget().getClass().getName();
Object[] params = point.getArgs();
StringBuffer bfParams = new StringBuffer();
Enumeration<String> paraNames = null;
HttpServletRequest request = null;
if (params != null && params.length > 0) {
request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
paraNames = request.getParameterNames();
String key;
String value;
while (paraNames.hasMoreElements()) {
key = paraNames.nextElement();
value = request.getParameter(key);
bfParams.append(key).append("=").append(value).append("&");
}
if (StringUtils.isBlank(bfParams)) {
bfParams.append(request.getQueryString());
}
}
String strMessage = String
.format("[類名]:%s,[方法]:%s,[參數]:%s", strClassName, strMethodName, bfParams.toString());
LOGGER.info(strMessage);
if (isWriteLog(strMethodName)) {
try {
Subject currentUser = SecurityUtils.getSubject();
PrincipalCollection collection = currentUser.getPrincipals();
if (null != collection) {
String loginName = collection.getPrimaryPrincipal().toString();
SysLog sysLog = new SysLog();
sysLog.setLoginName(loginName);
sysLog.setRoleName(loginName);
sysLog.setOptContent(strMessage);
sysLog.setCreateTime(new Date());
if (request != null) {
sysLog.setClientIp(request.getRemoteAddr());
}
LOGGER.info(sysLog.toString());
sysLogService.insert(sysLog);
}
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
}
}
return point.proceed();
}