Search in sources :

Example 16 with TestingAuthenticationToken

use of org.springframework.security.authentication.TestingAuthenticationToken in project spring-boot by spring-projects.

the class MvcEndpointIntegrationTests method sensitiveEndpointsAreSecureWithActuatorRoleWithCustomContextPath.

@Test
public void sensitiveEndpointsAreSecureWithActuatorRoleWithCustomContextPath() throws Exception {
    TestSecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("user", "N/A", "ROLE_ACTUATOR"));
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.register(SecureConfiguration.class);
    EnvironmentTestUtils.addEnvironment(this.context, "management.context-path:/management");
    MockMvc mockMvc = createSecureMockMvc();
    mockMvc.perform(get("/management/beans")).andExpect(status().isOk());
}
Also used : TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.Test)

Example 17 with TestingAuthenticationToken

use of org.springframework.security.authentication.TestingAuthenticationToken in project spring-boot by spring-projects.

the class MvcEndpointIntegrationTests method defaultJsonResponseIsNotIndented.

@Test
public void defaultJsonResponseIsNotIndented() throws Exception {
    TestSecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("user", "N/A", "ROLE_ACTUATOR"));
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.register(SecureConfiguration.class);
    MockMvc mockMvc = createSecureMockMvc();
    mockMvc.perform(get("/mappings")).andExpect(content().string(startsWith("{\"")));
}
Also used : TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.Test)

Example 18 with TestingAuthenticationToken

use of org.springframework.security.authentication.TestingAuthenticationToken in project spring-boot by spring-projects.

the class MvcEndpointIntegrationTests method jsonExtensionProvided.

@Test
public void jsonExtensionProvided() throws Exception {
    TestSecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("user", "N/A", "ROLE_ACTUATOR"));
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.register(SecureConfiguration.class);
    MockMvc mockMvc = createSecureMockMvc();
    mockMvc.perform(get("/beans.json")).andExpect(status().isOk());
}
Also used : TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.Test)

Example 19 with TestingAuthenticationToken

use of org.springframework.security.authentication.TestingAuthenticationToken in project spring-security by spring-projects.

the class AuthenticationTagTests method htmlEscapingIsUsedByDefault.

@Test
public void htmlEscapingIsUsedByDefault() throws Exception {
    SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("<>& ", ""));
    authenticationTag.setProperty("name");
    authenticationTag.doStartTag();
    authenticationTag.doEndTag();
    assertThat(authenticationTag.getLastMessage()).isEqualTo("&lt;&gt;&amp;&#32;");
}
Also used : TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Test(org.junit.Test)

Example 20 with TestingAuthenticationToken

use of org.springframework.security.authentication.TestingAuthenticationToken in project spring-security by spring-projects.

the class AuthenticationTagTests method settingHtmlEscapeToFalsePreventsEscaping.

@Test
public void settingHtmlEscapeToFalsePreventsEscaping() throws Exception {
    SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("<>& ", ""));
    authenticationTag.setProperty("name");
    authenticationTag.setHtmlEscape("false");
    authenticationTag.doStartTag();
    authenticationTag.doEndTag();
    assertThat(authenticationTag.getLastMessage()).isEqualTo("<>& ");
}
Also used : TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Test(org.junit.Test)

Aggregations

TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)183 Test (org.junit.Test)106 Authentication (org.springframework.security.core.Authentication)76 SecurityContext (org.springframework.security.core.context.SecurityContext)46 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)38 SecurityContextImpl (org.springframework.security.core.context.SecurityContextImpl)38 MifosUser (org.mifos.security.MifosUser)36 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)32 MifosUserBuilder (org.mifos.builders.MifosUserBuilder)28 Before (org.junit.Before)25 AuthenticationManager (org.springframework.security.authentication.AuthenticationManager)13 HttpServletRequest (javax.servlet.http.HttpServletRequest)12 HttpServletResponse (javax.servlet.http.HttpServletResponse)10 ConfigAttribute (org.springframework.security.access.ConfigAttribute)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)9 MockFilterChain (org.springframework.mock.web.MockFilterChain)9 GrantedAuthority (org.springframework.security.core.GrantedAuthority)9 FilterChain (javax.servlet.FilterChain)8 MutableAcl (org.springframework.security.acls.model.MutableAcl)8 PrincipalSid (org.springframework.security.acls.domain.PrincipalSid)7