Java Code Examples for org.springframework.security.web.header.writers.frameoptions.XFrameOptionsHeaderWriter

The following examples show how to use org.springframework.security.web.header.writers.frameoptions.XFrameOptionsHeaderWriter. These examples are extracted from open source projects. 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 Project: codenjoy   Source File: SecurityConfig.java    License: GNU General Public License v3.0 6 votes vote down vote up
private static HttpSecurity securityHeaders(HttpSecurity http, List<String> allowedHosts) throws Exception {
    // @formatter:off
    http.cors()
            .and()
                .headers()
                    .httpStrictTransportSecurity().maxAgeInSeconds(31536000)
                .and()
                    .contentTypeOptions()
                .and()
                    .contentSecurityPolicy(
                            "default-src 'self';" +
                            "script-src 'self' 'unsafe-eval' 'unsafe-inline';" +
                            "img-src 'self' data:;" +
                            "connect-src 'self' ws: wss: http: https:;" +
                            "font-src 'self';" +
                            "style-src 'self' 'unsafe-inline';")
                .and()
                    .addHeaderWriter(new XFrameOptionsHeaderWriter(allowFromHostsStrategy(allowedHosts)))
            .and()
                .csrf().disable();
    // @formatter:on
    return http;
}
 
Example 2
Source Project: spring4ws-demos   Source File: WebSecurityConfig.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void configure(HttpSecurity http) throws Exception {
	// @formatter:off
	http.csrf().disable()
		.headers()
	   	  .addHeaderWriter(
				new XFrameOptionsHeaderWriter(
						XFrameOptionsHeaderWriter.XFrameOptionsMode.SAMEORIGIN))
		.and()
		  .formLogin().defaultSuccessUrl("/portfolio/index.html")
		  .loginPage("/portfolio/login.html")
		  .failureUrl("/portfolio/login.html?error").permitAll()
		.and()
		  .logout()
		    .logoutSuccessUrl("/portfolio/login.html?logout")
		    .logoutUrl("/portfolio/logout.html").permitAll()
		.and()
		  .authorizeRequests()
		    .antMatchers("/portfolio/login.css").permitAll()
		    .antMatchers("/portfolio/**").authenticated();
	// @formatter:on
}
 
Example 3
Source Project: springboot-vue.js-bbs   Source File: SecurityConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void configure(HttpSecurity http) throws Exception {
    http
        .cors()
            .and()
        .authorizeRequests()
            .antMatchers("/board/**").permitAll()
            .antMatchers("/admin/**").hasAuthority(Authority.ADMIN.getAuthority())
            .antMatchers("/h2-console/**").permitAll()
            .antMatchers("/oauth/**").hasAuthority(Authority.USER.getAuthority())
            .and()
        .csrf()
            .ignoringAntMatchers("/h2-console/**")
            .and()
        .headers()
            .addHeaderWriter(new XFrameOptionsHeaderWriter(new WhiteListedAllowFromStrategy(Arrays.asList("localhost"))))
            .and()
        .formLogin()
            .loginPage("/login").failureUrl("/login?error").permitAll()
            .usernameParameter("username")
            .passwordParameter("password")
            .defaultSuccessUrl("/")
            .and()
        .logout()
            .logoutUrl("/logout")
            .logoutSuccessUrl("/")
            .deleteCookies("JSESSIONID")
            .invalidateHttpSession(true)
            .and()
        .exceptionHandling()
            .accessDeniedPage("/denied")
            .and()
        .rememberMe()
            .key(REMEMBER_ME_KEY)
            .rememberMeServices(persistentTokenBasedRememberMeServices());
}
 
Example 4
Source Project: onetwo   Source File: CasSecurityConfigurerAdapter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
    protected void configure(HttpSecurity http) throws Exception {
		//DefaultFilterInvocationSecurityMetadataSource
//		AjaxAuthenticationHandler authHandler = new AjaxAuthenticationHandler("/login", "/plugins/permission/admin");

		casFilter.setAuthenticationManager(authenticationManager());
	    http
	    	.headers()
				.addHeaderWriter(new XFrameOptionsHeaderWriter(XFrameOptionsMode.SAMEORIGIN))
			.and()
			.exceptionHandling()
				.authenticationEntryPoint(casEntryPoint)
			.and()
//			.authenticationProvider(casAuthenticationProvider)
			.addFilter(casFilter)
	    	.authorizeRequests()
	    		.anyRequest().authenticated()//去掉会启动失败,原因未知
	    		.withObjectPostProcessor(new ObjectPostProcessor<FilterSecurityInterceptor>() {

					@Override
                    public <O extends FilterSecurityInterceptor> O postProcess(O object) {
						if(securityMetadataSourceBuilder!=null){
							securityMetadataSourceBuilder.setFilterSecurityInterceptor(object);
							securityMetadataSourceBuilder.buildSecurityMetadataSource();
						}
	                    return object;
                    }
	    			
				})
			.and()
	    	.sessionManagement()
	    		.maximumSessions(1)
	    		.maxSessionsPreventsLogin(true);
    }
 
