Skip to content

Commit

Permalink
Make 'azure-spring-boot-sample-active-directory-backend-v2' work well…
Browse files Browse the repository at this point in the history
… in new aad implementation. (#17821)

* Make 'azure-spring-boot-sample-active-directory-backend' and 'xxx-backedn-v2' work well in new aad implementation.
  • Loading branch information
Rujun Chen authored Nov 26, 2020
1 parent 57deafa commit 800d7e8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@

package com.azure.spring.sample.aad.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.oauth2.client.OAuth2AuthorizedClient;
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientService;
import org.springframework.security.oauth2.client.annotation.RegisteredOAuth2AuthorizedClient;
import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
Expand All @@ -15,8 +14,6 @@

@Controller
public class HomeController {
@Autowired
private OAuth2AuthorizedClientService authorizedClientService;

@GetMapping("group1")
@ResponseBody
Expand All @@ -33,11 +30,11 @@ public String group2() {
}

@GetMapping("/")
public String index(Model model, OAuth2AuthenticationToken authentication) {
final OAuth2AuthorizedClient authorizedClient =
this.authorizedClientService.loadAuthorizedClient(
authentication.getAuthorizedClientRegistrationId(),
authentication.getName());
public String index(
Model model,
OAuth2AuthenticationToken authentication,
@RegisteredOAuth2AuthorizedClient OAuth2AuthorizedClient authorizedClient
) {
model.addAttribute("userName", authentication.getName());
model.addAttribute("clientName", authorizedClient.getClientRegistration().getClientName());
return "index";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@

package com.azure.spring.sample.aad.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.oauth2.client.OAuth2AuthorizedClient;
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientService;
import org.springframework.security.oauth2.client.annotation.RegisteredOAuth2AuthorizedClient;
import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
Expand All @@ -17,8 +16,6 @@
@ConditionalOnProperty(prefix = "azure.activedirectory", value = "tenant-id")
@Controller
public class HomeController {
@Autowired
private OAuth2AuthorizedClientService authorizedClientService;

@GetMapping("group1")
@ResponseBody
Expand All @@ -35,11 +32,11 @@ public String group2() {
}

@GetMapping("/")
public String index(Model model, OAuth2AuthenticationToken authentication) {
final OAuth2AuthorizedClient authorizedClient =
this.authorizedClientService.loadAuthorizedClient(
authentication.getAuthorizedClientRegistrationId(),
authentication.getName());
public String index(
Model model,
OAuth2AuthenticationToken authentication,
@RegisteredOAuth2AuthorizedClient OAuth2AuthorizedClient authorizedClient
) {
model.addAttribute("userName", authentication.getName());
model.addAttribute("clientName", authorizedClient.getClientRegistration().getClientName());
return "index";
Expand Down

0 comments on commit 800d7e8

Please sign in to comment.