diff --git a/azure-spring-boot-samples/azure-active-directory-spring-boot-app-role-sample/README.md b/azure-spring-boot-samples/azure-active-directory-spring-boot-app-role-sample/README.md deleted file mode 100644 index 67ba3bcde..000000000 --- a/azure-spring-boot-samples/azure-active-directory-spring-boot-app-role-sample/README.md +++ /dev/null @@ -1,82 +0,0 @@ -### How to configure - -#### Register your application with your Azure Active Directory Tenant - -Follow the guide [here](https://docs.microsoft.com/en-us/azure/active-directory/develop/v1-protocols-openid-connect-code#register-your-application-with-your-ad-tenant). - -#### Configure appRoles - -In order to use only the `id_token` for our authentication and authorization purposes we will use the -`appRoles` feature which AAD provides. Follow the guide -[Add app roles in your application](https://docs.microsoft.com/en-us/azure/active-directory/develop/howto-add-app-roles-in-azure-ad-apps) - -For the test SPA provided with this example you should create the following roles in your manifest: - -``` - "appRoles": [ - { - "allowedMemberTypes": [ - "User" - ], - "displayName": "Admin", - "id": "2fa848d0-8054-4e11-8c73-7af5f1171001", - "isEnabled": true, - "description": "Full admin access", - "value": "Admin" - }, - { - "allowedMemberTypes": [ - "User" - ], - "displayName": "User", - "id": "f8ed78b5-fabc-488e-968b-baa48a570001", - "isEnabled": true, - "description": "Normal user access", - "value": "User" - } - ], -``` - -After you've created the roles go to your Enterprise Application, select "Users and groups" and -assign the new roles to your Users (assignment to groups is not available in the free AAD). - -Furthermore enable the implicit flow in the manifest for the demo application -(or if you have SPAs calling you): -``` -"oauth2AllowImplicitFlow": "true", -``` - -#### Configure application.properties - -You have to configure the `client-id`of your application registration: - -```properties -azure.aad.app-role.client-id=xxxxxx-your-client-id-xxxxxx -``` - -### How to run - - - Use Maven - - ``` - # Under azure-spring-boot project root directory - mvn clean install -DskipTests - cd azure-spring-boot-samples - cd azure-active-directory-spring-boot-backend-stateless-sample - mvn spring-boot:run - ``` - -### Check the authentication and authorization - -1. Access http://localhost:8080 -2. Without logging in try the three endpoints (public, authorized and admin). While the public - endpoint should work without a token the other two will return a 403. -3. Insert your `client-id` and `tenant-id` and perform a log in. If successfull the token textarea - should get populated. Also the token header and token payload field will be populated. -4. Again access the three endpoints. Depending on your user and the assigned `appRoles` you should - be able to call the authorized and admin endpoints. - -#### Demo -![demoonstration video](docs/demo.webp "Demo Video") - - diff --git a/azure-spring-boot-samples/azure-active-directory-spring-boot-app-role-sample/docs/demo.webp b/azure-spring-boot-samples/azure-active-directory-spring-boot-app-role-sample/docs/demo.webp deleted file mode 100644 index 881e819fb..000000000 Binary files a/azure-spring-boot-samples/azure-active-directory-spring-boot-app-role-sample/docs/demo.webp and /dev/null differ diff --git a/azure-spring-boot-samples/azure-active-directory-spring-boot-app-role-sample/pom.xml b/azure-spring-boot-samples/azure-active-directory-spring-boot-app-role-sample/pom.xml deleted file mode 100644 index 7d8c05428..000000000 --- a/azure-spring-boot-samples/azure-active-directory-spring-boot-app-role-sample/pom.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - - azure-spring-boot-samples - com.microsoft.azure - 0.0.1-SNAPSHOT - - 4.0.0 - - azure-active-directory-spring-boot-app-role-sample - - - - com.microsoft.azure - azure-active-directory-spring-boot-starter - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-starter-security - - - - org.springframework.security - spring-security-oauth2-client - - - org.springframework.security - spring-security-oauth2-jose - - - - - ${project.basedir}/../.. - - - \ No newline at end of file diff --git a/azure-spring-boot-samples/azure-active-directory-spring-boot-app-role-sample/src/main/java/sample/aad/AzureADStatelessBackendSampleApplication.java b/azure-spring-boot-samples/azure-active-directory-spring-boot-app-role-sample/src/main/java/sample/aad/AzureADStatelessBackendSampleApplication.java deleted file mode 100644 index 32c3dec53..000000000 --- a/azure-spring-boot-samples/azure-active-directory-spring-boot-app-role-sample/src/main/java/sample/aad/AzureADStatelessBackendSampleApplication.java +++ /dev/null @@ -1,17 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package sample.aad; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class AzureADStatelessBackendSampleApplication { - - public static void main(String[] args) { - SpringApplication.run(AzureADStatelessBackendSampleApplication.class, args); - } -} diff --git a/azure-spring-boot-samples/azure-active-directory-spring-boot-app-role-sample/src/main/java/sample/aad/controller/MainController.java b/azure-spring-boot-samples/azure-active-directory-spring-boot-app-role-sample/src/main/java/sample/aad/controller/MainController.java deleted file mode 100644 index cd018a333..000000000 --- a/azure-spring-boot-samples/azure-active-directory-spring-boot-app-role-sample/src/main/java/sample/aad/controller/MainController.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package sample.aad.controller; - -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class MainController { - - @GetMapping("/public") - @ResponseBody - public String publicMethod() { - return "public endpoint response"; - } - - @GetMapping("/authorized") - @ResponseBody - @PreAuthorize("hasRole('ROLE_User')") - public String onlyAuthorizedUsers() { - return "authorized endpoint response"; - } - - @GetMapping("/admin/demo") - @ResponseBody - //For this endpoint we configure the required role in the AADWebSecurityConfig class. - // However it is advisable to use method level security with "@PreAuthorize( hasRole(" - public String onlyForAdmins() { - return "admin endpoint"; - } -} diff --git a/azure-spring-boot-samples/azure-active-directory-spring-boot-app-role-sample/src/main/java/sample/aad/security/AADWebSecurityConfig.java b/azure-spring-boot-samples/azure-active-directory-spring-boot-app-role-sample/src/main/java/sample/aad/security/AADWebSecurityConfig.java deleted file mode 100644 index 8829ac548..000000000 --- a/azure-spring-boot-samples/azure-active-directory-spring-boot-app-role-sample/src/main/java/sample/aad/security/AADWebSecurityConfig.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package sample.aad.security; - -import com.microsoft.azure.spring.autoconfigure.aad.AADAppRoleAuthenticationFilter; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; -import org.springframework.security.config.http.SessionCreationPolicy; -import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; - -@EnableWebSecurity -@EnableGlobalMethodSecurity(prePostEnabled = true) -public class AADWebSecurityConfig extends WebSecurityConfigurerAdapter { - - @Autowired - private AADAppRoleAuthenticationFilter aadAuthFilter; - - @Override - protected void configure(HttpSecurity http) throws Exception { - http.csrf().disable(); - - http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER); - - http.authorizeRequests() - .antMatchers("/admin/**").hasRole("Admin") - .antMatchers("/", "/index.html", "/public").permitAll() - .anyRequest().authenticated(); - - http.addFilterBefore(aadAuthFilter, UsernamePasswordAuthenticationFilter.class); - - } -} diff --git a/azure-spring-boot-samples/azure-active-directory-spring-boot-app-role-sample/src/main/resources/application.properties b/azure-spring-boot-samples/azure-active-directory-spring-boot-app-role-sample/src/main/resources/application.properties deleted file mode 100644 index b030b9f7d..000000000 --- a/azure-spring-boot-samples/azure-active-directory-spring-boot-app-role-sample/src/main/resources/application.properties +++ /dev/null @@ -1,5 +0,0 @@ -# By default, azure.activedirectory.environment property has value `global`, -# supported value is global, cn. Please refer to the README for details. -# azure.activedirectory.environment=global -azure.aad.app-role.client-id=xxxxxx-your-client-id-xxxxxx - diff --git a/azure-spring-boot-samples/azure-active-directory-spring-boot-app-role-sample/src/main/resources/static/index.html b/azure-spring-boot-samples/azure-active-directory-spring-boot-app-role-sample/src/main/resources/static/index.html deleted file mode 100644 index f3dc96763..000000000 --- a/azure-spring-boot-samples/azure-active-directory-spring-boot-app-role-sample/src/main/resources/static/index.html +++ /dev/null @@ -1,152 +0,0 @@ - - - - - - - - - - Stateless Backend Demo - - -
- -
-
- - - - - - Login - Logout -
-
- - -
-
- - - - -
-
- - - -
-
- -
-
- -
- - - - - - - - - - \ No newline at end of file