Search in sources :

Example 1 with HeaderWriter

use of org.springframework.security.web.header.HeaderWriter in project spring-security by spring-projects.

the class HeaderWriterLogoutHandlerTests method logoutWhenHasHeaderWriterThenInvoked.

@Test
public void logoutWhenHasHeaderWriterThenInvoked() {
    HeaderWriter headerWriter = mock(HeaderWriter.class);
    HeaderWriterLogoutHandler handler = new HeaderWriterLogoutHandler(headerWriter);
    handler.logout(this.request, this.response, mock(Authentication.class));
    verify(headerWriter).writeHeaders(this.request, this.response);
}
Also used : Authentication(org.springframework.security.core.Authentication) HeaderWriter(org.springframework.security.web.header.HeaderWriter) Test(org.junit.jupiter.api.Test)

Example 2 with HeaderWriter

use of org.springframework.security.web.header.HeaderWriter in project spring-security by spring-projects.

the class HeadersConfigurer method createHeaderWriterFilter.

/**
 * Creates the {@link HeaderWriter}
 * @return the {@link HeaderWriter}
 */
private HeaderWriterFilter createHeaderWriterFilter() {
    List<HeaderWriter> writers = getHeaderWriters();
    if (writers.isEmpty()) {
        throw new IllegalStateException("Headers security is enabled, but no headers will be added. Either add headers or disable headers security");
    }
    HeaderWriterFilter headersFilter = new HeaderWriterFilter(writers);
    headersFilter = postProcess(headersFilter);
    return headersFilter;
}
Also used : HstsHeaderWriter(org.springframework.security.web.header.writers.HstsHeaderWriter) ContentSecurityPolicyHeaderWriter(org.springframework.security.web.header.writers.ContentSecurityPolicyHeaderWriter) ReferrerPolicyHeaderWriter(org.springframework.security.web.header.writers.ReferrerPolicyHeaderWriter) HpkpHeaderWriter(org.springframework.security.web.header.writers.HpkpHeaderWriter) FeaturePolicyHeaderWriter(org.springframework.security.web.header.writers.FeaturePolicyHeaderWriter) HeaderWriter(org.springframework.security.web.header.HeaderWriter) XContentTypeOptionsHeaderWriter(org.springframework.security.web.header.writers.XContentTypeOptionsHeaderWriter) XXssProtectionHeaderWriter(org.springframework.security.web.header.writers.XXssProtectionHeaderWriter) PermissionsPolicyHeaderWriter(org.springframework.security.web.header.writers.PermissionsPolicyHeaderWriter) CrossOriginEmbedderPolicyHeaderWriter(org.springframework.security.web.header.writers.CrossOriginEmbedderPolicyHeaderWriter) CrossOriginResourcePolicyHeaderWriter(org.springframework.security.web.header.writers.CrossOriginResourcePolicyHeaderWriter) CrossOriginOpenerPolicyHeaderWriter(org.springframework.security.web.header.writers.CrossOriginOpenerPolicyHeaderWriter) XFrameOptionsHeaderWriter(org.springframework.security.web.header.writers.frameoptions.XFrameOptionsHeaderWriter) HeaderWriterFilter(org.springframework.security.web.header.HeaderWriterFilter)

Example 3 with HeaderWriter

use of org.springframework.security.web.header.HeaderWriter in project spring-security by spring-projects.

the class CompositeHeaderWriterTests method writeHeadersWhenConfiguredWithDelegatesThenInvokesEach.

@Test
public void writeHeadersWhenConfiguredWithDelegatesThenInvokesEach() {
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse response = mock(HttpServletResponse.class);
    HeaderWriter one = mock(HeaderWriter.class);
    HeaderWriter two = mock(HeaderWriter.class);
    CompositeHeaderWriter headerWriter = new CompositeHeaderWriter(Arrays.asList(one, two));
    headerWriter.writeHeaders(request, response);
    verify(one).writeHeaders(request, response);
    verify(two).writeHeaders(request, response);
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) HttpServletResponse(jakarta.servlet.http.HttpServletResponse) HeaderWriter(org.springframework.security.web.header.HeaderWriter) Test(org.junit.jupiter.api.Test)

Aggregations

HeaderWriter (org.springframework.security.web.header.HeaderWriter)3 Test (org.junit.jupiter.api.Test)2 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)1 HttpServletResponse (jakarta.servlet.http.HttpServletResponse)1 Authentication (org.springframework.security.core.Authentication)1 HeaderWriterFilter (org.springframework.security.web.header.HeaderWriterFilter)1 ContentSecurityPolicyHeaderWriter (org.springframework.security.web.header.writers.ContentSecurityPolicyHeaderWriter)1 CrossOriginEmbedderPolicyHeaderWriter (org.springframework.security.web.header.writers.CrossOriginEmbedderPolicyHeaderWriter)1 CrossOriginOpenerPolicyHeaderWriter (org.springframework.security.web.header.writers.CrossOriginOpenerPolicyHeaderWriter)1 CrossOriginResourcePolicyHeaderWriter (org.springframework.security.web.header.writers.CrossOriginResourcePolicyHeaderWriter)1 FeaturePolicyHeaderWriter (org.springframework.security.web.header.writers.FeaturePolicyHeaderWriter)1 HpkpHeaderWriter (org.springframework.security.web.header.writers.HpkpHeaderWriter)1 HstsHeaderWriter (org.springframework.security.web.header.writers.HstsHeaderWriter)1 PermissionsPolicyHeaderWriter (org.springframework.security.web.header.writers.PermissionsPolicyHeaderWriter)1 ReferrerPolicyHeaderWriter (org.springframework.security.web.header.writers.ReferrerPolicyHeaderWriter)1 XContentTypeOptionsHeaderWriter (org.springframework.security.web.header.writers.XContentTypeOptionsHeaderWriter)1 XXssProtectionHeaderWriter (org.springframework.security.web.header.writers.XXssProtectionHeaderWriter)1 XFrameOptionsHeaderWriter (org.springframework.security.web.header.writers.frameoptions.XFrameOptionsHeaderWriter)1