0
votes

I have added below definition for global exception in my Spring MVC application and got the below exception but i do not know what is wrong i think the problem in my Spring security but i am not sure any one can help me?

Global exception definition

<!-- global exception mapping -->
<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
    <property name="exceptionMappings">
    <map>
        <entry key="DataAccessException" value="error" />
    </map>
</property>
<property name="defaultErrorView" value="error"/>
</bean>
<!-- end global exception mapping -->

When any exception occurred at this action i got an exception "org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not supported"

@RequestMapping(value ="/addUser", method = RequestMethod.POST)
public String addUser(@Valid User user, BindingResult result, Model model, @RequestParam("userRole") String role) throws Exception {
    if(result.hasErrors()) {
        return "register";
    }
    String hashPassword = new PasswordHashProcessor().getHashPassword(user.getPassword());
    user.setPassword(hashPassword);
    daoService.addUser(user, role);
    List<UserRole> users = daoService.getNotAdminUsers();
    model.addAttribute("users", users);
    return "users";
}

The displayed log as below

DEBUG org.springframework.security.web.util.matcher.AntPathRequestMatcher - Checking match of request : '/adduser'; against '/admin' DEBUG org.springframework.security.web.util.matcher.AntPathRequestMatcher - Checking match of request : '/adduser'; against '/user' DEBUG org.springframework.security.web.access.intercept.FilterSecurityInterceptor - Secure object: FilterInvocation: URL: /addUser; Attributes: [hasRole('ROLE_ADMIN')] DEBUG org.springframework.security.web.access.intercept.FilterSecurityInterceptor - Previously Authenticated: org.springframework.security.authentication.UsernamePasswordAuthenticationToken@bad860a5: Principal: org.springframework.security.core.userdetails.User@586034f: Username: admin; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; Granted Authorities: ROLE_ADMIN; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@fffdaa08: RemoteIpAddress: 127.0.0.1; SessionId: 52613DC126F07FDCFA50EC1B2841159F; Granted Authorities: ROLE_ADMIN DEBUG org.springframework.security.access.vote.AffirmativeBased - Voter: org.springframework.security.web.access.expression.WebExpressionVoter@4577357d, returned: 1 DEBUG org.springframework.security.web.access.intercept.FilterSecurityInterceptor - Authorization successful DEBUG org.springframework.security.web.access.intercept.FilterSecurityInterceptor - RunAsManager did not change Authentication object DEBUG org.springframework.security.web.FilterChainProxy - /addUser reached end of additional filter chain; proceeding with original chain DEBUG org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'mvc-dispatcher' processing GET request for [/Ushers/addUser] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Looking up handler method for path /addUser EBUG org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver - Resolving exception from handler [null]: org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not supported DEBUG org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver - Resolving exception from handler [null]: org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not supported DEBUG org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver - Resolving exception from handler [null]: org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not supported WARN org.springframework.web.servlet.PageNotFound - Request method 'GET' not supported DEBUG org.springframework.web.servlet.DispatcherServlet - Null ModelAndView returned to DispatcherServlet with name 'mvc-dispatcher': assuming HandlerAdapter completed request handling DEBUG org.springframework.web.servlet.DispatcherServlet - Successfully completed request DEBUG org.springframework.security.web.access.ExceptionTranslationFilter - Chain processed normally DEBUG org.springframework.security.web.context.SecurityContextPersistenceFilter - SecurityContextHolder now cleared, as request processing completed

1

1 Answers

0
votes

The problem solved by this update,

@RequestMapping(value ="/addUser", method = RequestMethod.POST)
public String addUser(@ModelAttribute("user") @Valid User user, BindingResult result) {

    if(result.hasErrors()) {
        return "register";
    }
    String hashPassword = new PasswordHashProcessor().getHashPassword(user.getPassword());
    user.setPassword(hashPassword);
    daoService.addUser(user);
    return "redirect:/getUsers";
}