Example 5
Source Project: ambari-logsearch   Source File: SecurityConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected void configure(HttpSecurity http) throws Exception {
  http
    .headers()
      .addHeaderWriter(
        new LogSearchCompositeHeaderWriter("https".equals(logSearchHttpConfig.getProtocol()),
          new XXssProtectionHeaderWriter(),
          new XFrameOptionsHeaderWriter(XFrameOptionsHeaderWriter.XFrameOptionsMode.DENY),
          new XContentTypeOptionsHeaderWriter(),
          new StaticHeadersWriter("Pragma", "no-cache"),
          new StaticHeadersWriter("Cache-Control", "no-store")))
    .and()
    .csrf().disable()
    .authorizeRequests()
      .requestMatchers(requestMatcher())
        .permitAll()
      .antMatchers("/**")
        .hasRole("USER")
    .and()
    .authenticationProvider(logsearchAuthenticationProvider())
    .httpBasic()
      .authenticationEntryPoint(logsearchAuthenticationEntryPoint())
    .and()
    .addFilterBefore(logsearchTrustedProxyFilter(), BasicAuthenticationFilter.class)
    .addFilterAfter(logsearchKRBAuthenticationFilter(), LogsearchTrustedProxyFilter.class)
    .addFilterBefore(logsearchUsernamePasswordAuthenticationFilter(), LogsearchKRBAuthenticationFilter.class)
    .addFilterAfter(securityContextFormationFilter(), FilterSecurityInterceptor.class)
    .addFilterAfter(logsearchMetadataFilter(), LogsearchSecurityContextFormationFilter.class)
    .addFilterAfter(logsearchAuditLogFilter(), LogsearchSecurityContextFormationFilter.class)
    .addFilterAfter(logsearchServiceLogFilter(), LogsearchSecurityContextFormationFilter.class)
    .addFilterAfter(logSearchConfigStateFilter(), LogsearchSecurityContextFormationFilter.class)
    .addFilterBefore(logsearchCorsFilter(), LogsearchSecurityContextFormationFilter.class)
    .addFilterBefore(logsearchJwtFilter(), LogsearchSecurityContextFormationFilter.class)
    .logout()
      .logoutUrl("/logout")
      .deleteCookies(getCookies())
      .logoutSuccessHandler(new LogsearchLogoutSuccessHandler());

  if ((logSearchConfigApiConfig.isSolrFilterStorage() || logSearchConfigApiConfig.isZkFilterStorage())
          && !logSearchConfigApiConfig.isConfigApiEnabled())
    http.addFilterAfter(logSearchLogLevelFilterManagerFilter(), LogsearchSecurityContextFormationFilter.class);
}
 
Example 6
Source Project: onetwo   Source File: RbacBaseSecurityConfigurerAdapter.java    License: Apache License 2.0 4 votes vote down vote up
@Override
    protected void configure(HttpSecurity http) throws Exception {
		//DefaultFilterInvocationSecurityMetadataSource
		AjaxAuthenticationHandler authHandler = new AjaxAuthenticationHandler("/login", "/plugins/permission/admin");
	    http
	    	.headers()
				.addHeaderWriter(new XFrameOptionsHeaderWriter(XFrameOptionsMode.SAMEORIGIN))
				.and()
	    	.authorizeRequests()
	    		.anyRequest().authenticated()
	    		.withObjectPostProcessor(new ObjectPostProcessor<FilterSecurityInterceptor>() {

					@Override
                    public <O extends FilterSecurityInterceptor> O postProcess(O object) {
//						object.setRejectPublicInvocations(true);
						/*if(securityMetadataSource!=null){
							object.setSecurityMetadataSource(securityMetadataSource);
						}*/
						if(securityMetadataSourceBuilder!=null){
//							object.setSecurityMetadataSource(databaseSecurityMetadataSource.convertTo(object.getSecurityMetadataSource()));
							securityMetadataSourceBuilder.setFilterSecurityInterceptor(object);
							securityMetadataSourceBuilder.buildSecurityMetadataSource();
						}
	                    return object;
                    }
	    			
				})
				.and()
			.formLogin()
	    		.loginPage("/login")
	    		.loginProcessingUrl("/dologin")
				.successHandler(authHandler)
				.failureHandler(authHandler)
	    		.and()
	    	.logout()
	    		.deleteCookies("JSESSIONID")
	    		.invalidateHttpSession(true)
	    		.and()
	    	.sessionManagement()
	    		.maximumSessions(1)
	    		.maxSessionsPreventsLogin(true);
//	    		.failureUrl("/login?loginError=1")
	    	;
    }