然後通過Subject對象判斷當前用戶的角色/權限,然後進行不同的跳轉(直接在LoginAction中)。
我的登錄部分代碼:
Java代碼
usernamepasswortoken token = new usernamepasswortoken(名稱,密碼);
嘗試{
SecurityUtils.getSubject()。登錄(令牌);
subject subject = security utils . get subject();
//妳可以在這裏調用subject進行判斷。
system . out . println("-");
布爾is admin = subject . has role(" admin ");
log . info(" Administrator:"+is admin);
system . out . println("-");
String userId =(String)subject . get principal();
user user = userservice . get byid(userId);
ShiroUser ShiroUser = ShiroUser service . getbydyid(userId);
if(shiroUser == null){
this . addactionerror(getText(" log in . failure "));
返回錯誤;
}否則{
int used = shirouser . get used();
if(used == 1){
this . addactionerror(getText(" log in . noused "));
返回錯誤;
}
}
session session = subject . getsession(true);
session . set attribute(log in action。USER_KEY,USER);
session . set attribute(log in action。SHIRO_USER_KEY,shiroUser);
log.info("將工作流定義設置為會話");
session.setAttribute("ptDefine ",workflow context . getpt define());
} catch(認證異常e) {
log . info(e . getmessage());
this . addactionerror(getText(" log in . failure "));
}
if (this.hasErrors()) {
log.info("登錄錯誤...");
返回錯誤;
}