Even more Replacements of the HttpRemoteLogger with the sl4j Logger (ref #223)

This commit is contained in:
George Kalampokis 2020-01-28 18:33:50 +02:00
parent 781be46031
commit 69fde5f353
9 changed files with 38 additions and 32 deletions

View File

@ -37,6 +37,6 @@ public class WebMVCConfiguration extends WebMvcConfigurerAdapter {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new RequestInterceptor(this.apiContext.getHelpersService().getLoggerService()));
// registry.addInterceptor(new RequestInterceptor(this.apiContext.getHelpersService().getLoggerService()));
}
}

View File

@ -42,7 +42,7 @@ public class Admin extends BaseController {
private ConfigLoader configLoader;
@Autowired
public Admin(ApiContext apiContext, DatasetProfileManager datasetProfileManager, UserManager userManager, Logger logger, ConfigLoader configLoader) {
public Admin(ApiContext apiContext, DatasetProfileManager datasetProfileManager, UserManager userManager/*, Logger logger*/, ConfigLoader configLoader) {
super(apiContext);
this.datasetProfileManager = datasetProfileManager;
this.userManager = userManager;

View File

@ -9,7 +9,7 @@ import org.springframework.web.bind.annotation.InitBinder;
public abstract class BaseController {
private Logger logger;
/*private Logger logger;*/
private ApiContext apiContext;
@ -17,9 +17,9 @@ public abstract class BaseController {
return apiContext;
}
public Logger getLoggerService() {
/*public Logger getLoggerService() {
return logger;
}
}*/
public BaseController(ApiContext apiContext) {

View File

@ -1,6 +1,6 @@
package eu.eudat.controllers;
import eu.eudat.core.logger.Logger;
import eu.eudat.exceptions.security.NullEmailException;
import eu.eudat.logic.managers.UserManager;
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
@ -28,6 +28,8 @@ import eu.eudat.models.data.login.Credentials;
import eu.eudat.models.data.login.LoginInfo;
import eu.eudat.models.data.security.Principal;
import eu.eudat.types.ApiMessageCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@ -42,6 +44,7 @@ import java.security.GeneralSecurityException;
@CrossOrigin
@RequestMapping(value = "api/auth")
public class Login {
private static final Logger logger = LoggerFactory.getLogger(Login.class);
private CustomAuthenticationProvider customAuthenticationProvider;
private AuthenticationService nonVerifiedUserAuthenticationService;
@ -53,13 +56,13 @@ public class Login {
private ConfigurableProviderTokenValidator configurableProviderTokenValidator;
private ConfigLoader configLoader;
private Logger logger;
// private Logger logger;
private UserManager userManager;
@Autowired
public Login(CustomAuthenticationProvider customAuthenticationProvider, AuthenticationService nonVerifiedUserAuthenticationService,
TwitterTokenValidator twitterTokenValidator, LinkedInTokenValidator linkedInTokenValidator, B2AccessTokenValidator b2AccessTokenValidator,
ORCIDTokenValidator orcidTokenValidator, OpenAIRETokenValidator openAIRETokenValidator, ConfigurableProviderTokenValidator configurableProviderTokenValidator, ConfigLoader configLoader, UserManager userManager, Logger logger) {
ORCIDTokenValidator orcidTokenValidator, OpenAIRETokenValidator openAIRETokenValidator, ConfigurableProviderTokenValidator configurableProviderTokenValidator, ConfigLoader configLoader, UserManager userManager/*, Logger logger*/) {
this.customAuthenticationProvider = customAuthenticationProvider;
this.nonVerifiedUserAuthenticationService = nonVerifiedUserAuthenticationService;
this.twitterTokenValidator = twitterTokenValidator;
@ -69,7 +72,7 @@ public class Login {
this.openAIRETokenValidator = openAIRETokenValidator;
this.configurableProviderTokenValidator = configurableProviderTokenValidator;
this.configLoader = configLoader;
this.logger = logger;
// this.logger = logger;
this.userManager = userManager;
}
@ -77,7 +80,7 @@ public class Login {
@RequestMapping(method = RequestMethod.POST, value = {"/externallogin"}, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<Principal>> externallogin(@RequestBody LoginInfo credentials) throws GeneralSecurityException, NullEmailException {
this.logger.info(credentials, "Trying To Login With " + credentials.getProvider());
logger.info("Trying To Login With " + credentials.getProvider());
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Principal>().payload(customAuthenticationProvider.authenticate(credentials)).status(ApiMessageCode.SUCCESS_MESSAGE));
}
@ -85,7 +88,7 @@ public class Login {
@RequestMapping(method = RequestMethod.POST, value = {"/nativelogin"}, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<Principal>> nativelogin(@RequestBody Credentials credentials) throws NullEmailException {
this.logger.info(credentials.getUsername(), "Trying To Login");
logger.info(credentials.getUsername() + " Trying To Login");
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Principal>().payload(userManager.authenticate(this.nonVerifiedUserAuthenticationService, credentials)).status(ApiMessageCode.SUCCESS_MESSAGE));
}
@ -128,7 +131,7 @@ public class Login {
@RequestMapping(method = RequestMethod.POST, value = {"/me"}, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<Principal>> authMe(Principal principal) throws NullEmailException {
this.logger.info(principal, "Getting Me");
logger.info(principal + " Getting Me");
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Principal>().payload(this.nonVerifiedUserAuthenticationService.Touch(principal.getToken())).status(ApiMessageCode.NO_MESSAGE));
}
@ -137,7 +140,7 @@ public class Login {
public @ResponseBody
ResponseEntity<ResponseItem<Principal>> logout(Principal principal) {
this.nonVerifiedUserAuthenticationService.Logout(principal.getToken());
this.logger.info(principal, "Logged Out");
logger.info(principal + " Logged Out");
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Principal>().status(ApiMessageCode.NO_MESSAGE));
}

View File

@ -1,7 +1,8 @@
package eu.eudat.controllers.controllerhandler;
import eu.eudat.core.logger.Logger;
import eu.eudat.exceptions.security.UnauthorisedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
@ -18,19 +19,19 @@ import javax.annotation.Priority;
@ControllerAdvice
@Priority(4)
public class ControllerUnauthorisedHandler {
private Logger logger;
private static final Logger logger = LoggerFactory.getLogger(ControllerUnauthorisedHandler.class);
// private Logger logger;
@Autowired
public ControllerUnauthorisedHandler(Logger logger) {
this.logger = logger;
public ControllerUnauthorisedHandler(/*Logger logger*/) {
// this.logger = logger;
}
@ExceptionHandler(UnauthorisedException.class)
@ResponseStatus(HttpStatus.UNAUTHORIZED)
@ResponseBody
public void processValidationError(UnauthorisedException ex) {
this.logger.error(ex, ex.getMessage());
logger.error(ex.getMessage(), ex);
return;
}
}

View File

@ -2,6 +2,8 @@ package eu.eudat.controllers.interceptors;
import eu.eudat.logic.services.helpers.LoggerService;
import eu.eudat.types.WarningLevel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
@ -15,19 +17,19 @@ import java.util.Date;
*/
@Component
public class RequestInterceptor extends HandlerInterceptorAdapter {
private LoggerService loggerService;
private static final Logger logger = LoggerFactory.getLogger(RequestInterceptor.class);
// private LoggerService loggerService;
@Autowired
public RequestInterceptor(LoggerService loggerService) {
this.loggerService = loggerService;
public RequestInterceptor(/*LoggerService loggerService*/) {
// this.loggerService = loggerService;
}
@Override
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler) throws Exception {
String reqUri = request.getRequestURI();
this.loggerService.log("Call to " + reqUri + " method: " + request.getMethod() + " at: " + new Date(), WarningLevel.INFO);
logger.info("Call to " + reqUri + " method: " + request.getMethod() + " at: " + new Date(), WarningLevel.INFO);
return super.preHandle(request, response, handler);
}
}

View File

@ -9,5 +9,5 @@ public interface HelpersService {
MessageSource getMessageSource();
LoggerService getLoggerService();
// LoggerService getLoggerService();
}

View File

@ -11,12 +11,12 @@ import org.springframework.stereotype.Service;
public class HelpersServiceImpl implements HelpersService {
private MessageSource messageSource;
private LoggerService loggerService;
// private LoggerService loggerService;
@Autowired
public HelpersServiceImpl(MessageSource messageSource, LoggerService loggerService) {
public HelpersServiceImpl(MessageSource messageSource/*, LoggerService loggerService*/) {
this.messageSource = messageSource;
this.loggerService = loggerService;
// this.loggerService = loggerService;
}
@Override
@ -24,8 +24,8 @@ public class HelpersServiceImpl implements HelpersService {
return messageSource;
}
@Override
/*@Override
public LoggerService getLoggerService() {
return loggerService;
}
}*/
}

View File

@ -12,7 +12,7 @@ import java.util.Map;
/**
* Created by ikalyvas on 3/1/2018.
*/
@Service("loggerService")
//@Service("loggerService")
public class LoggerServiceImpl implements LoggerService {
private Logger logger;
private WarningLevel level;
@ -22,7 +22,7 @@ public class LoggerServiceImpl implements LoggerService {
this.level = level;
}
@Autowired
// @Autowired
public LoggerServiceImpl(Logger logger) {
this.logger = logger;
this.options.put(WarningLevel.DEBUG, (log, message) -> log.debug(message));