-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(config-api): audit log, agama ADS spec, fix for 0 index search (#…
…3369) * feat(config-api): audit log changes * feat(config-api): audit log and request interceptor * feat(config-api): sync with main * feat(config-api): audit log, agama ADS spec, fix for 0 index search * feat(config-api): audit log, agama ADS spec, fix for 0 index search
- Loading branch information
Showing
18 changed files
with
396 additions
and
43 deletions.
There are no files selected for viewing
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
40 changes: 40 additions & 0 deletions
40
jans-config-api/common/src/main/java/io/jans/configapi/model/configuration/AuditLogConf.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 io.jans.configapi.model.configuration; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import java.util.List; | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class AuditLogConf { | ||
|
||
/** | ||
* Flag to enable and disable audit log | ||
*/ | ||
private boolean enabled; | ||
|
||
/** | ||
* List of header attributes | ||
*/ | ||
private List<String> headerAttributes; | ||
|
||
public boolean isEnabled() { | ||
return enabled; | ||
} | ||
|
||
public void setEnabled(boolean enabled) { | ||
this.enabled = enabled; | ||
} | ||
|
||
public List<String> getHeaderAttributes() { | ||
return headerAttributes; | ||
} | ||
|
||
public void setHeaderAttributes(List<String> headerAttributes) { | ||
this.headerAttributes = headerAttributes; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "AuditLogConf [enabled=" + enabled + ", headerAttributes=" + headerAttributes + "]"; | ||
} | ||
|
||
} |
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
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
121 changes: 121 additions & 0 deletions
121
jans-config-api/server/src/main/java/io/jans/configapi/interceptor/AuditLogInterceptor.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,121 @@ | ||
/* | ||
* Janssen Project software is available under the MIT License (2008). See http://opensource.org/licenses/MIT for full text. | ||
* | ||
* Copyright (c) 2020, Janssen Project | ||
*/ | ||
|
||
package io.jans.configapi.interceptor; | ||
|
||
import io.jans.configapi.core.interceptor.RequestAuditInterceptor; | ||
import io.jans.configapi.model.configuration.AuditLogConf; | ||
import io.jans.configapi.util.AuthUtil; | ||
import jakarta.annotation.Priority; | ||
import jakarta.inject.Inject; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.ws.rs.WebApplicationException; | ||
import jakarta.ws.rs.core.Context; | ||
import jakarta.ws.rs.core.HttpHeaders; | ||
import jakarta.ws.rs.core.UriInfo; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import jakarta.interceptor.AroundInvoke; | ||
import jakarta.interceptor.Interceptor; | ||
import jakarta.interceptor.InvocationContext; | ||
|
||
@Interceptor | ||
@RequestAuditInterceptor | ||
@Priority(Interceptor.Priority.APPLICATION) | ||
public class AuditLogInterceptor { | ||
|
||
private static final Logger AUDIT_LOG = LoggerFactory.getLogger("audit"); | ||
|
||
@Context | ||
UriInfo info; | ||
|
||
@Context | ||
HttpServletRequest request; | ||
|
||
@Context | ||
private HttpHeaders httpHeaders; | ||
|
||
@Inject | ||
AuthUtil authUtil; | ||
|
||
@SuppressWarnings({ "all" }) | ||
@AroundInvoke | ||
public Object aroundReadFrom(InvocationContext context) throws Exception { | ||
|
||
try { | ||
processRequest(context); | ||
|
||
} catch (Exception ex) { | ||
throw new WebApplicationException(ex); | ||
} | ||
return context.proceed(); | ||
} | ||
|
||
private void processRequest(InvocationContext context) { | ||
|
||
Object[] ctxParameters = context.getParameters(); | ||
Method method = context.getMethod(); | ||
Class[] clazzArray = method.getParameterTypes(); | ||
|
||
if (clazzArray != null && clazzArray.length > 0) { | ||
for (int i = 0; i < clazzArray.length; i++) { | ||
|
||
Object obj = ctxParameters[i]; | ||
// Audit log | ||
logAuditData(context, obj); | ||
|
||
} | ||
} | ||
} | ||
|
||
private <T> void logAuditData(InvocationContext context, T obj) { | ||
try { | ||
AuditLogConf auditLogConf = getAuditLogConf(); | ||
if (auditLogConf != null && auditLogConf.isEnabled()) { | ||
AUDIT_LOG.info("====== Request for endpoint:{}, method:{}, from:{}, user:{}, data:{} ", info.getPath(), | ||
context.getMethod(), request.getRemoteAddr(), httpHeaders.getHeaderString("User-inum"), obj); | ||
Map<String, String> attributeMap = getAuditHeaderAttributes(auditLogConf); | ||
AUDIT_LOG.info("attributeMap:{} ", attributeMap); | ||
} | ||
|
||
} catch (Exception ex) { | ||
ex.printStackTrace(); | ||
} | ||
|
||
} | ||
|
||
private AuditLogConf getAuditLogConf() { | ||
return this.authUtil.getAuditLogConf(); | ||
} | ||
|
||
private Map<String, String> getAuditHeaderAttributes(AuditLogConf auditLogConf) { | ||
|
||
if (auditLogConf == null) { | ||
return Collections.emptyMap(); | ||
} | ||
List<String> attributes = auditLogConf.getHeaderAttributes(); | ||
|
||
Map<String, String> attributeMap = null; | ||
if (attributes != null && !attributes.isEmpty()) { | ||
attributeMap = new HashMap<>(); | ||
for (String attributeName : attributes) { | ||
|
||
String attributeValue = httpHeaders.getHeaderString(attributeName); | ||
attributeMap.put(attributeName, attributeValue); | ||
} | ||
} | ||
return attributeMap; | ||
} | ||
|
||
} |
Oops, something went wrong.