Permalink
Browse files

Integrate AngularJS with Spring Boot without Security

1 parent f223f26 commit 88f43da9fc14bb59e6d1b7f36f658730029b4bd7 @mraible mraible committed Oct 18, 2016
@@ -8,11 +8,17 @@
SearchService.$inject = ['$resource'];
function SearchService($resource) {
- var Search = $resource('/api/search/people.json');
+ var Search = $resource('http://localhost:8080/api/people', {}, {
+ 'query': {isArray: false}
+ });
Search.search = function (term, callback) {
+ if (term == undefined) {
+ term = '';
+ }
Search.query(function (response) {
- var results = response.filter(function (item) {
+ var people = response._embedded.people;
+ var results = people.filter(function (item) {
return JSON.stringify(item).toLowerCase().includes(term.toLowerCase());
});
return callback(results);
@@ -0,0 +1,27 @@
+package com.example;
+
+import org.springframework.stereotype.Component;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+/**
+ * Code borrowed from https://jira.spring.io/browse/DATAREST-573 to
+ * workaround Spring Data REST not supporting @CrossOrigin.
+ */
+@Component
+public class CorsFilter extends OncePerRequestFilter {
+
+ public void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
+ throws IOException, ServletException {
+ response.setHeader("Access-Control-Allow-Origin", "http://localhost:3000");
+ response.setHeader("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS, DELETE");
+ response.setHeader("Access-Control-Max-Age", "3600");
+ response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
+ chain.doFilter(request, response);
+ }
+}
@@ -4,15 +4,10 @@
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
-import static com.stormpath.spring.config.StormpathWebSecurityConfigurer.stormpath;
-
@Configuration
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
- http.apply(stormpath()).and()
- .authorizeRequests()
- .antMatchers("/api/**").fullyAuthenticated()
- .antMatchers("/**").permitAll();
+ http.authorizeRequests().antMatchers("/**").permitAll();
}
}

0 comments on commit 88f43da

Please sign in to comment.