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


Java Subject.getPrincipals方法代碼示例

本文整理匯總了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();
    }
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:14,代碼來源:IndexController.java

示例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();
}
 
開發者ID:TomChen001,項目名稱:xmanager,代碼行數:51,代碼來源:SysLogAspect.java


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