Skip to content
This repository was archived by the owner on Dec 12, 2018. It is now read-only.

Commit 476f5a4

Browse files
committed
Updated all examples and tutorials to Autowire AccountResolver rather than use AccountResolver.INSTANCE
1 parent 6d80bf1 commit 476f5a4

File tree

16 files changed

+104
-29
lines changed

16 files changed

+104
-29
lines changed

examples/spring-boot-default/src/main/java/com/stormpath/spring/boot/examples/HelloController.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public class HelloController {
3232
@Autowired
3333
private HelloService helloService;
3434

35+
@Autowired
36+
AccountResolver accountResolver;
37+
3538
@RequestMapping("/")
3639
String home(HttpServletRequest request) {
3740
return "home";
@@ -40,7 +43,7 @@ String home(HttpServletRequest request) {
4043
@RequestMapping("/restricted")
4144
String restricted(HttpServletRequest request, Model model) {
4245
String msg = helloService.sayHello(
43-
AccountResolver.INSTANCE.getAccount(request)
46+
accountResolver.getAccount(request)
4447
);
4548
model.addAttribute("msg", msg);
4649
return "restricted";

examples/spring-boot-webmvc-angular/src/main/java/com/stormpath/spring/boot/examples/ProfileController.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import com.stormpath.sdk.account.Account;
1919
import com.stormpath.sdk.servlet.account.AccountResolver;
20+
import org.springframework.beans.factory.annotation.Autowired;
2021
import org.springframework.stereotype.Controller;
2122
import org.springframework.web.bind.annotation.RequestBody;
2223
import org.springframework.web.bind.annotation.RequestMapping;
@@ -30,10 +31,13 @@
3031
@Controller
3132
public class ProfileController {
3233

34+
@Autowired
35+
AccountResolver accountResolver;
36+
3337
@RequestMapping(path = "/profile", method = POST)
3438
public void profile(HttpServletRequest req, HttpServletResponse res, @RequestBody Map<String, String> params) {
3539

36-
Account account = AccountResolver.INSTANCE.getAccount(req);
40+
Account account = accountResolver.getAccount(req);
3741

3842
if (account != null) {
3943
account.setGivenName(params.get("givenName"));

examples/spring-boot-webmvc/src/main/java/com/stormpath/spring/boot/examples/HelloController.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import com.stormpath.sdk.account.Account;
1919
import com.stormpath.sdk.servlet.account.AccountResolver;
20+
import org.springframework.beans.factory.annotation.Autowired;
2021
import org.springframework.stereotype.Controller;
2122
import org.springframework.ui.Model;
2223
import org.springframework.web.bind.annotation.RequestMapping;
@@ -26,12 +27,15 @@
2627
@Controller
2728
public class HelloController {
2829

30+
@Autowired
31+
AccountResolver accountResolver;
32+
2933
@RequestMapping("/")
3034
public String home(HttpServletRequest request, Model model) {
3135

3236
String name = "World";
3337

34-
Account account = AccountResolver.INSTANCE.getAccount(request);
38+
Account account = accountResolver.getAccount(request);
3539
if (account != null) {
3640
name = account.getGivenName();
3741
model.addAttribute(account);

examples/spring-security-spring-boot-webmvc/src/main/java/com/stormpath/spring/boot/examples/HelloController.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,15 @@ public class HelloController {
3333
@Autowired
3434
private HelloService helloService;
3535

36+
@Autowired
37+
AccountResolver accountResolver;
38+
3639
@RequestMapping("/")
3740
public String home(HttpServletRequest request, Model model) {
3841

3942
String name = "World";
4043

41-
Account account = AccountResolver.INSTANCE.getAccount(request);
44+
Account account = accountResolver.getAccount(request);
4245
if (account != null) {
4346
name = account.getGivenName();
4447
model.addAttribute(account);
@@ -51,7 +54,7 @@ public String home(HttpServletRequest request, Model model) {
5154

5255
@RequestMapping("/restricted")
5356
String restricted(HttpServletRequest request, Model model) {
54-
Account account = AccountResolver.INSTANCE.getAccount(request);
57+
Account account = accountResolver.getAccount(request);
5558
String msg = helloService.sayHello(account);
5659
model.addAttribute("msg", msg);
5760

examples/spring-security-webmvc/src/main/java/com/stormpath/spring/examples/HelloController.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,15 @@ public class HelloController {
3333
@Autowired
3434
private HelloService helloService;
3535

36+
@Autowired
37+
AccountResolver accountResolver;
38+
3639
@RequestMapping("/")
3740
ModelAndView home(HttpServletRequest request) {
3841

3942
String name = "World";
4043

41-
Account account = AccountResolver.INSTANCE.getAccount(request);
44+
Account account = accountResolver.getAccount(request);
4245
if (account != null) {
4346
name = account.getGivenName();
4447
}
@@ -50,7 +53,7 @@ ModelAndView home(HttpServletRequest request) {
5053

5154
@RequestMapping("/restricted")
5255
ModelAndView restricted(HttpServletRequest request) {
53-
String helloMessage = helloService.sayHello(AccountResolver.INSTANCE.getAccount(request));
56+
String helloMessage = helloService.sayHello(accountResolver.getAccount(request));
5457
ModelAndView mav = new ModelAndView("restricted");
5558
mav.addObject("message", helloMessage);
5659
return mav;

examples/spring-webmvc/src/main/java/com/stormpath/spring/examples/HelloController.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import com.stormpath.sdk.account.Account;
1919
import com.stormpath.sdk.servlet.account.AccountResolver;
20+
import org.springframework.beans.factory.annotation.Autowired;
2021
import org.springframework.web.bind.annotation.RequestMapping;
2122
import org.springframework.web.bind.annotation.RestController;
2223
import org.springframework.web.servlet.ModelAndView;
@@ -26,12 +27,15 @@
2627
@RestController
2728
public class HelloController {
2829

30+
@Autowired
31+
AccountResolver accountResolver;
32+
2933
@RequestMapping("/")
3034
ModelAndView home(HttpServletRequest request) {
3135

3236
String name = "World";
3337

34-
Account account = AccountResolver.INSTANCE.getAccount(request);
38+
Account account = accountResolver.getAccount(request);
3539
if (account != null) {
3640
name = account.getGivenName();
3741
}

tutorials/spring-boot/01-some-access-controls/src/main/java/com/stormpath/tutorial/controller/HelloController.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
package com.stormpath.tutorial.controller;
1717

1818
import com.stormpath.sdk.servlet.account.AccountResolver;
19+
import org.springframework.beans.factory.annotation.Autowired;
1920
import org.springframework.stereotype.Controller;
2021
import org.springframework.ui.Model;
22+
import org.springframework.util.Assert;
2123
import org.springframework.web.bind.annotation.RequestMapping;
2224

2325
import javax.servlet.http.HttpServletRequest;
@@ -28,6 +30,13 @@
2830
@Controller
2931
public class HelloController {
3032

33+
private AccountResolver accountResolver;
34+
35+
public HelloController(AccountResolver accountResolver) {
36+
Assert.notNull(accountResolver);
37+
this.accountResolver = accountResolver;
38+
}
39+
3140
@RequestMapping("/")
3241
String home(HttpServletRequest req, Model model) {
3342
model.addAttribute("status", req.getParameter("status"));
@@ -36,7 +45,7 @@ String home(HttpServletRequest req, Model model) {
3645

3746
@RequestMapping("/restricted")
3847
String restricted(HttpServletRequest req) {
39-
if (AccountResolver.INSTANCE.getAccount(req) != null) {
48+
if (accountResolver.getAccount(req) != null) {
4049
return "restricted";
4150
}
4251

tutorials/spring-boot/02-spring-security-ftw/src/main/java/com/stormpath/tutorial/controller/HelloController.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,14 @@
3131
@Controller
3232
public class HelloController {
3333

34+
private AccountResolver accountResolver;
3435
private HelloService helloService;
3536

3637
@Autowired
37-
public HelloController(HelloService helloService) {
38+
public HelloController(AccountResolver accountResolver, HelloService helloService) {
39+
Assert.notNull(accountResolver);
3840
Assert.notNull(helloService);
41+
this.accountResolver = accountResolver;
3942
this.helloService = helloService;
4043
}
4144

@@ -48,7 +51,7 @@ String home(HttpServletRequest req, Model model) {
4851
@RequestMapping("/restricted")
4952
String restricted(HttpServletRequest req, Model model) {
5053
String msg = helloService.sayHello(
51-
AccountResolver.INSTANCE.getAccount(req)
54+
accountResolver.getAccount(req)
5255
);
5356
model.addAttribute("msg", msg);
5457
return "restricted";

tutorials/spring-boot/03-spring-security-refined/src/main/java/com/stormpath/tutorial/controller/HelloController.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,14 @@
3131
@Controller
3232
public class HelloController {
3333

34+
private AccountResolver accountResolver;
3435
private HelloService helloService;
3536

3637
@Autowired
37-
public HelloController(HelloService helloService) {
38+
public HelloController(AccountResolver accountResolver, HelloService helloService) {
39+
Assert.notNull(accountResolver);
3840
Assert.notNull(helloService);
41+
this.accountResolver = accountResolver;
3942
this.helloService = helloService;
4043
}
4144

@@ -48,7 +51,7 @@ String home(HttpServletRequest req, Model model) {
4851
@RequestMapping("/restricted")
4952
String restricted(HttpServletRequest req, Model model) {
5053
String msg = helloService.sayHello(
51-
AccountResolver.INSTANCE.getAccount(req)
54+
accountResolver.getAccount(req)
5255
);
5356
model.addAttribute("msg", msg);
5457
return "restricted";

tutorials/spring-boot/04-a-finer-grain-of-control/src/main/java/com/stormpath/tutorial/controller/HelloController.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,14 @@
4040
@Controller
4141
public class HelloController {
4242

43+
private AccountResolver accountResolver;
4344
private HelloService helloService;
4445

4546
@Autowired
46-
public HelloController(HelloService helloService) {
47+
public HelloController(AccountResolver accountResolver, HelloService helloService) {
48+
Assert.notNull(accountResolver);
4749
Assert.notNull(helloService);
50+
this.accountResolver = accountResolver;
4851
this.helloService = helloService;
4952
}
5053

@@ -56,7 +59,7 @@ String home(HttpServletRequest req, Model model) {
5659

5760
@RequestMapping("/userdetails")
5861
String userDetails(HttpServletRequest req, Model model) {
59-
Account account = AccountResolver.INSTANCE.getAccount(req);
62+
Account account = accountResolver.getAccount(req);
6063
Map<String, List<String>> springSecurityPermissions = new HashMap<>();
6164

6265
// group perms
@@ -77,7 +80,7 @@ String userDetails(HttpServletRequest req, Model model) {
7780
@RequestMapping("/restricted")
7881
String restricted(HttpServletRequest req, Model model) {
7982
String msg = helloService.sayHello(
80-
AccountResolver.INSTANCE.getAccount(req)
83+
accountResolver.getAccount(req)
8184
);
8285
model.addAttribute("msg", msg);
8386
return "restricted";

0 commit comments

Comments
 (0)