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 @Override
public void addInterceptors(InterceptorRegistry registry) { 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; private ConfigLoader configLoader;
@Autowired @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); super(apiContext);
this.datasetProfileManager = datasetProfileManager; this.datasetProfileManager = datasetProfileManager;
this.userManager = userManager; this.userManager = userManager;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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