|
| 1 | +/* |
| 2 | + * This file is part of Hopsworks |
| 3 | + * Copyright (C) 2020, Logical Clocks AB. All rights reserved |
| 4 | + * |
| 5 | + * Hopsworks is free software: you can redistribute it and/or modify it under the terms of |
| 6 | + * the GNU Affero General Public License as published by the Free Software Foundation, |
| 7 | + * either version 3 of the License, or (at your option) any later version. |
| 8 | + * |
| 9 | + * Hopsworks is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 10 | + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 11 | + * PURPOSE. See the GNU Affero General Public License for more details. |
| 12 | + * |
| 13 | + * You should have received a copy of the GNU Affero General Public License along with this program. |
| 14 | + * If not, see <https://www.gnu.org/licenses/>. |
| 15 | + */ |
| 16 | +package io.hops.hopsworks.filters; |
| 17 | + |
| 18 | +import javax.ws.rs.container.ContainerRequestContext; |
| 19 | +import javax.ws.rs.container.ContainerResponseContext; |
| 20 | +import javax.ws.rs.container.ContainerResponseFilter; |
| 21 | +import javax.ws.rs.ext.Provider; |
| 22 | +import java.io.IOException; |
| 23 | + |
| 24 | +@Provider |
| 25 | +public class AllowCORSFilter implements ContainerResponseFilter { |
| 26 | + |
| 27 | + @Override |
| 28 | + public void filter(ContainerRequestContext request, ContainerResponseContext response) throws IOException { |
| 29 | + response.getHeaders().add("Access-Control-Allow-Origin", "*"); |
| 30 | + response.getHeaders().add("Access-Control-Allow-Headers", "origin, content-type, accept, authorization"); |
| 31 | + response.getHeaders().add("Access-Control-Expose-Headers", "authorization"); |
| 32 | + response.getHeaders().add("Access-Control-Allow-Credentials", "true"); |
| 33 | + response.getHeaders().add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, HEAD"); |
| 34 | + } |
| 35 | +} |
0 commit comments