Added some endpoints not protected
This commit is contained in:
@ -13,6 +13,8 @@ import org.springframework.context.event.EventListener;
|
||||
@SpringBootApplication
|
||||
public class App {
|
||||
|
||||
public final static String API_VERSION = "v1";
|
||||
|
||||
@Autowired
|
||||
UserService userService;
|
||||
|
||||
|
@ -5,6 +5,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.plannaplan.App;
|
||||
import com.plannaplan.Controller;
|
||||
import com.plannaplan.models.ConfigData;
|
||||
|
||||
@ -12,11 +13,13 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
@RequestMapping("/api/" + App.API_VERSION + "/configurator")
|
||||
public class ConfigController {
|
||||
|
||||
@Autowired
|
||||
|
@ -5,6 +5,7 @@ import java.util.Dictionary;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
|
||||
import com.plannaplan.App;
|
||||
import com.plannaplan.entities.Course;
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.services.CourseService;
|
||||
@ -15,38 +16,40 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
@RequestMapping("/api/" + App.API_VERSION + "/courses")
|
||||
public class CoursesController {
|
||||
@Autowired
|
||||
private CourseService courseService;
|
||||
|
||||
@GetMapping("/getCourses")
|
||||
public ResponseEntity<List<Dictionary<String,Object>>> getMethodName() {
|
||||
public ResponseEntity<List<Dictionary<String, Object>>> getMethodName() {
|
||||
List<Course> courses = this.courseService.getAllCourses();
|
||||
List<Dictionary<String,Object>> response = new ArrayList<>();
|
||||
for(Course c : courses){
|
||||
List<Dictionary<String, Object>> response = new ArrayList<>();
|
||||
for (Course c : courses) {
|
||||
Dictionary<String, Object> element = new Hashtable<>();
|
||||
element.put("id", c.getId());
|
||||
element.put("name",c.getName());
|
||||
element.put("name", c.getName());
|
||||
response.add(element);
|
||||
}
|
||||
|
||||
|
||||
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/getCoursesWithGroups")
|
||||
public ResponseEntity<List<Dictionary<String,Object>>> getCoursesWithGroups() {
|
||||
public ResponseEntity<List<Dictionary<String, Object>>> getCoursesWithGroups() {
|
||||
List<Course> courses = this.courseService.getAllCourses();
|
||||
List<Dictionary<String,Object>> response = new ArrayList<>();
|
||||
for(Course c : courses){
|
||||
List<Dictionary<String, Object>> response = new ArrayList<>();
|
||||
for (Course c : courses) {
|
||||
Dictionary<String, Object> element = new Hashtable<>();
|
||||
element.put("id", c.getId());
|
||||
element.put("name",c.getName());
|
||||
List<Dictionary<String,Object>> groups = new ArrayList<>();
|
||||
for(Groups g : c.getGroups()){
|
||||
Dictionary<String,Object> group = new Hashtable<>();
|
||||
element.put("name", c.getName());
|
||||
List<Dictionary<String, Object>> groups = new ArrayList<>();
|
||||
for (Groups g : c.getGroups()) {
|
||||
Dictionary<String, Object> group = new Hashtable<>();
|
||||
group.put("id", g.getId());
|
||||
group.put("day", g.getDay().label);
|
||||
group.put("time", g.getTimeString());
|
||||
@ -55,11 +58,11 @@ public class CoursesController {
|
||||
group.put("type", g.getType());
|
||||
groups.add(group);
|
||||
}
|
||||
|
||||
|
||||
element.put("groups", groups);
|
||||
response.add(element);
|
||||
}
|
||||
|
||||
|
||||
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ import java.util.Dictionary;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
|
||||
import com.plannaplan.App;
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.services.GroupService;
|
||||
|
||||
@ -13,21 +14,23 @@ import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
@RequestMapping("/api/" + App.API_VERSION + "/groups")
|
||||
public class GroupController {
|
||||
@Autowired
|
||||
private GroupService groupService;
|
||||
|
||||
@GetMapping("/getCourseGroups")
|
||||
public ResponseEntity<List<Dictionary<String, Object>>> getCourses(@RequestParam("id") Long id, @RequestParam(name="capacity", defaultValue="true") Boolean capacity){
|
||||
public ResponseEntity<List<Dictionary<String, Object>>> getCourses(@RequestParam("id") Long id,
|
||||
@RequestParam(name = "capacity", defaultValue = "true") Boolean capacity) {
|
||||
List<Groups> groups = this.groupService.getGroupsByCourse(id);
|
||||
List<Dictionary<String, Object>> response = new ArrayList<>();
|
||||
|
||||
|
||||
for (Groups g : groups) {
|
||||
Dictionary<String, Object> group = new Hashtable<>();
|
||||
group.put("id", g.getId());
|
||||
@ -37,7 +40,7 @@ public class GroupController {
|
||||
group.put("room", g.getRoom());
|
||||
if (capacity) {
|
||||
group.put("capacity", g.getCapacity());
|
||||
}
|
||||
}
|
||||
group.put("type", g.getType());
|
||||
|
||||
response.add(group);
|
||||
|
@ -2,7 +2,6 @@ package com.plannaplan.security;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.builders.WebSecurity;
|
||||
@ -37,7 +36,8 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
|
||||
@Override
|
||||
public void configure(final WebSecurity webSecurity) {
|
||||
webSecurity.ignoring().antMatchers("/token**");
|
||||
webSecurity.ignoring().antMatchers("/token**").antMatchers("/api/v1/courses/getCourses")
|
||||
.antMatchers("/api/v1/groups/getCourseGroups").antMatchers("/api/v1/courses/getCoursesWithGroups");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -46,15 +46,13 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
.sessionCreationPolicy(SessionCreationPolicy.STATELESS).and().exceptionHandling().and()
|
||||
.authenticationProvider(provider)
|
||||
.addFilterBefore(authenticationFilter(), AnonymousAuthenticationFilter.class).authorizeRequests()
|
||||
.antMatchers(HttpMethod.GET, "/token**").permitAll().anyRequest().authenticated();
|
||||
.anyRequest().authenticated();
|
||||
|
||||
}
|
||||
|
||||
@Bean
|
||||
AuthenticationFilter authenticationFilter() throws Exception {
|
||||
final AuthenticationFilter filter = new AuthenticationFilter(PROTECTED_URLS);
|
||||
filter.setAuthenticationManager(authenticationManager());
|
||||
// filter.setAuthenticationSuccessHandler(successHandler());
|
||||
return filter;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user