Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #194 from bsura/cors_fix
Browse files Browse the repository at this point in the history
Fix for CORS issue where sendError doesn't allow CORS headers to be set.
  • Loading branch information
dilipdevaraj-sfdc authored Oct 3, 2016
2 parents ad6cd08 + 7b87581 commit 3ec3711
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ArgusWeb/app/js/services/unauthorizedInterceptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ angular.module('argus.services.interceptor', [])
.factory("UnauthorizedInterceptor", ['$q', '$location', 'Storage', function ($q, $location, Storage) {
return {
responseError: function (rejection) {
if (rejection.status === 401 || rejection.status <= 0) {
if (rejection.status === 401 || rejection.status === 0) {
var url = rejection.config.url;
var suffix = '/login';
if (url.indexOf(suffix, url.length - suffix.length) === -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
Object remoteUser = session.getAttribute(USER_ATTRIBUTE_NAME);

if (!"options".equalsIgnoreCase(req.getMethod()) && !_isAuthEndpoint(req) && remoteUser == null) {
HttpServletResponse.class.cast(response).sendError(HttpServletResponse.SC_UNAUTHORIZED);
HttpServletResponse httpresponse = HttpServletResponse.class.cast(response);
httpresponse.setHeader("Access-Control-Allow-Origin", req.getHeader("Origin"));
httpresponse.setHeader("Access-Control-Allow-Credentials", "true");
httpresponse.sendError(HttpServletResponse.SC_UNAUTHORIZED);
} else if (remoteUser != null) {
user = PrincipalUserDto.class.cast(session.getAttribute(USER_ATTRIBUTE_NAME)).getUserName();
}
Expand Down

0 comments on commit 3ec3711

Please sign in to comment.