ThreadLocalClient小应用
今天遇到hibernate.find就会进行权限配置,如果某处想要跳过权限配置,则可以如下
ThreadLocalClient.get().envParamMap.put(DataAuthority.IS_APPLY_AUTHORITY, false);
所有ThreadLocalClient都在下面配置
package com.huatek.framework.security;
import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.huatek.framework.entity.FwAccount;
import com.huatek.framework.entity.FwActionCnt;
import com.huatek.framework.entity.FwGroup;
import com.huatek.framework.entity.FwSrcAction;
public class ClientInfoBean implements Serializable {
/**
*
*/
private static final long serialVersionUID = 8810206692236045600L;
private String actionURL;
private String actionMethod;
private String contextPath;
private String serverHost;
private int serverPort;
private Calendar accessCalendar;
private String actionId;
private String hostIp;
private int hostPort;
private Long menuId;
private boolean isLogged;
private String requestMethod;
public Map<String,Object> envParamMap = new HashMap<String,Object>();
public String getRequestMethod() {
return requestMethod;
}
public void setRequestMethod(String requestMethod) {
this.requestMethod = requestMethod;
}
public Long getMenuId() {
return menuId;
}
public void setMenuId(Long menuId) {
this.menuId = menuId;
}
private Long operationGroupId;
private List<FwGroup> permitGroup;
private List<FwSrcAction> permitAction;
public List<FwSrcAction> getPermitAction() {
return permitAction;
}
public void setPermitAction(List<FwSrcAction> permitAction) {
this.permitAction = permitAction;
}
public List<FwGroup> getPermitGroup() {
return permitGroup;
}
public void setPermitGroup(List<FwGroup> permitGroup) {
this.permitGroup = permitGroup;
}
public Long getOperationGroupId() {
return operationGroupId;
}
public void setOperationGroupId(Long operationGroupId) {
this.operationGroupId = operationGroupId;
}
private FwAccount operator;
private Set<FwActionCnt> auditContents;
public Set<FwActionCnt> getAuditContents() {
return auditContents;
}
public void setAuditContents(Set<FwActionCnt> auditContents) {
this.auditContents = auditContents;
}
private String actualActionPath;
public String getActualActionPath() {
return actualActionPath;
}
public void setActualActionPath(String actualActionPath) {
this.actualActionPath = actualActionPath;
}
public FwAccount getOperator() {
return operator;
}
public void setOperator(FwAccount operator) {
this.operator = operator;
}
private FwSrcAction srcAction;
public FwSrcAction getSrcAction() {
return srcAction;
}
public void setSrcAction(FwSrcAction srcAction) {
this.srcAction = srcAction;
}
public int getHostPort() {
return hostPort;
}
public void setHostPort(int hostPort) {
this.hostPort = hostPort;
}
public Calendar getAccessCalendar() {
return accessCalendar;
}
public void setAccessCalendar(Calendar accessCalendar) {
this.accessCalendar = accessCalendar;
}
public String getActionId() {
return actionId;
}
public void setActionId(String actionId) {
this.actionId = actionId;
}
public String getActionURL() {
return actionURL;
}
public void setActionURL(String actionName) {
this.actionURL = actionName;
}
public String getHostIp() {
return hostIp;
}
public void setHostIp(String hostIp) {
this.hostIp = hostIp;
}
public String toString() {
/*SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-DD hh:mm:ss");*/
Date time = accessCalendar.getInstance().getTime();
if(time==null){
time = new Date();
}
return "actionURL=" + this.actionURL + "\n" + "accessCalendar="
+ time + "\n"
+ "actionId=" + this.actionId + "\n"
+ "hostIp=" + this.hostIp;
}
public String getActionMethod() {
return actionMethod;
}
public void setActionMethod(String actionMethod) {
this.actionMethod = actionMethod;
}
public String getContextPath() {
return contextPath;
}
public void setContextPath(String contextPath) {
this.contextPath = contextPath;
}
public int getServerPort() {
return serverPort;
}
public void setServerPort(int serverPort) {
this.serverPort = serverPort;
}
public String getServerHost() {
return serverHost;
}
public void setServerHost(String serverHost) {
this.serverHost = serverHost;
}
public boolean isLogged() {
return isLogged;
}
public void setLogged(boolean isLogged) {
this.isLogged = isLogged;
}
}
根据下面判断当前的账户是否要继续
if(ThreadLocalClient.get().envParamMap.get(DataAuthority.IS_APPLY_AUTHORITY)!=null&& ThreadLocalClient.get().envParamMap.get(DataAuthority.IS_APPLY_AUTHORITY).equals(false)){ return hsql; } if (ThreadLocalClient.get() == null || ThreadLocalClient.get().getOperator()==null || ThreadLocalClient.get().getOperator().getId().longValue() == Constant.OPS_ADMIN .longValue()) { return hsql; }
自信与努力 用心坚持