屬性名 | 類型 | 默認(rèn)值 | 描述 |
bdf2.syncCacheremoteServerUrls | String | 空 | 用于指定在當(dāng)前應(yīng)用當(dāng)中用戶手工觸發(fā)權(quán)限模塊當(dāng)中刷新緩存操作時(shí),需要調(diào)用哪些其它節(jié)點(diǎn)應(yīng)用的Webservice來同步刷新權(quán)限緩存,比如: bdf2.syncCacheremoteServerUrls=http://www.bstek.com:82/bdf2-demo/,http://www.bstek.com:81/bdf2-demo/可以看到上面配置了兩個(gè)URL,中間使用逗號(hào)分隔,這樣當(dāng)前應(yīng)用在刷新權(quán)限緩存時(shí)就是更新這兩個(gè)URL上對(duì)應(yīng)的權(quán)限緩存信息,可以看到這個(gè)URL在定義時(shí)要包含我們應(yīng)用的ContextPath,比如這里的bdf2-demo。除了可以在dorado-home目錄下的configure.properties當(dāng)中配置bdf2.syncCacheremoteServerUrls這個(gè)屬性值以外,我們還可以將其配置成JVM變量,JVM變量名就是bdf2.syncCacheremoteServerUrls。 |
bdf2.syncCacheRemoteServerUsernamePassword | String | 空 | 調(diào)用目標(biāo)節(jié)點(diǎn)應(yīng)用Webservice時(shí)需要的驗(yàn)證的用戶名密碼信息,它們中間用逗號(hào)分隔(username,password,順序不能顛倒),同時(shí)這個(gè)屬性值除了可以在dorado-home目錄下的configure.properties當(dāng)中外,還可以配置到我們應(yīng)用所在JVM變量當(dāng)中,變量名就叫bdf2.syncCacheRemoteServerUsernamePassword。 |
實(shí)現(xiàn)權(quán)限緩存同步類的源碼
package com.bstek.bdf2.webservice.sync.cache; import java.lang.reflect.Method; import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.InitializingBean; import com.bstek.bdf2.core.aop.IMethodInterceptor; import com.bstek.bdf2.core.business.IUser; import com.bstek.bdf2.core.context.ContextHolder; import com.bstek.bdf2.webservice.client.WebServiceClient; import com.bstek.bdf2.webservice.jaxb.IWebservice; import com.bstek.bdf2.webservice.rpc.data.DataRequest; import com.bstek.bdf2.webservice.rpc.data.DataResponse; /** * @author Jacky.gao * @since 2013年7月12日 */ public class SyncRefreshSecurityCache implements IMethodInterceptor,InitializingBean{ private static final String C1="com.bstek.bdf2.core.view.role.component.RoleComponentMaintain"; private static final String C2="com.bstek.bdf2.core.view.role.RoleMaintain"; private static final String C3="com.bstek.bdf2.core.view.role.url.RoleUrlMaintain"; private static final String C4="com.bstek.bdf2.authoritydelegation.view.role.url.RoleUrlMaintain"; private static final String M1="refreshUrlSecurityMetadata"; private static final String M2="refreshAllSecurityMetadata"; private static final String M3="refreshComponentSecurityMetadata"; private String remoteServerUrls; private String remoteServerUsernamePassword; private String username; private String password; public boolean support(Class<?> objectClass, Method method) { if(objectClass==null)return false; if(ContextHolder.getRequest()==null)return false; Object loginWay=ContextHolder.getHttpSession().getAttribute(ContextHolder.USER_LOGIN_WAY_KEY); if(loginWay!=null && loginWay.equals(IWebservice.WS_LOGIN_WAY.toString()))return false; if(StringUtils.isEmpty(remoteServerUrls))return false; String className=objectClass.getName(); if(className.equals(C1) || className.equals(C2) || className.equals(C3) || className.equals(C4)){ String methodName=method.getName(); if(methodName.equals(M1) || methodName.equals(M2) || methodName.equals(M3)){ return true; } } return false; } public void doBefore(Class<?> objectClass, Method method, Object[] arguments) throws Exception { //do nothing } public void doAfter(Class<?> objectClass, Method method,Object[] arguments, Object returnValue) throws Exception { DataRequest req=new DataRequest(); req.setBeanId("bdf2.roleMaintain"); req.setMethodName(method.getName()); String suffix="dorado/webservice/SpringBeanRPC"; if(StringUtils.isEmpty(remoteServerUsernamePassword)){ IUser user=ContextHolder.getLoginUser(); this.username=user.getUsername(); this.password=user.getPassword(); } for(String url:remoteServerUrls.split(",")){ if(url.endsWith("/")){ url=url+suffix; }else{ url=url+"/"+suffix; } WebServiceClient client=new WebServiceClient(url); client.setUsernameToken(username, password, true); client.setMarshallerClasses(new Class<?>[]{DataRequest.class,DataResponse.class}); DataResponse res=(DataResponse)client.sendAndReceive(req); if(!res.isSuccessful()){ throw new RuntimeException(res.getReturnValue()); } } } public void afterPropertiesSet() throws Exception { if(StringUtils.isEmpty(remoteServerUsernamePassword)){ remoteServerUsernamePassword=System.getProperty("bdf2.syncCacheRemoteServerUsernamePasswo rd"); } if(StringUtils.isNotEmpty(remoteServerUsernamePassword)){ String[] account=remoteServerUsernamePassword.split(","); if(account.length!=2){ throw new IllegalArgumentException("Username and password must be separated by commas"); } this.username=account[0]; this.password=account[1]; } if(StringUtils.isEmpty(remoteServerUrls)){ remoteServerUrls=System.getProperty("bdf2.syncCacheremoteServerUrls"); } } public void setRemoteServerUrls(String remoteServerUrls) { this.remoteServerUrls = remoteServerUrls; } public void setRemoteServerUsernamePassword(String remoteServerUsernamePassword) { this.remoteServerUsernamePassword = remoteServerUsernamePassword; } }
更多建議: