I am using Angular 4 , JAX-RS for rest services. Angular is deployed in tomcat server and JAX-RS rest services were deployed in Websphere 8.5 App server. I am trying to secure the rest services using Basic Auth. Here is web.xml part used for resolving CORS issue and Basic Auth
<filter>
<filter-name>CORS</filter-name>
<filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
<init-param>
<param-name>cors.allowGenericHttpRequests</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>cors.allowOrigin</param-name>
<param-value>*</param-value>
</init-param>
<init-param>
<param-name>cors.allowSubdomains</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>cors.supportedMethods</param-name>
<param-value>GET, POST, PUT, DELETE, OPTIONS, HEAD </param-value>
</init-param>
<init-param>
<param-name>cors.supportedHeaders</param-name>
<param-value>*</param-value>
</init-param>
<init-param>
<param-name>cors.supportsCredentials</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>cors.maxAge</param-name>
<param-value>-1</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CORS</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<security-role>
<description>default</description>
<role-name>default</role-name>
</security-role>
<security-constraint>
<display-name>DefaultConstraints</display-name>
<web-resource-collection>
<web-resource-name>all resources</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
<http-method>PUT</http-method>
<http-method>HEAD</http-method>
<http-method>TRACE</http-method>
<http-method>DELETE</http-method>
<http-method>OPTIONS</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>default</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
When Angular app invokes Rest services from chrome browser with the above configuration in Java web it is throwing the error and below is seen in the browser console.
Failed to load resource: the server responded with a status of 401 (Unauthorized)
Failed to load http://localhost:9091/xxxxxxx/rest/v1/technologies: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. The response had HTTP status code 401.
If the same angular app invokes the rest services from IE , the browser is throwing a pop-up for credentials and after succesful login, angular is able to fetch and display the records.
It is working for IE, not working for chrome.
If I remove the security constraint, basic auth, roles and only place CORS filter, Angular is able to fetch records from rest services in both chrome and IE. If fails only in chrome when security constraint.
Please help me in resolving. Let me know if there are any mistakes.
Thanks, Hari.