-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added client side authentication support while saving malicious and s…
…mart events
- Loading branch information
Showing
5 changed files
with
257 additions
and
162 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
apps/api-threat-detection/src/main/java/com/akto/auth/grpc/AuthToken.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.akto.auth.grpc; | ||
|
||
<<<<<<< Updated upstream | ||
import io.grpc.CallCredentials; | ||
import io.grpc.Metadata; | ||
import io.grpc.Status; | ||
|
||
import java.util.concurrent.Executor; | ||
|
||
import static io.grpc.Metadata.ASCII_STRING_MARSHALLER; | ||
|
||
public class AuthToken extends CallCredentials { | ||
|
||
private final String token; | ||
public static final Metadata.Key<String> AUTHORIZATION_METADATA_KEY = | ||
Metadata.Key.of("Authorization", ASCII_STRING_MARSHALLER); | ||
|
||
public AuthToken(String token) { | ||
this.token = token; | ||
} | ||
|
||
@Override | ||
public void applyRequestMetadata( | ||
RequestInfo requestInfo, Executor appExecutor, MetadataApplier applier) { | ||
appExecutor.execute( | ||
() -> { | ||
try { | ||
Metadata headers = new Metadata(); | ||
headers.put(AUTHORIZATION_METADATA_KEY, token); | ||
applier.apply(headers); | ||
} catch (Throwable e) { | ||
applier.fail(Status.UNAUTHENTICATED.withCause(e)); | ||
} | ||
}); | ||
} | ||
||||||| Stash base | ||
======= | ||
public class AuthToken { | ||
>>>>>>> Stashed changes | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 42 additions & 18 deletions
60
apps/api-threat-detection/src/main/java/com/akto/suspect_data/Message.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,57 @@ | ||
package com.akto.suspect_data; | ||
|
||
import com.akto.proto.threat_protection.consumer_service.v1.MaliciousEvent; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import java.util.Optional; | ||
|
||
// Kafka Message Wrapper for suspect data | ||
public class Message { | ||
private String accountId; | ||
private MaliciousEvent data; | ||
private String accountId; | ||
private String data; | ||
|
||
public Message() { | ||
} | ||
private static ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
public Message(String accountId, MaliciousEvent data) { | ||
this.accountId = accountId; | ||
this.data = data; | ||
} | ||
public Message() {} | ||
|
||
public String getAccountId() { | ||
return accountId; | ||
} | ||
public Message(String accountId, String data) { | ||
this.accountId = accountId; | ||
this.data = data; | ||
} | ||
|
||
public void setAccountId(String accountId) { | ||
this.accountId = accountId; | ||
} | ||
public String getAccountId() { | ||
return accountId; | ||
} | ||
|
||
public MaliciousEvent getData() { | ||
return data; | ||
public void setAccountId(String accountId) { | ||
this.accountId = accountId; | ||
} | ||
|
||
public String getData() { | ||
return data; | ||
} | ||
|
||
public void setData(String data) { | ||
this.data = data; | ||
} | ||
|
||
public Optional<String> marshal() { | ||
try { | ||
return Optional.ofNullable(objectMapper.writeValueAsString(this)); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
public void setData(MaliciousEvent data) { | ||
this.data = data; | ||
return Optional.empty(); | ||
} | ||
|
||
public static Optional<Message> unmarshal(String message) { | ||
try { | ||
return Optional.ofNullable(objectMapper.readValue(message, Message.class)); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
return Optional.empty(); | ||
} | ||
} |
Oops, something went wrong.