Add manual addition of total users in prometheus
This commit is contained in:
parent
3b76397c24
commit
5019bc4271
|
@ -8,12 +8,14 @@ import eu.eudat.exceptions.security.NullEmailException;
|
|||
import eu.eudat.logic.builders.entity.CredentialBuilder;
|
||||
import eu.eudat.logic.builders.entity.UserInfoBuilder;
|
||||
import eu.eudat.logic.builders.entity.UserTokenBuilder;
|
||||
import eu.eudat.logic.managers.MetricsManager;
|
||||
import eu.eudat.logic.security.validators.TokenValidatorFactoryImpl;
|
||||
import eu.eudat.logic.services.ApiContext;
|
||||
import eu.eudat.models.data.login.Credentials;
|
||||
import eu.eudat.models.data.loginprovider.LoginProviderUser;
|
||||
import eu.eudat.models.data.security.Principal;
|
||||
import eu.eudat.types.Authorities;
|
||||
import eu.eudat.types.MetricNames;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -30,10 +32,12 @@ public abstract class AbstractAuthenticationService implements AuthenticationSer
|
|||
|
||||
protected ApiContext apiContext;
|
||||
protected Environment environment;
|
||||
protected MetricsManager metricsManager;
|
||||
|
||||
public AbstractAuthenticationService(ApiContext apiContext, Environment environment) {
|
||||
public AbstractAuthenticationService(ApiContext apiContext, Environment environment, MetricsManager metricsManager) {
|
||||
this.apiContext = apiContext;
|
||||
this.environment = environment;
|
||||
this.metricsManager = metricsManager;
|
||||
}
|
||||
|
||||
protected Date addADay(Date date) {
|
||||
|
@ -91,6 +95,7 @@ public abstract class AbstractAuthenticationService implements AuthenticationSer
|
|||
if (credential == null && credentials.getUsername().equals(environment.getProperty("autouser.root.username"))) {
|
||||
try {
|
||||
credential = this.autoCreateUser(credentials.getUsername(), credentials.getSecret());
|
||||
metricsManager.increaseValue(MetricNames.USERS, 1, MetricNames.TOTAL);
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
return null;
|
||||
|
@ -162,7 +167,7 @@ public abstract class AbstractAuthenticationService implements AuthenticationSer
|
|||
role.setRole(Authorities.USER.getValue());
|
||||
role.setUserInfo(userInfo);
|
||||
apiContext.getOperationsContext().getDatabaseRepository().getUserRoleDao().createOrUpdate(role);
|
||||
|
||||
metricsManager.increaseValue(MetricNames.USERS, 1, MetricNames.TOTAL);
|
||||
} else {
|
||||
Map<String, Object> additionalInfo = userInfo.getAdditionalinfo() != null ?
|
||||
new JSONObject(userInfo.getAdditionalinfo()).toMap() : new HashMap<>();
|
||||
|
|
|
@ -5,6 +5,7 @@ import eu.eudat.data.entities.UserInfo;
|
|||
import eu.eudat.data.entities.UserRole;
|
||||
import eu.eudat.data.entities.UserToken;
|
||||
import eu.eudat.logic.builders.model.models.PrincipalBuilder;
|
||||
import eu.eudat.logic.managers.MetricsManager;
|
||||
import eu.eudat.logic.services.ApiContext;
|
||||
import eu.eudat.models.data.security.Principal;
|
||||
import eu.eudat.types.Authorities;
|
||||
|
@ -19,8 +20,8 @@ import java.util.List;
|
|||
@Service("nonVerifiedUserAuthenticationService")
|
||||
public class NonVerifiedUserEmailAuthenticationService extends AbstractAuthenticationService {
|
||||
|
||||
public NonVerifiedUserEmailAuthenticationService(ApiContext apiContext, Environment environment) {
|
||||
super(apiContext, environment);
|
||||
public NonVerifiedUserEmailAuthenticationService(ApiContext apiContext, Environment environment, MetricsManager metricsManager) {
|
||||
super(apiContext, environment, metricsManager);
|
||||
}
|
||||
|
||||
public Principal Touch(UserToken token) {
|
||||
|
|
|
@ -10,6 +10,7 @@ import eu.eudat.logic.builders.entity.CredentialBuilder;
|
|||
import eu.eudat.logic.builders.entity.UserInfoBuilder;
|
||||
import eu.eudat.logic.builders.entity.UserTokenBuilder;
|
||||
import eu.eudat.logic.builders.model.models.PrincipalBuilder;
|
||||
import eu.eudat.logic.managers.MetricsManager;
|
||||
import eu.eudat.logic.security.validators.TokenValidatorFactoryImpl;
|
||||
import eu.eudat.logic.services.ApiContext;
|
||||
import eu.eudat.models.data.login.Credentials;
|
||||
|
@ -27,8 +28,8 @@ import java.util.*;
|
|||
@Service("verifiedUserAuthenticationService")
|
||||
public class VerifiedUserAuthenticationService extends AbstractAuthenticationService {
|
||||
|
||||
public VerifiedUserAuthenticationService(ApiContext apiContext, Environment environment) {
|
||||
super(apiContext, environment);
|
||||
public VerifiedUserAuthenticationService(ApiContext apiContext, Environment environment, MetricsManager metricsManager) {
|
||||
super(apiContext, environment, metricsManager);
|
||||
}
|
||||
|
||||
public Principal Touch(UserToken token) {
|
||||
|
|
Loading…
Reference in New Issue