org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestWrapper Java Examples

The following examples show how to use org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestWrapper. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ErrorController.java    From codenjoy with GNU General Public License v3.0 6 votes vote down vote up
private ResponseEntity<ModelMap> error(Exception exception, HttpServletRequest req, ModelMap model) {
    String url = req.getRequestURL().toString();

    // для "not found" запросов вытаскиваем доп инфо
    if (req instanceof SecurityContextHolderAwareRequestWrapper) {
        ServletRequest request = ((SecurityContextHolderAwareRequestWrapper) req).getRequest();
        if (request instanceof FirewalledRequest) {
            ServletRequest request2 = ((FirewalledRequest) request).getRequest();
            if (request2 instanceof Request) {
                url = String.format("%s [%s]",
                        url, ((Request)request2).getOriginalURI());
            }
        }
    }

    ModelAndView view = ticket.get(url, exception);
    model.mergeAttributes(view.getModel());

    return new ResponseEntity<>(model,
            HttpStatus.INTERNAL_SERVER_ERROR);
}
 
Example #2
Source File: ErrorController.java    From codenjoy with GNU General Public License v3.0 6 votes vote down vote up
private String error(Exception exception, HttpServletRequest req, ModelMap model) {
    String url = req.getRequestURL().toString();

    // для "not found" запросов вытаскиваем доп инфо
    if (req instanceof SecurityContextHolderAwareRequestWrapper) {
        ServletRequest request = ((SecurityContextHolderAwareRequestWrapper) req).getRequest();
        if (request instanceof FirewalledRequest) {
            ServletRequest request2 = ((FirewalledRequest) request).getRequest();
            if (request2 instanceof Request) {
                url = String.format("%s [%s]",
                        url, ((Request)request2).getOriginalURI());
            }
        }
    }

    ModelAndView view = ticket.get(url, exception);
    model.mergeAttributes(view.getModel());

    return view.getViewName();
}
 
Example #3
Source File: AwsProxyRequestDispatcherTest.java    From aws-serverless-java-container with Apache License 2.0 5 votes vote down vote up
@Test
public void setPathForWrappedRequest_forwardByPath_proxyRequestObjectInPropertyReferencesSameProxyRequest() throws InvalidRequestEventException {
    AwsProxyRequest proxyRequest = new AwsProxyRequestBuilder("/hello", "GET").build();
    HttpServletRequest servletRequest = requestReader.readRequest(proxyRequest,null, new MockLambdaContext(), ContainerConfig.defaultConfig());
    SecurityContextHolderAwareRequestWrapper springSecurityRequest = new SecurityContextHolderAwareRequestWrapper(servletRequest, "ADMIN");

    AwsProxyRequestDispatcher dispatcher = new AwsProxyRequestDispatcher(FORWARD_PATH, false, null);
    dispatcher.setRequestPath(springSecurityRequest, FORWARD_PATH);
    assertEquals(FORWARD_PATH, springSecurityRequest.getRequestURI());
}
 
Example #4
Source File: AwsProxyRequestDispatcherTest.java    From aws-serverless-java-container with Apache License 2.0 5 votes vote down vote up
@Test
public void setPathForWrappedRequestWithoutGatewayEvent_forwardByPath_throwsException() {
    AwsProxyRequest proxyRequest = new AwsProxyRequestBuilder("/hello", "GET").build();
    AwsProxyHttpServletRequest servletRequest = new AwsProxyHttpServletRequest(proxyRequest, new MockLambdaContext(), null);
    SecurityContextHolderAwareRequestWrapper springSecurityRequest = new SecurityContextHolderAwareRequestWrapper(servletRequest, "ADMIN");

    AwsProxyRequestDispatcher dispatcher = new AwsProxyRequestDispatcher(FORWARD_PATH, false, null);
    try {
        dispatcher.setRequestPath(springSecurityRequest, FORWARD_PATH);
    } catch (Exception e) {
        assertTrue(e instanceof IllegalStateException);
        return;
    }
    fail();
}
 
Example #5
Source File: SecurityService.java    From airsonic-advanced with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Returns the name of the currently logged-in user.
 *
 * @param request The HTTP request.
 * @return The name of the logged-in user, or <code>null</code>.
 */
public String getCurrentUsername(HttpServletRequest request) {
    return new SecurityContextHolderAwareRequestWrapper(request, null).getRemoteUser();
}
 
Example #6
Source File: SecurityService.java    From airsonic with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Returns the name of the currently logged-in user.
 *
 * @param request The HTTP request.
 * @return The name of the logged-in user, or <code>null</code>.
 */
public String getCurrentUsername(HttpServletRequest request) {
    return new SecurityContextHolderAwareRequestWrapper(request, null).getRemoteUser();
}