Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions docs/src/modules/sdk/pages/sanitization.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ Text anonymization—detecting and masking sensitive details like names, emails,

Akka supports this through service-wide sanitization.

The sanitization disabled by default and can be selectively enabled through configuration.
The sanitization is disabled by default and can be selectively enabled through configuration.

When enabled, sanitization is automatically applied to text that:
When enabled, sanitization is automatically applied to text that is:

* written to logs
* passed to agent models from agent requests
Expand All @@ -34,9 +34,16 @@ Before being written in logs or passed to agent models.

Sanitization can also be programmatically applied to text in any component where it makes sense for a specific
business case, for example before sending some text to a third party API or before writing a text in the state
of an entity. This is done by injecting a `akka.javasdk.Sanitizer` in the component constructor and
of an entity. This is done by xref:setup-and-dependency-injection.adoc[injecting] a `akka.javasdk.Sanitizer` in the component constructor and
then using `akka.javasdk.Sanitizer#sanitize` on the text.

[source,java,indent=0]
.{sample-base-url}/doc-snippets/src/main/java/com/example/api/SanitizingEndpoint.java[SanitizingEndpoint.java]
----
include::example$doc-snippets/src/main/java/com/example/api/SanitizingEndpoint.java[tag=ad-hoc-sanitization]
----


== Sanitizer types

There are two types of sanitizers available, it is possible combine predefined and custom sanitizers in the same service:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.example.api;

import akka.javasdk.Sanitizer;
import akka.javasdk.annotations.Acl;
import akka.javasdk.annotations.http.Get;
import akka.javasdk.annotations.http.HttpEndpoint;

// tag::ad-hoc-sanitization[]
@HttpEndpoint("/example-with-ad-hoc-sanitization")
@Acl(allow = @Acl.Matcher(principal = Acl.Principal.ALL))
public class SanitizingEndpoint {

private final Sanitizer sanitizer;

public SanitizingEndpoint(Sanitizer sanitizer) {
this.sanitizer = sanitizer;
}

@Get("/somepath/{id}")
public String returnSanitizedData(String id) {
// String data from another component or a third party library/API
String someText = loadText();
String sanitizedText = sanitizer.sanitize(someText);
return sanitizedText;
}

// end::ad-hoc-sanitization[]

private String loadText() {
return "";
}
}
Loading