use of org.springframework.web.method.HandlerMethod in project alien4cloud by alien4cloud.
the class AuditController method getAllAvailableMethodsForAudit.
private <T extends Method> Map<T, Boolean> getAllAvailableMethodsForAudit(RequestMappingHandlerMapping requestMappingHandlerMapping, IAuditedMethodFactory<T> methodFactory) {
Map<RequestMappingInfo, HandlerMethod> handlerMethods = requestMappingHandlerMapping.getHandlerMethods();
Map<T, Boolean> allMethods = Maps.newHashMap();
for (Map.Entry<RequestMappingInfo, HandlerMethod> handlerMethodEntry : handlerMethods.entrySet()) {
HandlerMethod method = handlerMethodEntry.getValue();
Method auditedMethod = auditService.getAuditedMethod(method);
if (auditedMethod != null) {
Audit audit = method.getMethodAnnotation(Audit.class);
boolean enabledByDefault = audit != null && audit.enabledByDefault();
allMethods.put(methodFactory.buildAuditedMethod(auditedMethod, method), enabledByDefault);
}
}
return allMethods;
}
use of org.springframework.web.method.HandlerMethod in project alien4cloud by alien4cloud.
the class AuditService method getAuditedMethod.
public Method getAuditedMethod(HandlerMethod controllerMethod) {
RequestMapping methodMapping = AnnotationUtils.findAnnotation(controllerMethod.getMethod(), RequestMapping.class);
RequestMapping controllerMapping = AnnotationUtils.findAnnotation(controllerMethod.getMethod().getDeclaringClass(), RequestMapping.class);
String httpMethod = null;
if (controllerMapping != null) {
httpMethod = getRequestMappingMethod(controllerMapping);
if (methodMapping != null) {
String methodHttpMethod = getRequestMappingMethod(methodMapping);
if (httpMethod == null) {
// Controller http method override method http method
httpMethod = methodHttpMethod;
}
}
} else if (methodMapping != null) {
httpMethod = getRequestMappingMethod(methodMapping);
}
if (httpMethod == null) {
return null;
}
Audit audit = getAuditAnnotation(controllerMethod);
return new Method(controllerMethod.getMethod().toGenericString(), httpMethod, getAuditCategoryName(controllerMethod, audit), getAuditActionName(controllerMethod, audit), getAuditHiddenFields(audit));
}
use of org.springframework.web.method.HandlerMethod in project alien4cloud by alien4cloud.
the class AuditLogFilter method getHandlerMethod.
private HandlerMethod getHandlerMethod(HttpServletRequest request) {
HandlerExecutionChain handlerChain;
try {
handlerChain = getHandler(request);
} catch (Exception e) {
logger.warn("Unable to get handler method", e);
return null;
}
if (handlerChain == null) {
return null;
}
if (!(handlerChain.getHandler() instanceof HandlerMethod)) {
return null;
}
HandlerMethod handlerMethod = (HandlerMethod) handlerChain.getHandler();
return handlerMethod;
}
use of org.springframework.web.method.HandlerMethod in project molgenis by molgenis.
the class PluginInterceptorTest method preHandle.
@Test
public void preHandle() throws Exception {
String uri = PluginController.PLUGIN_URI_PREFIX + "test";
PluginController molgenisPlugin = createMolgenisPluginController(uri);
HandlerMethod handlerMethod = mock(HandlerMethod.class);
when(handlerMethod.getBean()).thenReturn(molgenisPlugin);
PluginInterceptor molgenisPluginInterceptor = new PluginInterceptor(molgenisUi, permissionService);
MockHttpServletRequest request = new MockHttpServletRequest();
assertTrue(molgenisPluginInterceptor.preHandle(request, null, handlerMethod));
assertEquals(request.getAttribute(PluginAttributes.KEY_CONTEXT_URL), uri);
}
use of org.springframework.web.method.HandlerMethod in project molgenis by molgenis.
the class PluginInterceptorTest method postHandlePluginidWithQueryString.
@Test
public void postHandlePluginidWithQueryString() throws Exception {
PluginInterceptor molgenisPluginInterceptor = new PluginInterceptor(molgenisUi, permissionService);
String uri = PluginController.PLUGIN_URI_PREFIX + "plugin_id_test";
HttpServletRequest mockHttpServletRequest = mock(HttpServletRequest.class);
when(mockHttpServletRequest.getQueryString()).thenReturn("entity=entityTypeId");
HandlerMethod handlerMethod = mock(HandlerMethod.class);
when(handlerMethod.getBean()).thenReturn(createMolgenisPluginController(uri));
ModelAndView modelAndView = new ModelAndView();
molgenisPluginInterceptor.postHandle(mockHttpServletRequest, null, handlerMethod, modelAndView);
assertEquals(modelAndView.getModel().get(PluginAttributes.KEY_PLUGIN_ID), "plugin_id_test");
assertNotNull(modelAndView.getModel().get(PluginAttributes.KEY_MOLGENIS_UI));
assertEquals(modelAndView.getModel().get(PluginAttributes.KEY_AUTHENTICATED), false);
assertEquals(modelAndView.getModel().get(PluginAttributes.KEY_PLUGIN_ID_WITH_QUERY_STRING), "plugin_id_test?entity=entityTypeId");
}
Aggregations