-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
254a50d
commit f7fc45c
Showing
4 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/java/com/databasepreservation/common/filter/CORSFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.databasepreservation.common.filter; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import javax.ws.rs.container.ContainerRequestContext; | ||
import javax.ws.rs.container.ContainerResponseContext; | ||
import javax.ws.rs.container.ContainerResponseFilter; | ||
import javax.ws.rs.ext.Provider; | ||
|
||
import com.databasepreservation.common.server.ViewerConfiguration; | ||
|
||
@Provider | ||
public class CORSFilter implements ContainerResponseFilter { | ||
|
||
@Override | ||
public void filter(ContainerRequestContext request, ContainerResponseContext response) throws IOException { | ||
|
||
List<String> allowedOriginsList = ViewerConfiguration.getInstance() | ||
.getViewerConfigurationAsList(ViewerConfiguration.CORS_ALLOW_ORIGIN); | ||
String requestOrigin = request.getHeaderString("Origin"); | ||
|
||
if (allowedOriginsList.contains(requestOrigin)) { | ||
response.getHeaders().add("Access-Control-Allow-Origin", requestOrigin); | ||
} | ||
response.getHeaders().add("Access-Control-Allow-Headers", | ||
ViewerConfiguration.getInstance().getViewerConfigurationAsString("", ViewerConfiguration.CORS_ALLOW_HEADERS)); | ||
response.getHeaders().add("Access-Control-Allow-Credentials", ViewerConfiguration.getInstance() | ||
.getViewerConfigurationAsString("false", ViewerConfiguration.CORS_ALLOW_CREDENTIALS)); | ||
response.getHeaders().add("Access-Control-Allow-Methods", | ||
ViewerConfiguration.getInstance().getViewerConfigurationAsString("", ViewerConfiguration.CORS_ALLOW_METHODS)); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters