All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alogic.auth.service.CheckSinglePrivilege Maven / Gradle / Ivy

package com.alogic.auth.service;

import java.util.HashMap;
import java.util.Map;

import com.alogic.auth.Principal;
import com.alogic.auth.PrincipalManager;
import com.alogic.auth.Session;
import com.alogic.auth.SessionManagerFactory;
import com.anysoft.util.JsonTools;
import com.logicbus.backend.AbstractServant;
import com.logicbus.backend.Context;
import com.logicbus.backend.message.JsonMessage;
import com.logicbus.backend.message.YamlMessage;
import com.logicbus.models.servant.ServiceDescription;

/**
 * 检查单项权限
 * 
 * @author duanyy
 * @since 1.6.10.10
 * 
 * @version 1.6.11.59 [20180911 duanyy] 
* - 优化权限接口
* * @version 1.6.12.27 [20190403 duanyy]
* - 增加对yaml的支持
*/ public class CheckSinglePrivilege extends AbstractServant{ @Override protected void onDestroy() { } @Override protected void onCreate(ServiceDescription sd) { } @Override protected int onJson(Context ctx){ JsonMessage msg = (JsonMessage)ctx.asMessage(JsonMessage.class); @SuppressWarnings("unchecked") Map data = (Map)msg.getRoot().get("data"); if (data == null){ data = new HashMap(); msg.getRoot().put("data", data); } PrincipalManager sm = (PrincipalManager)SessionManagerFactory.getDefault(); Session sess = sm.getSession(ctx, false); if (sess == null){ JsonTools.setString(data,"isLoggedIn","false"); }else{ Principal principal = sm.getCurrent(ctx); if (principal != null){ String privilege = this.getArgument("privilege", "", ctx); JsonTools.setString(data,"privilege",privilege); sm.checkPrivilege(principal, data); } JsonTools.setBoolean(data,"isLoggedIn",sess.isLoggedIn()); } return 0; } @Override protected int onYaml(Context ctx){ YamlMessage msg = (YamlMessage)ctx.asMessage(YamlMessage.class); @SuppressWarnings("unchecked") Map data = (Map)msg.getRoot().get("data"); if (data == null){ data = new HashMap(); msg.getRoot().put("data", data); } PrincipalManager sm = (PrincipalManager)SessionManagerFactory.getDefault(); Session sess = sm.getSession(ctx, false); if (sess == null){ JsonTools.setString(data,"isLoggedIn","false"); }else{ Principal principal = sm.getCurrent(ctx); if (principal != null){ String privilege = this.getArgument("privilege", "", ctx); JsonTools.setString(data,"privilege",privilege); sm.checkPrivilege(principal, data); } JsonTools.setBoolean(data,"isLoggedIn",sess.isLoggedIn()); } return 0; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy