我正在尝试使用Java Config实现方法安全性,但我收到一个错误: -
org.springframework.expression.spel.SpelEvaluationException: EL1057E:(pos 1): No bean resolver registered in the context to resolve access to bean 'appPermissionEvaluator'
Run Code Online (Sandbox Code Playgroud)
方法是: -
@PreAuthorize("@appPermissionEvaluator.hasSystemPermission()")
public String something() {
...
}
Run Code Online (Sandbox Code Playgroud)
Config类定义是(MethodSecurityConfig.java): -
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class MethodSecurityConfig extends GlobalMethodSecurityConfiguration {
@Bean
public AppPermissionEvaluator appPermissionEvaluator() {
return new AppPermissionEvaluator();
}
@Override
protected MethodSecurityExpressionHandler createExpressionHandler() {
DefaultMethodSecurityExpressionHandler expressionHandler =
new DefaultMethodSecurityExpressionHandler();
expressionHandler.setPermissionEvaluator(appPermissionEvaluator());
return expressionHandler;
}
...
}
Run Code Online (Sandbox Code Playgroud)
我检查了我能够在同一个类中自动装配bean,我发现默认的hasPermission()方法正在我已经实现它们,唯一的问题是从SpEL读取bean.我不确定是什么问题.任何指针?
我正在使用Spring 4.1.5和Spring security 3.2.7
通用分析中如何获取流量源数据?
我正在 firebug 控制台中尝试以下代码:-
ga(function(tracker) {
var src = tracker.get('campaignSource');
console.log(src);
});
Run Code Online (Sandbox Code Playgroud)
但它总是记录“未定义”。
字段“campaignMedium”也返回“未定义”。
但我得到了某些字段的正确值,例如“clientId”或“screenResolution”或“language”。
是否有其他流程来获取这些信息?
PS:我使用https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#trafficsources作为字段名称的参考。
在@ControllerAdvice
课堂上我有一个@ExceptionHandler
,这个处理程序可以很好地处理控制器错误,但是如果我有一个过滤器,它们就无法处理异常。我该如何处理这些异常?
过滤器是:-
public class AuthFilter extends UsernamePasswordAuthenticationFilter {
private LoginDTO loginDTO;
public AuthFilter() {
setRequiresAuthenticationRequestMatcher(
new AntPathRequestMatcher("/login", "POST"));
}
@Override
public Authentication attemptAuthentication(HttpServletRequest request,
HttpServletResponse response) throws AuthenticationException {
try {
loginDTO = new ObjectMapper().readValue(request.getReader(), LoginDTO.class);
} catch (Exception e) {
throw new APIException(ExceptionMessages.INVALID_LOGIN_JSON,
HttpStatus.BAD_REQUEST);
}
return super.attemptAuthentication(request, response);
}
...
}
Run Code Online (Sandbox Code Playgroud)
异常处理程序是(在@ControllerAdvice 中)
@ExceptionHandler(APIException.class)
public ResponseEntity<ErrorDTO> handleAPIException(APIException e) {
return new ResponseEntity<ErrorDTO>(new ErrorDTO(e.getMessage()),
e.getHttpStatus());
}
Run Code Online (Sandbox Code Playgroud)
更新
我的要求是为 spring 安全过滤器提供一个全局异常处理程序。有什么办法吗?
在 Google Analytics 中,有一些全局对象:-
对于 ga.js:-
哪个对象保证 ga.js 正在被使用?
对于analytics.js:-
既然全局对象的名称可以更改,那么我们如何在 analytics.js 中获取实际的全局对象?