redact allow colors, bug fixes

This commit is contained in:
Anthony Stirling 2023-08-30 22:52:38 +01:00
parent 8509a16d6e
commit 0fc29de02c
27 changed files with 403 additions and 95 deletions

BIN
images/login-dark.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

BIN
images/login-light.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 118 KiB

After

Width:  |  Height:  |  Size: 131 KiB

View file

@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
@ -121,8 +122,17 @@ public class UserController {
@PreAuthorize("hasRole('ROLE_ADMIN')")
@GetMapping("/admin/deleteUser/{username}")
public String deleteUser(@PathVariable String username) {
@PostMapping("/admin/deleteUser/{username}")
public String deleteUser(@PathVariable String username, Authentication authentication) {
// Get the currently authenticated username
String currentUsername = authentication.getName();
// Check if the provided username matches the current session's username
if (currentUsername.equals(username)) {
throw new IllegalArgumentException("Cannot delete currently logined in user.");
}
userService.deleteUser(username);
return "redirect:/addUsers";
}

View file

@ -45,6 +45,7 @@ public class RedactController {
@Parameter(description = "List of listOfText to redact from the PDF", required = true, schema = @Schema(type = "string")) @RequestParam("listOfText") String listOfTextString,
@RequestParam(value = "useRegex", required = false) boolean useRegex,
@RequestParam(value = "wholeWordSearch", required = false) boolean wholeWordSearchBool,
@RequestParam(value = "redactColor", required = false, defaultValue = "#000000") String colorString,
@RequestParam(value = "customPadding", required = false) float customPadding,
@RequestParam(value = "convertPDFToImage", required = false) boolean convertPDFToImage) throws Exception {
@ -52,12 +53,26 @@ public class RedactController {
String[] listOfText = listOfTextString.split("\n");
byte[] bytes = file.getBytes();
PDDocument document = PDDocument.load(new ByteArrayInputStream(bytes));
Color redactColor;
try {
if (!colorString.startsWith("#")) {
colorString = "#" + colorString;
}
redactColor = Color.decode(colorString);
} catch (NumberFormatException e) {
logger.warn("Invalid color string provided. Using default color BLACK for redaction.");
redactColor = Color.BLACK;
}
for (String text : listOfText) {
text = text.trim();
System.out.println(text);
TextFinder textFinder = new TextFinder(text, useRegex, wholeWordSearchBool);
List<PDFText> foundTexts = textFinder.getTextLocations(document);
redactFoundText(document, foundTexts, customPadding);
redactFoundText(document, foundTexts, customPadding,redactColor);
}
@ -88,13 +103,13 @@ public class RedactController {
}
private void redactFoundText(PDDocument document, List<PDFText> blocks, float customPadding) throws IOException {
private void redactFoundText(PDDocument document, List<PDFText> blocks, float customPadding, Color redactColor) throws IOException {
var allPages = document.getDocumentCatalog().getPages();
for (PDFText block : blocks) {
var page = allPages.get(block.getPageIndex());
PDPageContentStream contentStream = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.APPEND, true, true);
contentStream.setNonStrokingColor(Color.BLACK);
contentStream.setNonStrokingColor(redactColor);
float padding = (block.getY2() - block.getY1()) * 0.3f + customPadding;
PDRectangle pageBox = page.getBBox();
contentStream.addRect(block.getX1(), pageBox.getHeight() - block.getY1() - padding, block.getX2() - block.getX1(), block.getY2() - block.getY1() + 2 * padding);
@ -103,4 +118,5 @@ public class RedactController {
}
}
}

View file

@ -58,14 +58,13 @@ public class AccountWebController {
@Autowired
private UserRepository userRepository; // Assuming you have a repository for user operations
@Autowired
private UserService userService; // Assuming you have a repository for user operations
@PreAuthorize("hasRole('ROLE_ADMIN')")
@GetMapping("/addUsers")
public String showAddUserForm(Model model) {
public String showAddUserForm(Model model, Authentication authentication) {
List<User> allUsers = userRepository.findAll();
model.addAttribute("users", allUsers);
model.addAttribute("currentUsername", authentication.getName());
return "addUsers";
}

View file

@ -35,7 +35,20 @@ delete=Delete
username=Username
password=Password
welcome=Welcome
=Property
##########################
### TODO: Translate ###
##########################
property=Property
black=Black
white=White
red=Red
green=Green
blue=Blue
custom=Custom...
#############
# NAVBAR #
@ -309,9 +322,6 @@ showJS.tags=JS
# #
###########################
#login
##########################
### TODO: Translate ###
##########################
login.title=Sign in
login.signin=Sign in
login.rememberme=Remember me
@ -323,6 +333,10 @@ login.signinTitle=Please sign in
#auto-redact
autoRedact.title=Auto Redact
autoRedact.header=Auto Redact
##########################
### TODO: Translate ###
##########################
autoRedact.colorLabel=Colour
autoRedact.textsToRedactLabel=Text to Redact (line-separated)
autoRedact.textsToRedactPlaceholder=e.g. \nConfidential \nTop-Secret
autoRedact.useRegexLabel=Use Regex

View file

@ -35,7 +35,20 @@ delete=Delete
username=Username
password=Password
welcome=Welcome
=Property
##########################
### TODO: Translate ###
##########################
property=Property
black=Black
white=White
red=Red
green=Green
blue=Blue
custom=Custom...
#############
# NAVBAR #
@ -309,9 +322,6 @@ showJS.tags=JS
# #
###########################
#login
##########################
### TODO: Translate ###
##########################
login.title=Sign in
login.signin=Sign in
login.rememberme=Remember me
@ -323,6 +333,10 @@ login.signinTitle=Please sign in
#auto-redact
autoRedact.title=Auto Redact
autoRedact.header=Auto Redact
##########################
### TODO: Translate ###
##########################
autoRedact.colorLabel=Colour
autoRedact.textsToRedactLabel=Text to Redact (line-separated)
autoRedact.textsToRedactPlaceholder=e.g. \nConfidential \nTop-Secret
autoRedact.useRegexLabel=Use Regex

View file

@ -35,7 +35,20 @@ delete=Delete
username=Username
password=Password
welcome=Welcome
=Property
##########################
### TODO: Translate ###
##########################
property=Property
black=Black
white=White
red=Red
green=Green
blue=Blue
custom=Custom...
#############
# NAVBAR #
@ -309,9 +322,6 @@ showJS.tags=JS
# #
###########################
#login
##########################
### TODO: Translate ###
##########################
login.title=Sign in
login.signin=Sign in
login.rememberme=Remember me
@ -323,6 +333,10 @@ login.signinTitle=Please sign in
#auto-redact
autoRedact.title=Auto Redact
autoRedact.header=Auto Redact
##########################
### TODO: Translate ###
##########################
autoRedact.colorLabel=Colour
autoRedact.textsToRedactLabel=Text to Redact (line-separated)
autoRedact.textsToRedactPlaceholder=e.g. \nConfidential \nTop-Secret
autoRedact.useRegexLabel=Use Regex

View file

@ -35,7 +35,17 @@ delete=Delete
username=Username
password=Password
welcome=Welcome
=Property
property=Property
black=Black
white=White
red=Red
green=Green
blue=Blue
custom=Custom...
#############
# NAVBAR #
@ -320,6 +330,7 @@ login.signinTitle=Please sign in
#auto-redact
autoRedact.title=Auto Redact
autoRedact.header=Auto Redact
autoRedact.colorLabel=Colour
autoRedact.textsToRedactLabel=Text to Redact (line-separated)
autoRedact.textsToRedactPlaceholder=e.g. \nConfidential \nTop-Secret
autoRedact.useRegexLabel=Use Regex

View file

@ -35,7 +35,20 @@ delete=Delete
username=Username
password=Password
welcome=Welcome
=Property
##########################
### TODO: Translate ###
##########################
property=Property
black=Black
white=White
red=Red
green=Green
blue=Blue
custom=Custom...
#############
# NAVBAR #
@ -309,9 +322,6 @@ showJS.tags=JS
# #
###########################
#login
##########################
### TODO: Translate ###
##########################
login.title=Sign in
login.signin=Sign in
login.rememberme=Remember me
@ -323,6 +333,10 @@ login.signinTitle=Please sign in
#auto-redact
autoRedact.title=Auto Redact
autoRedact.header=Auto Redact
##########################
### TODO: Translate ###
##########################
autoRedact.colorLabel=Color
autoRedact.textsToRedactLabel=Text to Redact (line-separated)
autoRedact.textsToRedactPlaceholder=e.g. \nConfidential \nTop-Secret
autoRedact.useRegexLabel=Use Regex

View file

@ -35,7 +35,20 @@ delete=Delete
username=Username
password=Password
welcome=Welcome
=Property
##########################
### TODO: Translate ###
##########################
property=Property
black=Black
white=White
red=Red
green=Green
blue=Blue
custom=Custom...
#############
# NAVBAR #
@ -309,9 +322,6 @@ showJS.tags=JS
# #
###########################
#login
##########################
### TODO: Translate ###
##########################
login.title=Sign in
login.signin=Sign in
login.rememberme=Remember me
@ -323,6 +333,10 @@ login.signinTitle=Please sign in
#auto-redact
autoRedact.title=Auto Redact
autoRedact.header=Auto Redact
##########################
### TODO: Translate ###
##########################
autoRedact.colorLabel=Colour
autoRedact.textsToRedactLabel=Text to Redact (line-separated)
autoRedact.textsToRedactPlaceholder=e.g. \nConfidential \nTop-Secret
autoRedact.useRegexLabel=Use Regex

View file

@ -35,7 +35,20 @@ delete=Delete
username=Username
password=Password
welcome=Welcome
=Property
##########################
### TODO: Translate ###
##########################
property=Property
black=Black
white=White
red=Red
green=Green
blue=Blue
custom=Custom...
#############
# NAVBAR #
@ -309,9 +322,6 @@ showJS.tags=JS
# #
###########################
#login
##########################
### TODO: Translate ###
##########################
login.title=Sign in
login.signin=Sign in
login.rememberme=Remember me
@ -323,6 +333,10 @@ login.signinTitle=Please sign in
#auto-redact
autoRedact.title=Auto Redact
autoRedact.header=Auto Redact
##########################
### TODO: Translate ###
##########################
autoRedact.colorLabel=Colour
autoRedact.textsToRedactLabel=Text to Redact (line-separated)
autoRedact.textsToRedactPlaceholder=e.g. \nConfidential \nTop-Secret
autoRedact.useRegexLabel=Use Regex

View file

@ -35,7 +35,20 @@ delete=Delete
username=Username
password=Password
welcome=Welcome
=Property
##########################
### TODO: Translate ###
##########################
property=Property
black=Black
white=White
red=Red
green=Green
blue=Blue
custom=Custom...
#############
# NAVBAR #
@ -309,9 +322,6 @@ showJS.tags=afficher,javascript,js
# #
###########################
#login
##########################
### TODO: Translate ###
##########################
login.title=Sign in
login.signin=Sign in
login.rememberme=Remember me
@ -323,6 +333,10 @@ login.signinTitle=Please sign in
#auto-redact
autoRedact.title=Auto Redact
autoRedact.header=Auto Redact
##########################
### TODO: Translate ###
##########################
autoRedact.colorLabel=Colour
autoRedact.textsToRedactLabel=Text to Redact (line-separated)
autoRedact.textsToRedactPlaceholder=e.g. \nConfidential \nTop-Secret
autoRedact.useRegexLabel=Use Regex

View file

@ -35,7 +35,20 @@ delete=Delete
username=Username
password=Password
welcome=Welcome
=Property
##########################
### TODO: Translate ###
##########################
property=Property
black=Black
white=White
red=Red
green=Green
blue=Blue
custom=Custom...
#############
# NAVBAR #
@ -309,9 +322,6 @@ showJS.tags=JS
# #
###########################
#login
##########################
### TODO: Translate ###
##########################
login.title=Sign in
login.signin=Sign in
login.rememberme=Remember me
@ -323,6 +333,10 @@ login.signinTitle=Please sign in
#auto-redact
autoRedact.title=Auto Redact
autoRedact.header=Auto Redact
##########################
### TODO: Translate ###
##########################
autoRedact.colorLabel=Colour
autoRedact.textsToRedactLabel=Text to Redact (line-separated)
autoRedact.textsToRedactPlaceholder=e.g. \nConfidential \nTop-Secret
autoRedact.useRegexLabel=Use Regex

View file

@ -35,7 +35,20 @@ delete=Delete
username=Username
password=Password
welcome=Welcome
=Property
##########################
### TODO: Translate ###
##########################
property=Property
black=Black
white=White
red=Red
green=Green
blue=Blue
custom=Custom...
#############
# NAVBAR #
@ -309,9 +322,6 @@ showJS.tags=JS
# #
###########################
#login
##########################
### TODO: Translate ###
##########################
login.title=Sign in
login.signin=Sign in
login.rememberme=Remember me
@ -323,6 +333,10 @@ login.signinTitle=Please sign in
#auto-redact
autoRedact.title=Auto Redact
autoRedact.header=Auto Redact
##########################
### TODO: Translate ###
##########################
autoRedact.colorLabel=Colour
autoRedact.textsToRedactLabel=Text to Redact (line-separated)
autoRedact.textsToRedactPlaceholder=e.g. \nConfidential \nTop-Secret
autoRedact.useRegexLabel=Use Regex

View file

@ -35,7 +35,20 @@ delete=Delete
username=Username
password=Password
welcome=Welcome
=Property
##########################
### TODO: Translate ###
##########################
property=Property
black=Black
white=White
red=Red
green=Green
blue=Blue
custom=Custom...
#############
# NAVBAR #
@ -309,9 +322,6 @@ showJS.tags=JS
# #
###########################
#login
##########################
### TODO: Translate ###
##########################
login.title=Sign in
login.signin=Sign in
login.rememberme=Remember me
@ -323,6 +333,10 @@ login.signinTitle=Please sign in
#auto-redact
autoRedact.title=Auto Redact
autoRedact.header=Auto Redact
##########################
### TODO: Translate ###
##########################
autoRedact.colorLabel=Colour
autoRedact.textsToRedactLabel=Text to Redact (line-separated)
autoRedact.textsToRedactPlaceholder=e.g. \nConfidential \nTop-Secret
autoRedact.useRegexLabel=Use Regex

View file

@ -35,7 +35,20 @@ delete=Verwijderen
username=Gebruikersnaam
password=Wachtwoord
welcome=Welkom
=Property
##########################
### TODO: Translate ###
##########################
property=Property
black=Black
white=White
red=Red
green=Green
blue=Blue
custom=Custom...
#############
# NAVBAR #
@ -309,9 +322,6 @@ showJS.tags=JS
# #
###########################
#login
##########################
### TODO: Translate ###
##########################
login.title=Sign in
login.signin=Sign in
login.rememberme=Remember me
@ -323,6 +333,10 @@ login.signinTitle=Please sign in
#auto-redact
autoRedact.title=Auto Redact
autoRedact.header=Auto Redact
##########################
### TODO: Translate ###
##########################
autoRedact.colorLabel=Colour
autoRedact.textsToRedactLabel=Text to Redact (line-separated)
autoRedact.textsToRedactPlaceholder=e.g. \nConfidential \nTop-Secret
autoRedact.useRegexLabel=Use Regex

View file

@ -35,7 +35,20 @@ delete=Delete
username=Username
password=Password
welcome=Welcome
=Property
##########################
### TODO: Translate ###
##########################
property=Property
black=Black
white=White
red=Red
green=Green
blue=Blue
custom=Custom...
#############
# NAVBAR #
@ -309,9 +322,6 @@ showJS.tags=JS
# #
###########################
#login
##########################
### TODO: Translate ###
##########################
login.title=Sign in
login.signin=Sign in
login.rememberme=Remember me
@ -323,6 +333,10 @@ login.signinTitle=Please sign in
#auto-redact
autoRedact.title=Auto Redact
autoRedact.header=Auto Redact
##########################
### TODO: Translate ###
##########################
autoRedact.colorLabel=Colour
autoRedact.textsToRedactLabel=Text to Redact (line-separated)
autoRedact.textsToRedactPlaceholder=e.g. \nConfidential \nTop-Secret
autoRedact.useRegexLabel=Use Regex

View file

@ -35,7 +35,20 @@ delete=Delete
username=Username
password=Password
welcome=Welcome
=Property
##########################
### TODO: Translate ###
##########################
property=Property
black=Black
white=White
red=Red
green=Green
blue=Blue
custom=Custom...
#############
# NAVBAR #
@ -309,9 +322,6 @@ showJS.tags=JavaScript
# #
###########################
#login
##########################
### TODO: Translate ###
##########################
login.title=Sign in
login.signin=Sign in
login.rememberme=Remember me
@ -323,6 +333,10 @@ login.signinTitle=Please sign in
#auto-redact
autoRedact.title=Auto Redact
autoRedact.header=Auto Redact
##########################
### TODO: Translate ###
##########################
autoRedact.colorLabel=Colour
autoRedact.textsToRedactLabel=Text to Redact (line-separated)
autoRedact.textsToRedactPlaceholder=e.g. \nConfidential \nTop-Secret
autoRedact.useRegexLabel=Use Regex

View file

@ -35,7 +35,20 @@ delete=Delete
username=Username
password=Password
welcome=Welcome
=Property
##########################
### TODO: Translate ###
##########################
property=Property
black=Black
white=White
red=Red
green=Green
blue=Blue
custom=Custom...
#############
# NAVBAR #
@ -309,9 +322,6 @@ showJS.tags=JS
# #
###########################
#login
##########################
### TODO: Translate ###
##########################
login.title=Sign in
login.signin=Sign in
login.rememberme=Remember me
@ -323,6 +333,10 @@ login.signinTitle=Please sign in
#auto-redact
autoRedact.title=Auto Redact
autoRedact.header=Auto Redact
##########################
### TODO: Translate ###
##########################
autoRedact.colorLabel=Colour
autoRedact.textsToRedactLabel=Text to Redact (line-separated)
autoRedact.textsToRedactPlaceholder=e.g. \nConfidential \nTop-Secret
autoRedact.useRegexLabel=Use Regex

View file

@ -35,7 +35,20 @@ delete=Delete
username=Username
password=Password
welcome=Welcome
=Property
##########################
### TODO: Translate ###
##########################
property=Property
black=Black
white=White
red=Red
green=Green
blue=Blue
custom=Custom...
#############
# NAVBAR #
@ -309,9 +322,6 @@ showJS.tags=JS
# #
###########################
#login
##########################
### TODO: Translate ###
##########################
login.title=Sign in
login.signin=Sign in
login.rememberme=Remember me
@ -323,6 +333,10 @@ login.signinTitle=Please sign in
#auto-redact
autoRedact.title=Auto Redact
autoRedact.header=Auto Redact
##########################
### TODO: Translate ###
##########################
autoRedact.colorLabel=Colour
autoRedact.textsToRedactLabel=Text to Redact (line-separated)
autoRedact.textsToRedactPlaceholder=e.g. \nConfidential \nTop-Secret
autoRedact.useRegexLabel=Use Regex

View file

@ -35,7 +35,20 @@ delete=Delete
username=Username
password=Password
welcome=Welcome
=Property
##########################
### TODO: Translate ###
##########################
property=Property
black=Black
white=White
red=Red
green=Green
blue=Blue
custom=Custom...
#############
# NAVBAR #
@ -309,9 +322,6 @@ showJS.tags=JS
# #
###########################
#login
##########################
### TODO: Translate ###
##########################
login.title=Sign in
login.signin=Sign in
login.rememberme=Remember me
@ -323,6 +333,10 @@ login.signinTitle=Please sign in
#auto-redact
autoRedact.title=Auto Redact
autoRedact.header=Auto Redact
##########################
### TODO: Translate ###
##########################
autoRedact.colorLabel=Colour
autoRedact.textsToRedactLabel=Text to Redact (line-separated)
autoRedact.textsToRedactPlaceholder=e.g. \nConfidential \nTop-Secret
autoRedact.useRegexLabel=Use Regex

View file

@ -35,7 +35,20 @@ delete=Delete
username=Username
password=Password
welcome=Welcome
=Property
##########################
### TODO: Translate ###
##########################
property=Property
black=Black
white=White
red=Red
green=Green
blue=Blue
custom=Custom...
#############
# NAVBAR #
@ -309,9 +322,6 @@ showJS.tags=JS
# #
###########################
#login
##########################
### TODO: Translate ###
##########################
login.title=Sign in
login.signin=Sign in
login.rememberme=Remember me
@ -323,6 +333,10 @@ login.signinTitle=Please sign in
#auto-redact
autoRedact.title=Auto Redact
autoRedact.header=Auto Redact
##########################
### TODO: Translate ###
##########################
autoRedact.colorLabel=Colour
autoRedact.textsToRedactLabel=Text to Redact (line-separated)
autoRedact.textsToRedactPlaceholder=e.g. \nConfidential \nTop-Secret
autoRedact.useRegexLabel=Use Regex

View file

@ -32,13 +32,16 @@
<td th:text="${user.username}"></td>
<td th:text="${user.getRolesAsString()}"></td>
<td>
<a th:href="@{'/admin/deleteUser/' + ${user.username}}" th:text="#{delete}">Delete</a>
<form th:if="${user.username != currentUsername}" th:action="@{'/admin/deleteUser/' + ${user.username}}" method="post">
<button type="submit" th:text="#{delete}">Delete</button>
</form>
</td>
</tr>
</tbody>
</table>
<h2 th:text="#{adminUserSettings.addUser}">Add New User</h2>
<form action="/admin/saveUser" method="post">
<div class="mb-3">

View file

@ -21,6 +21,37 @@
<textarea class="form-control" id="listOfText" name="listOfText" rows="4" required th:placeholder="#{autoRedact.textsToRedactPlaceholder}"></textarea>
</div>
<div class="mb-3">
<label for="defaultColor" class="form-label" th:text="#{autoRedact.colorLabel}">Color</label>
<select class="form-control" id="defaultColor" name="defaultColor" onchange="handleColorChange(this.value)">
<option value="#000000" th:text="#{black}">Black</option>
<option value="#FFFFFF" th:text="#{white}">White</option>
<option value="#FF0000" th:text="#{red}">Red</option>
<option value="#00FF00" th:text="#{green}">Green</option>
<option value="#0000FF" th:text="#{blue}">Blue</option>
<option value="custom" th:text="#{custom}">Custom...</option>
</select>
</div>
<!-- Custom Color Input -->
<div class="mb-3" id="customColorContainer" style="display: none;">
<label for="customColor" class="form-label" th:text="#{autoRedact.colorLabel}">Custom Color</label>
<input type="text" class="form-control" id="customColor" name="redactColor" placeholder="#FF00FF">
</div>
<script>
function handleColorChange(selectedValue) {
if (selectedValue === "custom") {
document.getElementById('customColorContainer').style.display = 'block';
} else {
document.getElementById('customColorContainer').style.display = 'none';
document.getElementById('customColor').value = selectedValue;
}
}
</script>
<div class="mb-3 form-check">
<input type="checkbox" class="form-check-input" id="useRegex" name="useRegex">
<label class="form-check-label" for="useRegex" th:text="#{autoRedact.useRegexLabel}"></label>