Package org.springframework.security.web.servletapi

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


        SecurityContextHolder.getContext().setAuthentication(auth);

        MockHttpServletRequest request = new MockHttpServletRequest();
        request.setRequestURI("/");

        SecurityContextHolderAwareRequestWrapper wrapper = new SecurityContextHolderAwareRequestWrapper(request, "");

        assertEquals("rod", wrapper.getRemoteUser());
        assertTrue(wrapper.isUserInRole("ROLE_FOO"));
        assertFalse(wrapper.isUserInRole("ROLE_NOT_GRANTED"));
        assertEquals(auth, wrapper.getUserPrincipal());
    }
View Full Code Here


        SecurityContextHolder.getContext().setAuthentication(auth);

        MockHttpServletRequest request = new MockHttpServletRequest();
        request.setRequestURI("/");

        SecurityContextHolderAwareRequestWrapper wrapper = new SecurityContextHolderAwareRequestWrapper(request, "ROLE_");

        assertTrue(wrapper.isUserInRole("FOO"));
    }
View Full Code Here

        SecurityContextHolder.getContext().setAuthentication(auth);

        MockHttpServletRequest request = new MockHttpServletRequest();
        request.setRequestURI("/");

        SecurityContextHolderAwareRequestWrapper wrapper = new SecurityContextHolderAwareRequestWrapper(request, "");

        assertEquals("rodAsUserDetails", wrapper.getRemoteUser());
        assertFalse(wrapper.isUserInRole("ROLE_FOO"));
        assertFalse(wrapper.isUserInRole("ROLE_NOT_GRANTED"));
        assertTrue(wrapper.isUserInRole("ROLE_FOOBAR"));
        assertTrue(wrapper.isUserInRole("ROLE_HELLO"));
        assertEquals(auth, wrapper.getUserPrincipal());
    }
View Full Code Here

        SecurityContextHolder.getContext().setAuthentication(null);

        MockHttpServletRequest request = new MockHttpServletRequest();
        request.setRequestURI("/");

        SecurityContextHolderAwareRequestWrapper wrapper = new SecurityContextHolderAwareRequestWrapper(request, "");
        assertNull(wrapper.getRemoteUser());
        assertFalse(wrapper.isUserInRole("ROLE_ANY"));
        assertNull(wrapper.getUserPrincipal());
    }
View Full Code Here

        SecurityContextHolder.getContext().setAuthentication(auth);

        MockHttpServletRequest request = new MockHttpServletRequest();
        request.setRequestURI("/");

        SecurityContextHolderAwareRequestWrapper wrapper = new SecurityContextHolderAwareRequestWrapper(request, "");

        assertNull(wrapper.getRemoteUser());
        assertFalse(wrapper.isUserInRole("ROLE_HELLO")); // principal is null, so reject
        assertFalse(wrapper.isUserInRole("ROLE_FOOBAR")); // principal is null, so reject
        assertNull(wrapper.getUserPrincipal());
    }
View Full Code Here

    /**
     * Check if user has role.
     */
    private boolean hasRole(String role) {
        HttpServletRequest req = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
        SecurityContextHolderAwareRequestWrapper sc = new SecurityContextHolderAwareRequestWrapper(req, "");
        return sc.isUserInRole(role);
    }
View Full Code Here

    /**
     * Check if user has role.
     */
    private boolean hasRole(String role) {
        HttpServletRequest req = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
        SecurityContextHolderAwareRequestWrapper sc = new SecurityContextHolderAwareRequestWrapper(req, "");
        return sc.isUserInRole(role);
    }
View Full Code Here

  @Before
  public void setMockRequest() {
    MockHttpServletRequest req = new MockHttpServletRequest();
    req.addHeader("User-Agent", "Win");
    SecurityContextHolderAwareRequestWrapper reqWrapper = new SecurityContextHolderAwareRequestWrapper(req, "U");
    RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(reqWrapper));
  }
View Full Code Here

  @Before
  public void setMockContext() {
    MockHttpServletRequest req = new MockHttpServletRequest();
    req.addHeader("User-Agent", "Win");
    SecurityContextHolderAwareRequestWrapper reqWrapper = new SecurityContextHolderAwareRequestWrapper(req, "U");
    RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(reqWrapper));
  }
View Full Code Here

    if (StringUtils.isNotBlank(httpUrl)) {
      return httpUrl;
    }

    // if empty
    SecurityContextHolderAwareRequestWrapper request = cast(RequestContextHolder.currentRequestAttributes()
        .resolveReference("request"));
    int serverPort = request.getServerPort();
    // If it's http default port it will ignore the port part.
    // However, if ngrinder is provided in HTTPS.. it can be a problem.
    // FIXME : Later fix above.
    String portString = (serverPort == DEFAULT_WEB_PORT) ? StringUtils.EMPTY : ":" + serverPort;
    return httpUrl + request.getScheme() + "://" + request.getServerName() + portString + request.getContextPath();
  }
View Full Code Here

TOP

Related Classes of org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestWrapper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.