Merge changes I11562ab1,Id0671530,I51265bdd
* changes: Allow additional cookies during xd requests Always setLastLoginExternalIdKey for IdentifiedUsers Remove duplicate Vary: Access-Control-Request header
This commit is contained in:
@@ -212,6 +212,11 @@ public class CorsIT extends AbstractDaemonTest {
|
|||||||
Header allowOrigin = r.getFirstHeader(ACCESS_CONTROL_ALLOW_ORIGIN);
|
Header allowOrigin = r.getFirstHeader(ACCESS_CONTROL_ALLOW_ORIGIN);
|
||||||
assertThat(allowOrigin).named(ACCESS_CONTROL_ALLOW_ORIGIN).isNotNull();
|
assertThat(allowOrigin).named(ACCESS_CONTROL_ALLOW_ORIGIN).isNotNull();
|
||||||
assertThat(allowOrigin.getValue()).named(ACCESS_CONTROL_ALLOW_ORIGIN).isEqualTo(origin);
|
assertThat(allowOrigin.getValue()).named(ACCESS_CONTROL_ALLOW_ORIGIN).isEqualTo(origin);
|
||||||
|
|
||||||
|
Header allowAuth = r.getFirstHeader(ACCESS_CONTROL_ALLOW_CREDENTIALS);
|
||||||
|
assertThat(allowAuth).named(ACCESS_CONTROL_ALLOW_CREDENTIALS).isNotNull();
|
||||||
|
assertThat(allowAuth.getValue()).named(ACCESS_CONTROL_ALLOW_CREDENTIALS).isEqualTo("true");
|
||||||
|
|
||||||
checkTopic(change, "test-xd");
|
checkTopic(change, "test-xd");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -554,6 +554,7 @@ public class RestApiServlet extends HttpServlet {
|
|||||||
}
|
}
|
||||||
res.addHeader(VARY, ORIGIN);
|
res.addHeader(VARY, ORIGIN);
|
||||||
res.setHeader(ACCESS_CONTROL_ALLOW_ORIGIN, origin);
|
res.setHeader(ACCESS_CONTROL_ALLOW_ORIGIN, origin);
|
||||||
|
res.setHeader(ACCESS_CONTROL_ALLOW_CREDENTIALS, "true");
|
||||||
} else if (!Strings.isNullOrEmpty(origin)) {
|
} else if (!Strings.isNullOrEmpty(origin)) {
|
||||||
// All other requests must be processed, but conditionally set CORS headers.
|
// All other requests must be processed, but conditionally set CORS headers.
|
||||||
if (globals.allowOrigin != null) {
|
if (globals.allowOrigin != null) {
|
||||||
@@ -591,7 +592,6 @@ public class RestApiServlet extends HttpServlet {
|
|||||||
|
|
||||||
String headers = req.getHeader(ACCESS_CONTROL_REQUEST_HEADERS);
|
String headers = req.getHeader(ACCESS_CONTROL_REQUEST_HEADERS);
|
||||||
if (headers != null) {
|
if (headers != null) {
|
||||||
res.addHeader(VARY, ACCESS_CONTROL_REQUEST_HEADERS);
|
|
||||||
for (String reqHdr : Splitter.on(',').trimResults().split(headers)) {
|
for (String reqHdr : Splitter.on(',').trimResults().split(headers)) {
|
||||||
if (!ALLOWED_CORS_REQUEST_HEADERS.contains(reqHdr.toLowerCase(Locale.US))) {
|
if (!ALLOWED_CORS_REQUEST_HEADERS.contains(reqHdr.toLowerCase(Locale.US))) {
|
||||||
throw new BadRequestException(reqHdr + " not allowed in CORS");
|
throw new BadRequestException(reqHdr + " not allowed in CORS");
|
||||||
@@ -1148,7 +1148,6 @@ public class RestApiServlet extends HttpServlet {
|
|||||||
CurrentUser user = globals.currentUser.get();
|
CurrentUser user = globals.currentUser.get();
|
||||||
if (isRead(req)) {
|
if (isRead(req)) {
|
||||||
user.setAccessPath(AccessPath.REST_API);
|
user.setAccessPath(AccessPath.REST_API);
|
||||||
user.setLastLoginExternalIdKey(globals.webSession.get().getLastLoginExternalId());
|
|
||||||
} else if (user instanceof AnonymousUser) {
|
} else if (user instanceof AnonymousUser) {
|
||||||
throw new AuthException("Authentication required");
|
throw new AuthException("Authentication required");
|
||||||
} else if (!globals.webSession.get().isAccessPathOk(AccessPath.REST_API)) {
|
} else if (!globals.webSession.get().isAccessPathOk(AccessPath.REST_API)) {
|
||||||
@@ -1156,6 +1155,9 @@ public class RestApiServlet extends HttpServlet {
|
|||||||
"Invalid authentication method. In order to authenticate, "
|
"Invalid authentication method. In order to authenticate, "
|
||||||
+ "prefix the REST endpoint URL with /a/ (e.g. http://example.com/a/projects/).");
|
+ "prefix the REST endpoint URL with /a/ (e.g. http://example.com/a/projects/).");
|
||||||
}
|
}
|
||||||
|
if (user.isIdentifiedUser()) {
|
||||||
|
user.setLastLoginExternalIdKey(globals.webSession.get().getLastLoginExternalId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isRead(HttpServletRequest req) {
|
private static boolean isRead(HttpServletRequest req) {
|
||||||
|
Reference in New Issue
Block a user