AbstractRefreshableTargetSource在spring2.0里面才有
[code]
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.acegisecurity.intercept.web.FilterInvocationDefinitionSourceEditor;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.aop.target.dynamic.AbstractRefreshableTargetSource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceEditor;
public class RefreshableFileFilterInvocationDefinition extends
AbstractRefreshableTargetSource {
protected Log logger = LogFactory.getLog(getClass());
public static final String DEFAULT_LOCATION = "classpath:acegi-filterInvocation.conf";
private String location = DEFAULT_LOCATION;
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
protected Object freshTarget() {
ResourceEditor editor = new ResourceEditor();
editor.setAsText(getLocation());
Resource resource = (Resource) editor.getValue();
if (resource == null) {
logger
.warn("Can't find a Acegi FilterInvocationDefinition config file");
return null;
}
StringBuffer sb = new StringBuffer();
char[] cbuf = new char[100];
int read;
InputStream is = null;
InputStreamReader isr = null;
try {
is = resource.getInputStream();
isr = new InputStreamReader(is);
while ((read = (isr.read(cbuf, 0, cbuf.length))) != -1)
sb.append(cbuf, 0, read);
logger.info("loaded Acegi FilterInvocationDefinition config file");
} catch (IOException e) {
logger.warn(e.getMessage(), e);
} finally {
try {
if (isr != null)
isr.close();
if (is != null)
is.close();
} catch (IOException e) {
logger.warn(e.getMessage(), e);
}
}
FilterInvocationDefinitionSourceEditor configEditor = new FilterInvocationDefinitionSourceEditor();
configEditor.setAsText(sb.toString());
return configEditor.getValue();
}
}
[/code]
acegi的spring配置文件
class="org.acegisecurity.intercept.web.FilterSecurityInterceptor">
ref="authenticationManager" />
ref="httpRequestAccessDecisionManager" />
ref="objectDefinitionSource" />
class="RefreshableFileFilterInvocationDefinition">
class="org.springframework.aop.framework.ProxyFactoryBean">
ref="refreshableFileFilterInvocationDefinition" />
也可以用dwr来手动刷新,并且配置权限,role是在acegi里面配置的
scope="application">