Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/material_theme_project_new.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

137 changes: 132 additions & 5 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions SecurityDemo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ dependencies {
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
implementation 'org.springframework:spring-test'

implementation 'com.amazonaws:aws-lambda-java-core:1.2.1'
implementation 'com.amazonaws:aws-lambda-java-events:3.11.2'
implementation 'org.springframework.cloud:spring-cloud-function-adapter-aws:3.2.2'
implementation 'org.springframework.cloud:spring-cloud-function-web:3.2.2'

implementation 'com.fasterxml.jackson.core:jackson-databind'

implementation 'ch.qos.logback:logback-classic'

runtimeOnly 'org.springframework.boot:spring-boot-starter-tomcat'

}

tasks.named('test') {
Expand Down
43 changes: 43 additions & 0 deletions SecurityDemo/src/main/java/com/securitydemo/LambdaHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.securitydemo;

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ConfigurableApplicationContext;

import java.util.HashMap;
import java.util.Map;

public class LambdaHandler implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {
private static ConfigurableApplicationContext applicationContext;
private static SpringApiGatewayRequestHandler requestHandler;

@Override
public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent input, Context context) {
try {
// Initialize Spring context if not already done
if (applicationContext == null) {
applicationContext = SpringApplication.run(SecurityDemoApplication.class);
requestHandler = new SpringApiGatewayRequestHandler(applicationContext);
}

// Process the request through Spring
return requestHandler.handle(input);

} catch (Exception e) {
e.printStackTrace();
APIGatewayProxyResponseEvent errorResponse = new APIGatewayProxyResponseEvent();
errorResponse.setStatusCode(500);
errorResponse.setBody("{\"error\":\"" + e.getMessage() + "\"}");

// Add only Content-Type header without CORS
Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json");
errorResponse.setHeaders(headers);

return errorResponse;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;


@SpringBootApplication
@EnableMethodSecurity
public class SecurityDemoApplication {
Expand Down
Loading