use of org.apache.shiro.subject.Subject in project bamboobsc by billchen198318.
the class GreenStepHessianServiceExporter method handleRequest.
@Override
public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
/**
* 不用檢查checkValue模式
*/
if (!GreenStepHessianUtils.getConfigHessianHeaderCheckValueModeEnable()) {
super.handleRequest(request, response);
return;
}
/**
* 一般要檢查checkValue模式
*/
String checkValue = GreenStepHessianUtils.getHttpRequestHeaderCheckValue(request);
Map<String, String> dataMap = null;
try {
dataMap = GreenStepHessianUtils.getDecAuthValue(checkValue);
if (null == dataMap || !GreenStepHessianUtils.isCheckValue(dataMap)) {
logger.warn("fail check value hessian webService");
return;
}
String userId = GreenStepHessianUtils.getUserId(dataMap);
if (StringUtils.isBlank(userId)) {
logger.warn("no userId cannot access hessian webService");
return;
}
if (GreenStepHessianUtils.isProxyBlockedAccountId(userId)) {
logger.warn("blocked userId: " + userId + " cannot access hessian webService");
return;
}
} catch (Exception e) {
logger.error(e.getMessage().toString());
e.printStackTrace();
return;
}
Subject subject = null;
try {
ShiroLoginSupport loginSupport = new ShiroLoginSupport();
subject = loginSupport.forceCreateLoginSubject(request, response, GreenStepHessianUtils.getUserId(dataMap), "0123");
super.handleRequest(request, response);
} catch (Exception e) {
logger.error(e.getMessage().toString());
e.printStackTrace();
} finally {
if (null != subject) {
subject.logout();
}
}
}
use of org.apache.shiro.subject.Subject in project bamboobsc by billchen198318.
the class GreenStepMobileFormAuthenticationFilter method executeLogin.
protected boolean executeLogin(ServletRequest request, ServletResponse response) throws Exception {
GreenStepBaseUsernamePasswordToken token = (GreenStepBaseUsernamePasswordToken) this.createToken(request, response);
try {
this.doCaptchaValidate((HttpServletRequest) request, token);
ShiroLoginSupport loginSupport = new ShiroLoginSupport();
AccountVO account = loginSupport.queryUserValidate(token.getUsername());
Subject subject = this.getSubject(request, response);
subject.login(token);
// set session
this.setUserSession((HttpServletRequest) request, (HttpServletResponse) response, account);
return this.onLoginSuccess(token, subject, request, response);
} catch (AuthenticationException e) {
// clear session
UserAccountHttpSessionSupport.remove((HttpServletRequest) request);
this.getSubject(request, response).logout();
return this.onLoginFailure(token, e, request, response);
}
}
use of org.apache.shiro.subject.Subject in project bamboobsc by billchen198318.
the class MenuSupportUtils method loadSysMenuData.
protected static List<SysMenuVO> loadSysMenuData(String system) throws ServiceException, Exception {
List<SysMenuVO> menuList = null;
TbSys sys = new TbSys();
sys.setSysId(system);
if (sysService.countByEntityUK(sys) != 1) {
// 必需要有 TB_SYS 資料
throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.DATA_ERRORS));
}
Subject subject = SecurityUtils.getSubject();
String account = (String) subject.getPrincipal();
if (StringUtils.isBlank(account)) {
throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.DATA_ERRORS));
}
if (subject.hasRole(Constants.SUPER_ROLE_ADMIN) || subject.hasRole(Constants.SUPER_ROLE_ALL)) {
account = null;
}
DefaultResult<List<SysMenuVO>> result = sysMenuService.findForMenuGenerator(system, account);
if (result.getValue() != null) {
menuList = result.getValue();
}
if (menuList == null) {
menuList = new ArrayList<SysMenuVO>();
}
return menuList;
}
use of org.apache.shiro.subject.Subject in project bamboobsc by billchen198318.
the class BaseSupportAction method isActionAuthorize.
/**
* ControllerAuthorityCheckInterceptor 會去掉沒有權限的action, 只是配合 json 通一變數 "isAuthorize" 要用到
*
* @return
*/
protected String isActionAuthorize() {
((BaseSimpleActionInfo) this.baseActionInfoProvide).handlerActionAnnotations();
Subject subject = SecurityUtils.getSubject();
if (subject.hasRole(Constants.SUPER_ROLE_ALL) || subject.hasRole(Constants.SUPER_ROLE_ADMIN)) {
return YesNo.YES;
}
if (this.isControllerAuthority(((BaseSimpleActionInfo) this.baseActionInfoProvide).getActionAnnotations(), ((BaseSimpleActionInfo) this.baseActionInfoProvide).getActionMethodAnnotations(), subject)) {
return YesNo.YES;
}
if (subject.isPermitted(this.baseActionInfoProvide.getPageInfoActionName() + Constants._S2_ACTION_EXTENSION)) {
return YesNo.YES;
}
return YesNo.NO;
}
use of org.apache.shiro.subject.Subject in project ddf by codice.
the class NotificationController method getPersistedNotifications.
@Listener('/' + Notification.NOTIFICATION_TOPIC_ROOT)
public void getPersistedNotifications(final ServerSession remote, Message message) {
Subject subject = null;
try {
subject = SecurityUtils.getSubject();
} catch (Exception e) {
LOGGER.debug("Couldn't grab user subject from Shiro.", e);
}
String userId = getUserId(remote, subject);
if (null == userId) {
throw new IllegalArgumentException("User ID is null");
}
Map<String, Object> data = message.getDataAsMap();
if (MapUtils.isEmpty(data)) {
List<Map<String, Object>> notifications = getNotificationsForUser(userId);
if (CollectionUtils.isNotEmpty(notifications)) {
queuePersistedMessages(remote, notifications, "/" + Notification.NOTIFICATION_TOPIC_BROADCAST);
}
} else {
String id = UUID.randomUUID().toString().replaceAll("-", "");
String sessionId = remote.getId();
Notification notification = new Notification(id, sessionId, (String) data.get(Notification.NOTIFICATION_KEY_APPLICATION), (String) data.get(Notification.NOTIFICATION_KEY_TITLE), (String) data.get(Notification.NOTIFICATION_KEY_MESSAGE), (Long) data.get(Notification.NOTIFICATION_KEY_TIMESTAMP), userId);
Event event = new Event(Notification.NOTIFICATION_TOPIC_PUBLISH, notification);
eventAdmin.postEvent(event);
}
}
Aggregations