Skip to content

Commit 8c49685

Browse files
author
Dave Syer
committed
Add click link to Facebook
1 parent 956581c commit 8c49685

File tree

3 files changed

+56
-13
lines changed

3 files changed

+56
-13
lines changed

src/main/java/com/example/SocialApplication.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,31 @@
1515
*/
1616
package com.example;
1717

18+
import java.security.Principal;
19+
1820
import org.springframework.boot.SpringApplication;
1921
import org.springframework.boot.autoconfigure.SpringBootApplication;
2022
import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso;
23+
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
24+
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
25+
import org.springframework.web.bind.annotation.RequestMapping;
26+
import org.springframework.web.bind.annotation.RestController;
2127

2228
@SpringBootApplication
2329
@EnableOAuth2Sso
24-
public class SocialApplication {
30+
@RestController
31+
public class SocialApplication extends WebSecurityConfigurerAdapter {
32+
33+
@RequestMapping("/user")
34+
public Principal user(Principal principal) {
35+
return principal;
36+
}
37+
38+
@Override
39+
protected void configure(HttpSecurity http) throws Exception {
40+
http.antMatcher("/**").authorizeRequests().antMatchers("/", "/login**", "/webjars/**").permitAll().anyRequest()
41+
.authenticated();
42+
}
2543

2644
public static void main(String[] args) {
2745
SpringApplication.run(SocialApplication.class, args);

src/main/resources/application.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ security:
1010
clientAuthenticationScheme: form
1111
resource:
1212
userInfoUri: https://graph.facebook.com/me
13+
14+
logging:
15+
level:
16+
org.springframework.security: DEBUG
17+
1318
spring:
1419
resources:
1520
chain:
Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,38 @@
11
<!doctype html>
22
<html lang="en">
33
<head>
4-
<meta charset="utf-8"/>
5-
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
6-
<title>Demo</title>
7-
<meta name="description" content=""/>
8-
<meta name="viewport" content="width=device-width"/>
9-
<base href="/"/>
10-
<link rel="stylesheet" type="text/css" href="/webjars/bootstrap/css/bootstrap.min.css"/>
11-
<script type="text/javascript" src="/webjars/jquery/jquery.min.js"></script>
12-
<script type="text/javascript" src="/webjars/bootstrap/js/bootstrap.min.js"></script>
4+
<meta charset="utf-8" />
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
6+
<title>Demo</title>
7+
<meta name="description" content="" />
8+
<meta name="viewport" content="width=device-width" />
9+
<base href="/" />
10+
<link rel="stylesheet" type="text/css"
11+
href="/webjars/bootstrap/css/bootstrap.min.css" />
12+
<script type="text/javascript" src="/webjars/jquery/jquery.min.js"></script>
13+
<script type="text/javascript"
14+
src="/webjars/bootstrap/js/bootstrap.min.js"></script>
1315
</head>
14-
<body>
15-
<h1>Demo</h1>
16-
<div class="container"></div>
16+
<body ng-app="app" ng-controller="home as home">
17+
<h1>Login</h1>
18+
<div class="container" ng-show="!home.authenticated">
19+
With Facebook: <a href="/login">click here</a>
20+
</div>
21+
<div class="container" ng-show="home.authenticated">
22+
Logged in as: <span ng-bind="home.user"></span>
23+
</div>
24+
<script type="text/javascript" src="/webjars/angularjs/angular.min.js"></script>
25+
<script type="text/javascript">
26+
angular.module("app", []).controller("home", function($http) {
27+
var self = this;
28+
$http.get("/user").success(function(data) {
29+
self.user = data.userAuthentication.details.name;
30+
self.authenticated = true;
31+
}).error(function() {
32+
self.user = "N/A";
33+
self.authenticated = false;
34+
});
35+
});
36+
</script>
1737
</body>
1838
</html>

0 commit comments

Comments
 (0)