|
3 | 3 | import com.kakawait.spring.boot.security.cas.autoconfigure.CasHttpSecurityConfigurer;
|
4 | 4 | import com.kakawait.spring.boot.security.cas.autoconfigure.CasSecurityCondition;
|
5 | 5 | import com.kakawait.spring.boot.security.cas.autoconfigure.CasSecurityConfigurerAdapter;
|
| 6 | +import com.kakawait.spring.boot.security.cas.autoconfigure.CasSecurityProperties; |
6 | 7 | import com.kakawait.spring.security.cas.client.CasAuthorizationInterceptor;
|
7 | 8 | import com.kakawait.spring.security.cas.client.ticket.ProxyTicketProvider;
|
8 | 9 | import com.kakawait.spring.security.cas.client.validation.AssertionProvider;
|
|
16 | 17 | import org.springframework.context.annotation.Configuration;
|
17 | 18 | import org.springframework.context.annotation.Profile;
|
18 | 19 | import org.springframework.core.Ordered;
|
| 20 | +import org.springframework.core.annotation.Order; |
19 | 21 | import org.springframework.http.HttpStatus;
|
20 | 22 | import org.springframework.security.access.annotation.Secured;
|
21 | 23 | import org.springframework.security.authentication.AuthenticationManager;
|
|
25 | 27 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
26 | 28 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
27 | 29 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
| 30 | +import org.springframework.security.config.annotation.web.builders.WebSecurity; |
28 | 31 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
29 | 32 | import org.springframework.security.core.Authentication;
|
30 | 33 | import org.springframework.security.web.authentication.HttpStatusEntryPoint;
|
@@ -77,6 +80,37 @@ RestTemplate casRestTemplate(ServiceProperties serviceProperties, ProxyTicketPro
|
77 | 80 | return restTemplate;
|
78 | 81 | }
|
79 | 82 |
|
| 83 | + @Configuration |
| 84 | + @Order(CasSecurityProperties.CAS_AUTH_ORDER + 1) |
| 85 | + static class SecurityConfiguration extends WebSecurityConfigurerAdapter { |
| 86 | + |
| 87 | + /** |
| 88 | + * Ignoring path by completely remove security filter on /ignored endpoint. |
| 89 | + * That method should be use when you really need security/authentication. |
| 90 | + * For example for resources/static endpoints |
| 91 | + * <p> |
| 92 | + * If you would just like to {@code permitAll()} an endpoint you should instead check |
| 93 | + * {@see OverrideDefaultCasSecurity#configure} method. |
| 94 | + */ |
| 95 | + @Override |
| 96 | + public void configure(WebSecurity web) { |
| 97 | + web.ignoring().antMatchers("/ignored"); |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + @Configuration |
| 102 | + @Conditional(CasSecurityCondition.class) |
| 103 | + static class OverrideDefaultCasSecurity extends CasSecurityConfigurerAdapter { |
| 104 | + |
| 105 | + /** |
| 106 | + * Permit all an specific endpoint |
| 107 | + */ |
| 108 | + @Override |
| 109 | + public void configure(HttpSecurity http) throws Exception { |
| 110 | + http.authorizeRequests().antMatchers("/permit-all").permitAll(); |
| 111 | + } |
| 112 | + } |
| 113 | + |
80 | 114 | @Profile("!custom-logout")
|
81 | 115 | @Configuration
|
82 | 116 | @Conditional(CasSecurityCondition.class)
|
@@ -139,6 +173,7 @@ public void configure(HttpSecurity http) throws Exception {
|
139 | 173 | @Profile("custom-logout")
|
140 | 174 | @Configuration
|
141 | 175 | static class WebMvcConfiguration implements WebMvcConfigurer {
|
| 176 | + |
142 | 177 | @Override
|
143 | 178 | public void addViewControllers(ViewControllerRegistry registry) {
|
144 | 179 | registry.addViewController("/logout.html").setViewName("logout");
|
@@ -232,6 +267,11 @@ public String hello(Authentication authentication, Model model) {
|
232 | 267 | return casRestTemplate.getForEntity("http://httpbin.org/get", String.class).getBody();
|
233 | 268 | }
|
234 | 269 |
|
| 270 | + @RequestMapping(path = "/permit-all") |
| 271 | + public String permitAll() { |
| 272 | + return "index"; |
| 273 | + } |
| 274 | + |
235 | 275 | @RequestMapping(path = "/ignored")
|
236 | 276 | public String ignored() {
|
237 | 277 | return "index";
|
|
0 commit comments