Skip to content

Commit bc97cbd

Browse files
author
Dave Syer
committed
Explain the security configuration in the auth server
Fixes spring-guidesgh-16
1 parent 02aae5a commit bc97cbd

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

auth-server/README.adoc

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,30 @@ add an explicit approval step to the token grant we would need to
141141
provide a UI replacing the whitelabel version (at
142142
`/oauth/confirm_access`).
143143

144+
To finish the Authorization Server we just need to provide security
145+
configuration for its UI. In fact there isn't much of a user
146+
interface in this simple app, but we still need to protect the
147+
`/oauth/authorize` endpoint, and make sure that the home page
148+
with the "Login" buttons is visible. That's why we have this
149+
method:
150+
151+
```java
152+
@Override
153+
protected void configure(HttpSecurity http) throws Exception {
154+
http.antMatcher("/**") // <1>
155+
.authorizeRequests()
156+
.antMatchers("/", "/login**", "/webjars/**").permitAll() // <2>
157+
.anyRequest().authenticated() // <3>
158+
.and().exceptionHandling()
159+
.authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/")) // <4>
160+
...
161+
}
162+
```
163+
<1> All requests are protected by default
164+
<2> The home page and login endpoints are explicitly excluded
165+
<3> All other endpoints require an authenticated user
166+
<4> Unauthenticated users are re-directed to the home page
167+
144168
== How to Get an Access Token
145169

146170
Access tokens are now available from our new Authorization Server.
@@ -192,15 +216,15 @@ application is easy to create with Spring Boot. Here's an example:
192216
@RestController
193217
public class ClientApplication {
194218
195-
@RequestMapping("/")
196-
public String home(Principal user) {
197-
return "Hello " + user.getName();
198-
}
219+
@RequestMapping("/")
220+
public String home(Principal user) {
221+
return "Hello " + user.getName();
222+
}
199223
200-
public static void main(String[] args) {
201-
new SpringApplicationBuilder(ClientApplication.class)
202-
.properties("spring.config.name=client").run(args);
203-
}
224+
public static void main(String[] args) {
225+
new SpringApplicationBuilder(ClientApplication.class)
226+
.properties("spring.config.name=client").run(args);
227+
}
204228
205229
}
206230
----

0 commit comments

Comments
 (0)