Cleanup and fix tests
This commit is contained in:
@@ -1,11 +1,27 @@
|
||||
/*
|
||||
* Copyright 2023-2023 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 org.springframework.cloud.function.adapter.azure.helper;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.microsoft.azure.functions.HttpResponseMessage;
|
||||
import com.microsoft.azure.functions.HttpStatusType;
|
||||
import com.microsoft.azure.functions.HttpResponseMessage.Builder;
|
||||
import com.microsoft.azure.functions.HttpStatusType;
|
||||
|
||||
public class BuilderStub implements Builder {
|
||||
|
||||
@@ -36,4 +52,4 @@ public class BuilderStub implements Builder {
|
||||
return new HttpResponseMessageStub(this.status, this.headers, this.body);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2023-2023 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 org.springframework.cloud.function.adapter.azure.helper;
|
||||
|
||||
import java.net.URI;
|
||||
@@ -72,5 +88,4 @@ public class HttpRequestMessageStub<I> implements HttpRequestMessage<I> {
|
||||
public Builder createResponseBuilder(HttpStatus status) {
|
||||
return new BuilderStub().status(status);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2023-2023 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 org.springframework.cloud.function.adapter.azure.helper;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -34,4 +50,4 @@ public class HttpResponseMessageStub implements HttpResponseMessage {
|
||||
return this.body;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.microsoft.azure.functions.ExecutionContext;
|
||||
import com.microsoft.azure.functions.HttpMethod;
|
||||
import com.microsoft.azure.functions.HttpRequestMessage;
|
||||
import com.microsoft.azure.functions.annotation.AuthorizationLevel;
|
||||
import com.microsoft.azure.functions.annotation.FunctionName;
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.util.Iterator;
|
||||
import java.util.Optional;
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.function.Function;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.microsoft.azure.functions.ExecutionContext;
|
||||
import com.microsoft.azure.functions.HttpMethod;
|
||||
|
||||
@@ -217,7 +217,7 @@ public class ProxyServletContext implements ServletContext {
|
||||
|
||||
@Override
|
||||
public Map<String, ? extends ServletRegistration> getServletRegistrations() {
|
||||
throw new UnsupportedOperationException("This ServletContext does not represent a running web container");
|
||||
return this.registrations;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -72,27 +72,24 @@ public class PetStoreSpringAppConfig {
|
||||
|
||||
@Bean
|
||||
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||
http.csrf().disable() // need for POST
|
||||
.addFilterBefore(new GenericFilterBean() {
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
|
||||
throws IOException, ServletException {
|
||||
SecurityContext securityContext = SecurityContextHolder.getContext();
|
||||
securityContext.setAuthentication(UsernamePasswordAuthenticationToken.authenticated("user", "password",
|
||||
Collections.singleton(new SimpleGrantedAuthority("USER"))));
|
||||
HttpSession session = ((HttpServletRequest) request).getSession();
|
||||
session.setAttribute("SPRING_SECURITY_CONTEXT", securityContext);
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
}, SecurityContextHolderFilter.class)
|
||||
.authorizeHttpRequests((requests) -> requests
|
||||
.requestMatchers("/", "/pets", "/pets/").hasAnyAuthority("USER")
|
||||
.requestMatchers("/foo").hasAnyAuthority("FOO")
|
||||
.anyRequest().authenticated()
|
||||
http
|
||||
.addFilterBefore(new GenericFilterBean() {
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
|
||||
throws IOException, ServletException {
|
||||
SecurityContext securityContext = SecurityContextHolder.getContext();
|
||||
securityContext.setAuthentication(UsernamePasswordAuthenticationToken.authenticated("user", "password",
|
||||
Collections.singleton(new SimpleGrantedAuthority("USER"))));
|
||||
HttpSession session = ((HttpServletRequest) request).getSession();
|
||||
session.setAttribute("SPRING_SECURITY_CONTEXT", securityContext);
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
}, SecurityContextHolderFilter.class)
|
||||
.securityMatcher("/foo")
|
||||
.authorizeHttpRequests(authorize -> authorize
|
||||
.anyRequest().hasRole("FOO")
|
||||
)
|
||||
.exceptionHandling().accessDeniedHandler(accessDeniedHandler()).and()
|
||||
.logout((logout) -> logout.permitAll());
|
||||
|
||||
.exceptionHandling(f -> f.accessDeniedHandler(accessDeniedHandler()));
|
||||
return http.build();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user