mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Add user log context to user handler (#97)
Co-authored-by: pramilaniroshan <pramila@entgra.io> Reviewed-on: https://repository.entgra.net/community/device-mgt-core/pulls/97 Co-authored-by: Pramila Niroshan <pramila@entgra.io> Co-committed-by: Pramila Niroshan <pramila@entgra.io>
This commit is contained in:
parent
7f5137712c
commit
b4d5babd93
@ -25,12 +25,18 @@ public class UserLogContext extends LogContext {
|
|||||||
private final String userEmail;
|
private final String userEmail;
|
||||||
private final String metaInfo;
|
private final String metaInfo;
|
||||||
private final String tenantID;
|
private final String tenantID;
|
||||||
|
private final boolean isUserRegistered;
|
||||||
|
private final boolean isDeviceRegisterged;
|
||||||
|
private final String tenantDomain;
|
||||||
|
|
||||||
private UserLogContext(Builder builder) {
|
private UserLogContext(Builder builder) {
|
||||||
this.userEmail = builder.userEmail;
|
this.userEmail = builder.userEmail;
|
||||||
this.userName = builder.userName;
|
this.userName = builder.userName;
|
||||||
this.metaInfo = builder.metaInfo;
|
this.metaInfo = builder.metaInfo;
|
||||||
this.tenantID = builder.tenantID;
|
this.tenantID = builder.tenantID;
|
||||||
|
this.isUserRegistered = builder.isUserRegistered;
|
||||||
|
this.isDeviceRegisterged = builder.isDeviceRegisterged;
|
||||||
|
this.tenantDomain = builder.tenantDomain;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTenantID() {
|
public String getTenantID() {
|
||||||
@ -49,12 +55,26 @@ public class UserLogContext extends LogContext {
|
|||||||
return metaInfo;
|
return metaInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isUserRegistered() {
|
||||||
|
return isUserRegistered;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDeviceRegisterged() {
|
||||||
|
return isDeviceRegisterged;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTenantDomain() {
|
||||||
|
return tenantDomain;
|
||||||
|
}
|
||||||
|
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
private String userName;
|
private String userName;
|
||||||
private String userEmail;
|
private String userEmail;
|
||||||
private String metaInfo;
|
private String metaInfo;
|
||||||
private String tenantID;
|
private String tenantID;
|
||||||
|
private boolean isUserRegistered;
|
||||||
|
private boolean isDeviceRegisterged;
|
||||||
|
private String tenantDomain;
|
||||||
|
|
||||||
public Builder() {
|
public Builder() {
|
||||||
}
|
}
|
||||||
@ -95,6 +115,33 @@ public class UserLogContext extends LogContext {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getIsUserRegistered() {
|
||||||
|
return isUserRegistered;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setUserRegistered(boolean userRegistered) {
|
||||||
|
isUserRegistered = userRegistered;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getIsDeviceRegisterged() {
|
||||||
|
return isDeviceRegisterged;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setDeviceRegisterged(boolean deviceRegisterged) {
|
||||||
|
isDeviceRegisterged = deviceRegisterged;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTenantDomain() {
|
||||||
|
return tenantDomain;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setTenantDomain(String tenantDomain) {
|
||||||
|
this.tenantDomain = tenantDomain;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public UserLogContext build() {
|
public UserLogContext build() {
|
||||||
return new UserLogContext(this);
|
return new UserLogContext(this);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -51,6 +51,16 @@ public final class MDCContextUtil {
|
|||||||
if (mdcContext.getTenantID() != null) {
|
if (mdcContext.getTenantID() != null) {
|
||||||
MDC.put("TenantId", mdcContext.getTenantID());
|
MDC.put("TenantId", mdcContext.getTenantID());
|
||||||
}
|
}
|
||||||
|
if (mdcContext.isUserRegistered()) {
|
||||||
|
MDC.put("IsUserRegistered", "Registered");
|
||||||
|
}
|
||||||
|
if (mdcContext.isDeviceRegisterged()) {
|
||||||
|
MDC.put("IsDeviceRegistered", mdcContext.isDeviceRegisterged());
|
||||||
|
}
|
||||||
|
if (mdcContext.getTenantDomain() != null) {
|
||||||
|
MDC.put("TenantDomain", mdcContext.getTenantDomain());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -22,11 +22,12 @@ import com.google.gson.JsonElement;
|
|||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
import com.google.gson.JsonSyntaxException;
|
import com.google.gson.JsonSyntaxException;
|
||||||
|
import io.entgra.device.mgt.extensions.logger.spi.EntgraLogger;
|
||||||
|
import io.entgra.notification.logger.UserLogContext;
|
||||||
|
import io.entgra.notification.logger.impl.EntgraUserLoggerImpl;
|
||||||
import io.entgra.ui.request.interceptor.beans.AuthData;
|
import io.entgra.ui.request.interceptor.beans.AuthData;
|
||||||
import io.entgra.ui.request.interceptor.util.HandlerConstants;
|
import io.entgra.ui.request.interceptor.util.HandlerConstants;
|
||||||
import io.entgra.ui.request.interceptor.util.HandlerUtil;
|
import io.entgra.ui.request.interceptor.util.HandlerUtil;
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.apache.http.HttpHeaders;
|
import org.apache.http.HttpHeaders;
|
||||||
import org.apache.http.HttpStatus;
|
import org.apache.http.HttpStatus;
|
||||||
import org.apache.http.client.methods.HttpPost;
|
import org.apache.http.client.methods.HttpPost;
|
||||||
@ -48,7 +49,8 @@ import java.util.Base64;
|
|||||||
@MultipartConfig
|
@MultipartConfig
|
||||||
@WebServlet("/user")
|
@WebServlet("/user")
|
||||||
public class UserHandler extends HttpServlet {
|
public class UserHandler extends HttpServlet {
|
||||||
private static final Log log = LogFactory.getLog(UserHandler.class);
|
private static final EntgraLogger log = new EntgraUserLoggerImpl(UserHandler.class);
|
||||||
|
UserLogContext.Builder userLogContextBuilder = new UserLogContext.Builder();
|
||||||
private static final long serialVersionUID = 9050048549140517002L;
|
private static final long serialVersionUID = 9050048549140517002L;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -118,6 +120,7 @@ public class UserHandler extends HttpServlet {
|
|||||||
proxyResponse.setData(
|
proxyResponse.setData(
|
||||||
jTokenResultAsJsonObject.get("username").getAsString().replaceAll("@carbon.super", ""));
|
jTokenResultAsJsonObject.get("username").getAsString().replaceAll("@carbon.super", ""));
|
||||||
HandlerUtil.handleSuccess(resp, proxyResponse);
|
HandlerUtil.handleSuccess(resp, proxyResponse);
|
||||||
|
log.info("Customer login", userLogContextBuilder.setUserName(proxyResponse.getData()).setUserRegistered(true).build());
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("Error occurred while sending the response into the socket. ", e);
|
log.error("Error occurred while sending the response into the socket. ", e);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user