Skip to content

Commit

Permalink
Add Demo user
Browse files Browse the repository at this point in the history
  • Loading branch information
Frooodle committed Dec 27, 2023
1 parent 78da44a commit 3911be0
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class UserController {
@Autowired
private UserService userService;

@PreAuthorize("!hasAuthority('ROLE_DEMO_USER')")
@PostMapping("/register")
public String register(@RequestParam String username, @RequestParam String password, Model model) {
if(userService.usernameExists(username)) {
Expand All @@ -44,6 +45,7 @@ public String register(@RequestParam String username, @RequestParam String passw
return "redirect:/login?registered=true";
}

@PreAuthorize("!hasAuthority('ROLE_DEMO_USER')")
@PostMapping("/change-username-and-password")
public RedirectView changeUsernameAndPassword(Principal principal,
@RequestParam String currentPassword,
Expand Down Expand Up @@ -86,7 +88,7 @@ public RedirectView changeUsernameAndPassword(Principal principal,
}



@PreAuthorize("!hasAuthority('ROLE_DEMO_USER')")
@PostMapping("/change-username")
public RedirectView changeUsername(Principal principal,
@RequestParam String currentPassword,
Expand Down Expand Up @@ -123,7 +125,8 @@ public RedirectView changeUsername(Principal principal,

return new RedirectView("/login?messageType=credsUpdated");
}


@PreAuthorize("!hasAuthority('ROLE_DEMO_USER')")
@PostMapping("/change-password")
public RedirectView changePassword(Principal principal,
@RequestParam String currentPassword,
Expand Down Expand Up @@ -155,7 +158,7 @@ public RedirectView changePassword(Principal principal,
return new RedirectView("/login?messageType=credsUpdated");
}


@PreAuthorize("!hasAuthority('ROLE_DEMO_USER')")
@PostMapping("/updateUserSettings")
public String updateUserSettings(HttpServletRequest request, Principal principal) {
Map<String, String[]> paramMap = request.getParameterMap();
Expand Down Expand Up @@ -216,6 +219,7 @@ public String deleteUser(@PathVariable String username, Authentication authenti
return "redirect:/addUsers";
}

@PreAuthorize("!hasAuthority('ROLE_DEMO_USER')")
@PostMapping("/get-api-key")
public ResponseEntity<String> getApiKey(Principal principal) {
if (principal == null) {
Expand All @@ -229,6 +233,7 @@ public ResponseEntity<String> getApiKey(Principal principal) {
return ResponseEntity.ok(apiKey);
}

@PreAuthorize("!hasAuthority('ROLE_DEMO_USER')")
@PostMapping("/update-api-key")
public ResponseEntity<String> updateApiKey(Principal principal) {
if (principal == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public String showAddUserForm(Model model, Authentication authentication) {
}



@PreAuthorize("!hasAuthority('ROLE_DEMO_USER')")
@GetMapping("/account")
public String account(HttpServletRequest request, Model model, Authentication authentication) {
if (authentication == null || !authentication.isAuthenticated()) {
Expand Down Expand Up @@ -117,7 +117,7 @@ public String account(HttpServletRequest request, Model model, Authentication au
}



@PreAuthorize("!hasAuthority('ROLE_DEMO_USER')")
@GetMapping("/change-creds")
public String changeCreds(HttpServletRequest request, Model model, Authentication authentication) {
if (authentication == null || !authentication.isAuthenticated()) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/stirling/software/SPDF/model/Role.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ public enum Role {
WEB_ONLY_USER("ROLE_WEB_ONLY_USER", 0, 20),


INTERNAL_API_USER("STIRLING-PDF-BACKEND-API-USER", Integer.MAX_VALUE, Integer.MAX_VALUE);
INTERNAL_API_USER("STIRLING-PDF-BACKEND-API-USER", Integer.MAX_VALUE, Integer.MAX_VALUE),

DEMO_USER("ROLE_DEMO_USER", 100, 100);

private final String roleId;
private final int apiCallsPerDay;
private final int webCallsPerDay;
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/messages_ar_AR.properties
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ adminUserSettings.role=Role
adminUserSettings.actions=Actions
adminUserSettings.apiUser=Limited API User
adminUserSettings.webOnlyUser=Web Only User
adminUserSettings.demoUser=Demo User (No custom settings)
adminUserSettings.forceChange=Force user to change username/password on login
adminUserSettings.submit=Save User

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/messages_en_GB.properties
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ adminUserSettings.role=Role
adminUserSettings.actions=Actions
adminUserSettings.apiUser=Limited API User
adminUserSettings.webOnlyUser=Web Only User
adminUserSettings.demoUser=Demo User (No custom settings)
adminUserSettings.forceChange = Force user to change username/password on login
adminUserSettings.submit=Save User

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/templates/addUsers.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ <h2 th:text="#{adminUserSettings.addUser}">Add New User</h2>
<option value="ROLE_USER" th:text="#{adminUserSettings.user}">User</option>
<option value="ROLE_LIMITED_API_USER" th:text="#{adminUserSettings.apiUser}">Limited API User</option>
<option value="ROLE_WEB_ONLY_USER" th:text="#{adminUserSettings.webOnlyUser}">Web Only User</option>
<option value="ROLE_DEMO_USER" th:text="#{adminUserSettings.demoUser}">Demo User</option>
</select>
</div>
<div class="mb-3">
Expand Down

0 comments on commit 3911be0

Please sign in to comment.