Skip to content

Commit 1074292

Browse files
authored
Merge pull request kaakaww#18 from kaakaww/feature/SCAN-251-add-hidden-routes
SCAN-252 - added in some hidden routes for seed paths
2 parents 2a99687 + 5697178 commit 1074292

File tree

17 files changed

+607
-7
lines changed

17 files changed

+607
-7
lines changed

db/vulny.mv.db

0 Bytes
Binary file not shown.

src/main/java/hawk/Application.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
import java.util.stream.Stream;
55

66
import hawk.entity.Item;
7+
import hawk.entity.User;
78
import hawk.repos.ItemRepo;
8-
import hawk.repos.ItemsRepo;
9+
import hawk.repos.UserRepo;
910
import org.springframework.beans.factory.annotation.Value;
1011
import org.springframework.boot.CommandLineRunner;
1112
import org.springframework.boot.SpringApplication;
1213
import org.springframework.boot.autoconfigure.SpringBootApplication;
1314
import org.springframework.context.ApplicationContext;
1415
import org.springframework.context.annotation.Bean;
15-
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
1616

1717
@SpringBootApplication
1818
public class Application {
@@ -25,7 +25,7 @@ public static void main(String[] args) {
2525
private String dbUrl;
2626

2727
@Bean
28-
public CommandLineRunner commandLineRunner(ApplicationContext ctx, ItemRepo repo) {
28+
public CommandLineRunner commandLineRunner(ApplicationContext ctx, ItemRepo repo, UserRepo userRepo) {
2929

3030

3131
return args -> {
@@ -55,6 +55,20 @@ public CommandLineRunner commandLineRunner(ApplicationContext ctx, ItemRepo repo
5555
repo.findAll().forEach(item -> System.out.println(String.format("item: %s", item.getName())));
5656
}
5757

58+
System.out.println(String.format("Users in DB %d", userRepo.count()));
59+
60+
if (userRepo.count() == 0) {
61+
userRepo.findAll().forEach(item -> System.out.println(String.format("item: %s", item.getName())));
62+
63+
Stream.of(1, 2, 3).forEach(i -> {
64+
System.out.println(String.format("Adding item%d", i));
65+
userRepo.save(new User(String.format("user%d", i), String.format("we have the best users, users%d", i)));
66+
});
67+
68+
System.out.println(String.format("Items in DB %d", userRepo.count()));
69+
userRepo.findAll().forEach(item -> System.out.println(String.format("item: %s", item.getName())));
70+
}
71+
5872
};
5973
}
6074

src/main/java/hawk/Config.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package hawk;
22

33
import hawk.service.SearchService;
4+
import hawk.service.UserService;
45
import org.springframework.context.annotation.Bean;
56
import org.springframework.context.annotation.Configuration;
67
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
@@ -14,5 +15,7 @@ public class Config implements WebMvcConfigurer {
1415
public SearchService searchService(){
1516
return new SearchService();
1617
}
18+
@Bean
19+
public UserService userService() { return new UserService(); }
1720

1821
}

src/main/java/hawk/MultiHttpSecurityConfig.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ protected void configure(HttpSecurity http) throws Exception {
134134
"/openapi.yaml",
135135
"/swagger-ui/**",
136136
"/swagger-ui.html",
137-
"/log4j"
137+
"/log4j",
138+
"/hidden",
139+
"/hidden/*"
138140
).permitAll()
139141
.anyRequest().authenticated()
140142
.and()
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package hawk.api.jwt;
2+
3+
import hawk.form.Search;
4+
import hawk.service.SearchService;
5+
import hawk.service.UserService;
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.http.ResponseEntity;
8+
import org.springframework.web.bind.annotation.GetMapping;
9+
import org.springframework.web.bind.annotation.PathVariable;
10+
import org.springframework.web.bind.annotation.RequestMapping;
11+
import org.springframework.web.bind.annotation.RestController;
12+
13+
@RestController
14+
@RequestMapping("/api/jwt/users")
15+
public class JwtUserController {
16+
17+
private final UserService userService;
18+
19+
@Autowired
20+
public JwtUserController(UserService userService) {
21+
this.userService = userService;
22+
}
23+
24+
@GetMapping("/search/")
25+
public ResponseEntity searchAll() {
26+
Search search = new Search("");
27+
return ResponseEntity.ok(userService.search(search));
28+
}
29+
30+
@GetMapping("/search/{text}")
31+
public ResponseEntity search(@PathVariable("text") String text) {
32+
Search search = new Search(text);
33+
return ResponseEntity.ok(userService.search(search));
34+
}
35+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package hawk.controller;
2+
3+
import hawk.entity.Item;
4+
import hawk.form.Search;
5+
import hawk.service.SearchService;
6+
import hawk.service.UserService;
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.stereotype.Controller;
9+
import org.springframework.ui.Model;
10+
import org.springframework.web.bind.annotation.GetMapping;
11+
import org.springframework.web.bind.annotation.ModelAttribute;
12+
import org.springframework.web.bind.annotation.PostMapping;
13+
14+
import java.util.List;
15+
16+
@Controller
17+
public class AdminController {
18+
@Autowired
19+
UserService userService;
20+
21+
@GetMapping("/admin")
22+
public String index(Model model) {
23+
model.addAttribute("title", "Admin");
24+
return "admin";
25+
}
26+
27+
@GetMapping("/admin/users")
28+
public String users(Model model) {
29+
model.addAttribute("title", "Users");
30+
return "users";
31+
}
32+
33+
@GetMapping("/admin/companies")
34+
public String companies(Model model) {
35+
model.addAttribute("title", "Companies");
36+
return "companies";
37+
}
38+
39+
@GetMapping( "/admin/search")
40+
public String searchForm(Model model) {
41+
model.addAttribute("search", new Search());
42+
model.addAttribute("title", "User Search");
43+
return "user-search";
44+
}
45+
46+
@PostMapping( "/admin/search")
47+
public String searchSubmit(@ModelAttribute Search search, Model model) {
48+
List<Item> users = userService.search(search);
49+
model.addAttribute("users", users);
50+
model.addAttribute("search", search);
51+
model.addAttribute("title", "User Search");
52+
return "user-search";
53+
}
54+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package hawk.controller;
2+
3+
import org.springframework.stereotype.Controller;
4+
import org.springframework.ui.Model;
5+
import org.springframework.web.bind.annotation.GetMapping;
6+
7+
@Controller
8+
public class HiddenController {
9+
10+
@GetMapping("/hidden")
11+
public String index(Model model) {
12+
model.addAttribute("title", "Hidden Page");
13+
return "hidden";
14+
}
15+
16+
@GetMapping("/hidden/hidden2")
17+
public String jwtAuth(Model model) {
18+
model.addAttribute("title", "Rando hidden page");
19+
return "hidden2";
20+
}
21+
}

src/main/java/hawk/controller/PayloadController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class PayloadController {
2727
@Value("${payload.count:10}")
2828
private int payloadCount = 20;
2929

30-
@GetMapping("/payload/{size}")
30+
@GetMapping(value={"/payload/{size}","/admin/payload/{size}"})
3131
public String getPayload(Model model,
3232
@PathVariable("size") Integer size) {
3333

@@ -42,7 +42,7 @@ public String getPayload(Model model,
4242
return "payload-view";
4343
}
4444

45-
@GetMapping("/payloads")
45+
@GetMapping(value={"/payloads", "/admin/payloads"})
4646
public String getPayloadsList(Model model){
4747
Integer[] payloadSizes = new Integer[payloadCount];
4848

@@ -54,7 +54,7 @@ public String getPayloadsList(Model model){
5454
return "payloads";
5555
}
5656

57-
@GetMapping("/payload/stream/{size}")
57+
@GetMapping(value={"/payload/stream/{size}", "/admin/payload/stream/{size}"})
5858
public StreamingResponseBody getPayloadStream(@PathVariable("size") Integer size) {
5959
String tmpData = "mobile: 555-678-5343 ";
6060

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package hawk.entity;
2+
3+
import javax.persistence.Entity;
4+
import javax.persistence.GeneratedValue;
5+
import javax.persistence.GenerationType;
6+
import javax.persistence.Id;
7+
8+
@Entity
9+
public class User {
10+
@Id
11+
@GeneratedValue(strategy= GenerationType.AUTO)
12+
private Long id;
13+
private String name;
14+
private String description;
15+
16+
protected User() {}
17+
18+
public User(Long id, String name, String description) {
19+
this(name, description);
20+
this.id = id;
21+
}
22+
23+
public User(String name, String description) {
24+
this.name = name;
25+
this.description = description;
26+
}
27+
28+
public Long getId() {
29+
return id;
30+
}
31+
32+
public String getName() {
33+
return name;
34+
}
35+
36+
public String getDescription() {
37+
return description;
38+
}
39+
40+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package hawk.repos;
2+
3+
import hawk.entity.User;
4+
import org.springframework.data.repository.CrudRepository;
5+
6+
public interface UserRepo extends CrudRepository<User, Long> {
7+
}

0 commit comments

Comments
 (0)