Skip to content

Commit

Permalink
Update all samples (#764)
Browse files Browse the repository at this point in the history
  • Loading branch information
Netyyyy authored Jan 16, 2025
1 parent 8ef1cca commit f584ed3
Show file tree
Hide file tree
Showing 1,065 changed files with 3,088 additions and 61,390 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
build-with-maven:
strategy:
matrix:
java-version: ['8', '11', '17']
java-version: ['21', '17']
runs-on: ubuntu-latest
name: Build with Java ${{ matrix.java-version }}
steps:
Expand All @@ -20,9 +20,6 @@ jobs:
java-version: ${{ matrix.java-version }}
distribution: 'adopt'
cache: maven
- name: Build azure-spring-boot-samples 4.x with Maven - Java ${{ matrix.java-version }}
run: mvn -f pom.xml -P spring-cloud-azure-4.x --batch-mode --update-snapshots verify
- if: ${{ (matrix.java-version == '17') }}
name: Build azure-spring-boot-samples 5.x with Maven - ${{ matrix.java-version }}
- name: Build azure-spring-boot-samples 5.x with Maven - ${{ matrix.java-version }}
run: mvn -f pom.xml --batch-mode --update-snapshots verify

8 changes: 4 additions & 4 deletions .github/workflows/markdown-link-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ on: [push, pull_request]

jobs:
markdown-link-check:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04 #workaround https://github.com/UmbrellaDocs/action-linkspector/issues/32
steps:
- uses: actions/checkout@master
- uses: umbrelladocs/[email protected]
with:
- uses: actions/checkout@master
- uses: umbrelladocs/[email protected]
with:
reporter: github-pr-review
config_file: '.github/workflows/.linkspector.yml'
level: error
Expand Down
9 changes: 0 additions & 9 deletions CONVERT_SAMPLE_TO_USE_SPRING_BOOT_3_TEMPLATE.md

This file was deleted.

335 changes: 210 additions & 125 deletions README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,37 @@
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.azure.spring</groupId>
<artifactId>azure-spring-boot-samples</artifactId>
<version>1.0.0</version>
<relativePath>../../../pom.xml</relativePath>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.4.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<artifactId>spring-cloud-azure-starter-active-directory-b2c-resource-server</artifactId>
<groupId>com.azure.spring</groupId>
<artifactId>aad-b2c-resource-server</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>

<name>Spring-Cloud-Azure-Starter-Active-Directory-B2C Sample: Resource Server</name>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<version.spring.cloud.azure>5.19.0</version.spring.cloud.azure>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.azure.spring</groupId>
<artifactId>spring-cloud-azure-dependencies</artifactId>
<version>${version.spring.cloud.azure}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>com.azure.spring</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,31 @@

package com.azure.spring.sample.aad.b2c.security;

import com.azure.spring.cloud.autoconfigure.aad.AadJwtBearerTokenAuthenticationConverter;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
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.oauth2.server.resource.authentication.JwtAuthenticationConverter;
import org.springframework.security.oauth2.server.resource.authentication.JwtGrantedAuthoritiesConverter;
import org.springframework.security.web.SecurityFilterChain;

@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
@EnableMethodSecurity
@Configuration
public class WebSecurityConfiguration {

@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests((requests) -> requests.anyRequest().authenticated())
.oauth2ResourceServer()
.jwt()
.jwtAuthenticationConverter(new AadJwtBearerTokenAuthenticationConverter());
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
JwtAuthenticationConverter authenticationConverter = new JwtAuthenticationConverter();
JwtGrantedAuthoritiesConverter jwtGrantedAuthoritiesConverter = new JwtGrantedAuthoritiesConverter();
jwtGrantedAuthoritiesConverter.setAuthorityPrefix("APPROLE_");
authenticationConverter.setJwtGrantedAuthoritiesConverter(jwtGrantedAuthoritiesConverter);

http.authorizeHttpRequests((requests) -> requests.anyRequest().authenticated())
.oauth2ResourceServer(configure -> configure
.jwt(jwt -> jwt.jwtAuthenticationConverter(authenticationConverter)));

return http.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# In v2.0 tokens, `aud` is always the client ID of the API, while in v1.0 tokens it can be the resource URI used in the request.

spring:
http:
client:
factory: jdk
cloud:
azure:
# Properties like spring.cloud.azure.credential.client-id are global properties.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,39 @@
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.azure.spring</groupId>
<artifactId>azure-spring-boot-samples</artifactId>
<version>1.0.0</version>
<relativePath>../../../pom.xml</relativePath>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.4.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<artifactId>spring-cloud-azure-starter-active-directory-b2c-oidc</artifactId>
<groupId>com.azure.spring</groupId>
<artifactId>aad-b2c-web-application</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>

<name>Spring-Cloud-Azure-Starter-Active-Directory-B2C Sample: Web Application</name>
<description>Azure Active Directory B2C Spring Security 5 OAuth2 Integration Spring Boot Sample</description>
<url>https://github.com/Azure/azure-sdk-for-java</url>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<version.spring.cloud.azure>5.19.0</version.spring.cloud.azure>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.azure.spring</groupId>
<artifactId>spring-cloud-azure-dependencies</artifactId>
<version>${version.spring.cloud.azure}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>com.azure.spring</groupId>
Expand All @@ -41,7 +60,7 @@

<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
<artifactId>thymeleaf-extras-springsecurity6</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@

package com.azure.spring.sample.aad.b2c.security;

import com.azure.spring.cloud.autoconfigure.aadb2c.AadB2cOidcLoginConfigurer;
import com.azure.spring.cloud.autoconfigure.implementation.aadb2c.security.AadB2cOidcLoginConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
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.web.SecurityFilterChain;

@EnableWebSecurity
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
@Configuration
public class WebSecurityConfiguration {

private final AadB2cOidcLoginConfigurer configurer;

public WebSecurityConfiguration(AadB2cOidcLoginConfigurer configurer) {
this.configurer = configurer;
}

@Override
protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http.authorizeRequests()
.anyRequest().authenticated()
.and()
.apply(configurer);
// @formatter:on
@Bean
public SecurityFilterChain filterChain (HttpSecurity http) throws Exception {
http.authorizeHttpRequests((requests) -> requests.anyRequest().authenticated())
.with(configurer, c -> {});
return http.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
spring:
http:
client:
factory: jdk
cloud:
azure:
# Properties like spring.cloud.azure.credential.client-id are global properties.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Key concepts

This demo project explains the usage of the stateless authentication filter `AadAppRoleStatelessAuthenticationFilter`.
This demo project explains the usage of the stateless authentication filter `AadAppRoleStatelessAuthenticationFilter`.
This project is composed of a vue.js frontend and a simple backend with three endpoints
* `/public` (accessible by anyone)
* `/authorized` (role "UserRule" required)
Expand Down Expand Up @@ -57,7 +57,7 @@ For the test SPA provided with this example you should create the following role

After you've created the roles, go to **Microsoft Entra ID** and select **Users** to add two new users named "Admin" and "UserRule". Then back to select **Enterprise applications** in the left-hand navigation pane, click on your created application and select **Users and groups**, finally assign the new roles to your new Users (assignment of roles to groups is not available in the free tier of Microsoft Entra ID).

Furthermore enable the implicit flow in the manifest for the demo application
Furthermore, enable the implicit flow in the manifest for the demo application
(or if you have SPAs calling you):

```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,39 @@
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.azure.spring</groupId>
<artifactId>azure-spring-boot-samples</artifactId>
<version>1.0.0</version>
<relativePath>../../../pom.xml</relativePath>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.4.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<artifactId>spring-cloud-azure-starter-active-directory-resource-server-by-filter-stateless</artifactId>
<groupId>com.azure.spring</groupId>
<artifactId>aad-resource-server-by-filter-stateless</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>

<name>Spring-Cloud-Azure-Starter-Active-Directory Sample: Stateless Resource Server by Filter</name>
<description>Sample project using the Microsoft Entra ID stateless app-role filter for Microsoft Entra ID integration in Spring Security</description>
<url>https://github.com/Azure/azure-sdk-for-java</url>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<version.spring.cloud.azure>5.19.0</version.spring.cloud.azure>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.azure.spring</groupId>
<artifactId>spring-cloud-azure-dependencies</artifactId>
<version>${version.spring.cloud.azure}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>com.azure.spring</groupId>
Expand All @@ -41,5 +60,4 @@
<artifactId>spring-security-oauth2-jose</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,38 @@

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

import com.azure.spring.cloud.autoconfigure.aad.filter.AadAppRoleStatelessAuthenticationFilter;
import com.azure.spring.cloud.autoconfigure.implementation.aad.filter.AadAppRoleStatelessAuthenticationFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
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.annotation.web.configurers.CsrfConfigurer;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;

@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class AadWebSecurityConfig extends WebSecurityConfigurerAdapter {
@EnableMethodSecurity(prePostEnabled = true)
@Configuration
public class AadWebSecurityConfig {

@Autowired
private AadAppRoleStatelessAuthenticationFilter aadAuthFilter;

@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {

http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER);

http.authorizeRequests()
.antMatchers("/admin/**").hasRole("Admin")
.antMatchers("/", "/index.html", "/public").permitAll()
.anyRequest().authenticated();

http.addFilterBefore(aadAuthFilter, UsernamePasswordAuthenticationFilter.class);
http.csrf(CsrfConfigurer::disable)
.sessionManagement(configurer ->
configurer.sessionCreationPolicy(SessionCreationPolicy.NEVER))
.authorizeHttpRequests(request -> request
.requestMatchers("/admin/**").hasRole("Admin")
.requestMatchers("/", "/index.html", "/public").permitAll()
.anyRequest().authenticated())
.addFilterBefore(aadAuthFilter, UsernamePasswordAuthenticationFilter.class);

return http.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@

spring:
http:
client:
factory: jdk
cloud:
azure:
# Properties like spring.cloud.azure.credential.client-id are global properties.
Expand Down
Loading

0 comments on commit f584ed3

Please sign in to comment.