本文整理汇总了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();
}