org.springframework.security.config.annotation.SecurityConfigurer Java Examples
The following examples show how to use
org.springframework.security.config.annotation.SecurityConfigurer.
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 File: SecurityConfiguration.java From spring-security-saml-dsl with MIT License | 5 votes |
@Override protected void configure(HttpSecurity http) throws Exception { SecurityConfigurer securityConfigurerAdapter = saml() .identityProvider() .metadataFilePath(metadataPath) .and() .serviceProvider() .keyStore() .storeFilePath("saml/keystore.jks") .password("secret") .keyname("spring") .keyPassword("secret") .and() .protocol("https") .hostname("localhost:8443") .basePath("/") .entityId("com:example") .and(); http.apply(securityConfigurerAdapter); http .requiresChannel() .anyRequest().requiresSecure(); http .authorizeRequests() .antMatchers("/saml/**").permitAll() .antMatchers("/health").permitAll() .antMatchers("/error").permitAll() .anyRequest().authenticated(); }
Example #2
Source File: LdapAuthenticationProvider.java From gravitee-management-rest-api with Apache License 2.0 | 5 votes |
@Override public SecurityConfigurer configure() throws Exception { LOGGER.info("Configuring an LDAP Identity Provider"); LdapAuthenticationProviderConfigurer<AuthenticationManagerBuilder> ldapAuthenticationProviderConfigurer = new LdapAuthenticationProviderConfigurer<>(); // Create LDAP context DefaultSpringSecurityContextSource contextSource = new DefaultSpringSecurityContextSource( environment.getProperty("context.url")); contextSource.setBase(environment.getProperty("context.base")); contextSource.setUserDn(environment.getProperty("context.username")); contextSource.setPassword(environment.getProperty("context.password")); contextSource.afterPropertiesSet(); ldapAuthenticationProviderConfigurer .userSearchBase(environment.getProperty("authentication.user.base", "")) .userSearchFilter(environment.getProperty("authentication.user.filter")) .groupSearchBase(environment.getProperty("authentication.group.base", "")) .groupSearchFilter(environment.getProperty("authentication.group.filter", "(uniqueMember={0})")) .groupRoleAttribute(environment.getProperty("authentication.group.role.attribute", "cn")) .rolePrefix(""); DefaultLdapAuthoritiesPopulator populator = new DefaultLdapAuthoritiesPopulator(contextSource, environment.getProperty("authentication.group.base", "")); populator.setRolePrefix(""); populator.setGroupRoleAttribute(environment.getProperty("authentication.group.role.attribute", "cn")); populator.setGroupSearchFilter(environment.getProperty("authentication.group.filter", "(uniqueMember={0})")); ldapAuthenticationProviderConfigurer.ldapAuthoritiesPopulator(populator).contextSource(contextSource); // set up LDAP mapper UserDetailsContextPropertiesMapper userDetailsContextPropertiesMapper = new UserDetailsContextPropertiesMapper(); userDetailsContextPropertiesMapper.setEnvironment(environment); userDetailsContextPropertiesMapper.afterPropertiesSet(); ldapAuthenticationProviderConfigurer.userDetailsContextMapper(userDetailsContextPropertiesMapper); return ldapAuthenticationProviderConfigurer; }
Example #3
Source File: Application.java From boot-examples with Apache License 2.0 | 5 votes |
@Override protected void configure(HttpSecurity http) throws Exception { http.csrf().disable(); http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS); String[] restEndpointsToSecure = { "news"}; for (String endpoint : restEndpointsToSecure) { http.authorizeRequests().antMatchers("/" + endpoint + "/**").hasRole(CustomUserDetailsService.ROLE_USER); } SecurityConfigurer<DefaultSecurityFilterChain, HttpSecurity> securityConfigurerAdapter = new XAuthTokenConfigurer(userDetailsServiceBean()); http.apply(securityConfigurerAdapter); }