Skip to content

Commit 88f43da

Browse files
committed
Integrate AngularJS with Spring Boot without Security
1 parent f223f26 commit 88f43da

File tree

3 files changed

+36
-8
lines changed

3 files changed

+36
-8
lines changed

app/search/search.service.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@
88
SearchService.$inject = ['$resource'];
99

1010
function SearchService($resource) {
11-
var Search = $resource('/api/search/people.json');
11+
var Search = $resource('http://localhost:8080/api/people', {}, {
12+
'query': {isArray: false}
13+
});
1214

1315
Search.search = function (term, callback) {
16+
if (term == undefined) {
17+
term = '';
18+
}
1419
Search.query(function (response) {
15-
var results = response.filter(function (item) {
20+
var people = response._embedded.people;
21+
var results = people.filter(function (item) {
1622
return JSON.stringify(item).toLowerCase().includes(term.toLowerCase());
1723
});
1824
return callback(results);
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.example;
2+
3+
import org.springframework.stereotype.Component;
4+
import org.springframework.web.filter.OncePerRequestFilter;
5+
6+
import javax.servlet.FilterChain;
7+
import javax.servlet.ServletException;
8+
import javax.servlet.http.HttpServletRequest;
9+
import javax.servlet.http.HttpServletResponse;
10+
import java.io.IOException;
11+
12+
/**
13+
* Code borrowed from https://jira.spring.io/browse/DATAREST-573 to
14+
* workaround Spring Data REST not supporting @CrossOrigin.
15+
*/
16+
@Component
17+
public class CorsFilter extends OncePerRequestFilter {
18+
19+
public void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
20+
throws IOException, ServletException {
21+
response.setHeader("Access-Control-Allow-Origin", "http://localhost:3000");
22+
response.setHeader("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS, DELETE");
23+
response.setHeader("Access-Control-Max-Age", "3600");
24+
response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
25+
chain.doFilter(request, response);
26+
}
27+
}

src/main/java/com/example/SecurityConfiguration.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,10 @@
44
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
55
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
66

7-
import static com.stormpath.spring.config.StormpathWebSecurityConfigurer.stormpath;
8-
97
@Configuration
108
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
119
@Override
1210
protected void configure(HttpSecurity http) throws Exception {
13-
http.apply(stormpath()).and()
14-
.authorizeRequests()
15-
.antMatchers("/api/**").fullyAuthenticated()
16-
.antMatchers("/**").permitAll();
11+
http.authorizeRequests().antMatchers("/**").permitAll();
1712
}
1813
}

0 commit comments

Comments
 (0)