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());
}
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("{\"")));
}
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());
}
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("<>& ");
}
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("<>& ");
}
Aggregations