diff --git a/samples/webflux-security/src/main/java/io/spring/sample/graphql/Employee.java b/samples/webflux-security/src/main/java/io/spring/sample/graphql/Employee.java index 0737dada..d447d80c 100644 --- a/samples/webflux-security/src/main/java/io/spring/sample/graphql/Employee.java +++ b/samples/webflux-security/src/main/java/io/spring/sample/graphql/Employee.java @@ -1,3 +1,18 @@ +/* + * Copyright 2002-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package io.spring.sample.graphql; public class Employee { diff --git a/samples/webflux-security/src/main/java/io/spring/sample/graphql/EmployeeService.java b/samples/webflux-security/src/main/java/io/spring/sample/graphql/EmployeeService.java index b131f583..4d9d46b3 100644 --- a/samples/webflux-security/src/main/java/io/spring/sample/graphql/EmployeeService.java +++ b/samples/webflux-security/src/main/java/io/spring/sample/graphql/EmployeeService.java @@ -1,3 +1,18 @@ +/* + * Copyright 2002-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package io.spring.sample.graphql; import java.util.Arrays; diff --git a/samples/webflux-security/src/main/java/io/spring/sample/graphql/SalaryService.java b/samples/webflux-security/src/main/java/io/spring/sample/graphql/SalaryService.java index 7cd9fb36..358d3191 100644 --- a/samples/webflux-security/src/main/java/io/spring/sample/graphql/SalaryService.java +++ b/samples/webflux-security/src/main/java/io/spring/sample/graphql/SalaryService.java @@ -1,3 +1,18 @@ +/* + * Copyright 2002-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package io.spring.sample.graphql; import java.math.BigDecimal; @@ -19,6 +34,7 @@ public class SalaryService { @Secured({ "ROLE_HR" }) public void updateSalary(String employeeId, BigDecimal newSalary) { - + // empty } + } diff --git a/samples/webflux-security/src/main/java/io/spring/sample/graphql/SampleApplication.java b/samples/webflux-security/src/main/java/io/spring/sample/graphql/SampleApplication.java index 19225fa6..a86bf68c 100644 --- a/samples/webflux-security/src/main/java/io/spring/sample/graphql/SampleApplication.java +++ b/samples/webflux-security/src/main/java/io/spring/sample/graphql/SampleApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/samples/webflux-security/src/main/java/io/spring/sample/graphql/SampleWiring.java b/samples/webflux-security/src/main/java/io/spring/sample/graphql/SampleWiring.java index e08d2709..d8da884f 100644 --- a/samples/webflux-security/src/main/java/io/spring/sample/graphql/SampleWiring.java +++ b/samples/webflux-security/src/main/java/io/spring/sample/graphql/SampleWiring.java @@ -1,3 +1,18 @@ +/* + * Copyright 2002-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package io.spring.sample.graphql; import java.math.BigDecimal; @@ -23,23 +38,18 @@ public class SampleWiring implements RuntimeWiringCustomizer { @Override public void customize(RuntimeWiring.Builder builder) { - builder.type("Query", wiringBuilder -> - wiringBuilder.dataFetcher("employees", env -> - employeeService.getAllEmployees() - ) + builder.type("Query", wiring -> + wiring.dataFetcher("employees", env -> this.employeeService.getAllEmployees()) ); - builder.type("Employee", wiringBuilder -> - wiringBuilder.dataFetcher("salary", env -> { - Employee employee = env.getSource(); - return salaryService.getSalaryForEmployee(employee); - }) + builder.type("Employee", wiring -> + wiring.dataFetcher("salary", env -> this.salaryService.getSalaryForEmployee(env.getSource())) ); - builder.type("Mutation", wiringBuilder -> - wiringBuilder.dataFetcher("updateSalary", env -> { + builder.type("Mutation", wiring -> + wiring.dataFetcher("updateSalary", env -> { Map input = env.getArgument("input"); String employeeId = input.get("employeeId"); BigDecimal newSalary = new BigDecimal(input.get("salary")); - salaryService.updateSalary(employeeId, newSalary); + this.salaryService.updateSalary(employeeId, newSalary); return null; }) ); diff --git a/samples/webflux-security/src/main/java/io/spring/sample/graphql/SecurityConfig.java b/samples/webflux-security/src/main/java/io/spring/sample/graphql/SecurityConfig.java index 145b6ea1..9fc1ca75 100644 --- a/samples/webflux-security/src/main/java/io/spring/sample/graphql/SecurityConfig.java +++ b/samples/webflux-security/src/main/java/io/spring/sample/graphql/SecurityConfig.java @@ -1,3 +1,18 @@ +/* + * Copyright 2002-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package io.spring.sample.graphql; import org.springframework.context.annotation.Bean; @@ -20,17 +35,16 @@ public class SecurityConfig { @Bean SecurityWebFilterChain springWebFilterChain(ServerHttpSecurity http) throws Exception { return http - .csrf(c -> c.disable()) + .csrf(spec -> spec.disable()) // Demonstrate that method security works // Best practice to use both for defense in depth - .authorizeExchange(requests -> requests - .anyExchange().permitAll() - ) + .authorizeExchange(requests -> requests.anyExchange().permitAll()) .httpBasic(withDefaults()) .build(); } @Bean + @SuppressWarnings("deprecation") public MapReactiveUserDetailsService userDetailsService() { User.UserBuilder userBuilder = User.withDefaultPasswordEncoder(); UserDetails rob = userBuilder.username("rob").password("rob").roles("USER").build(); diff --git a/samples/webflux-security/src/main/java/io/spring/sample/graphql/SecurityDataFetcherExceptionResolver.java b/samples/webflux-security/src/main/java/io/spring/sample/graphql/SecurityDataFetcherExceptionResolver.java index b57ee5a3..a77fb36e 100644 --- a/samples/webflux-security/src/main/java/io/spring/sample/graphql/SecurityDataFetcherExceptionResolver.java +++ b/samples/webflux-security/src/main/java/io/spring/sample/graphql/SecurityDataFetcherExceptionResolver.java @@ -1,6 +1,22 @@ +/* + * Copyright 2002-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package io.spring.sample.graphql; import java.util.Arrays; +import java.util.Collections; import java.util.List; import graphql.GraphQLError; @@ -47,7 +63,7 @@ public class SecurityDataFetcherExceptionResolver implements DataFetcherExceptio } private Mono> unauthorized(DataFetchingEnvironment environment) { - return Mono.fromCallable(() -> Arrays.asList( + return Mono.fromCallable(() -> Collections.singletonList( GraphqlErrorBuilder.newError(environment) .errorType(ErrorType.UNAUTHORIZED) .message("Unauthorized") @@ -55,7 +71,7 @@ public class SecurityDataFetcherExceptionResolver implements DataFetcherExceptio } private Mono> forbidden(DataFetchingEnvironment environment) { - return Mono.fromCallable(() -> Arrays.asList( + return Mono.fromCallable(() -> Collections.singletonList( GraphqlErrorBuilder.newError(environment) .errorType(ErrorType.FORBIDDEN) .message("Forbidden") diff --git a/samples/webflux-security/src/test/java/io/spring/sample/graphql/SampleApplicationTests.java b/samples/webflux-security/src/test/java/io/spring/sample/graphql/SampleApplicationTests.java index b3cd3bb5..325e9cd0 100644 --- a/samples/webflux-security/src/test/java/io/spring/sample/graphql/SampleApplicationTests.java +++ b/samples/webflux-security/src/test/java/io/spring/sample/graphql/SampleApplicationTests.java @@ -1,3 +1,18 @@ +/* + * Copyright 2002-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package io.spring.sample.graphql; import java.util.Collections;