Skip to content

Commit

Permalink
Redirect logs outside of console (#78)
Browse files Browse the repository at this point in the history
* Redirect logs outside of console

* Log user log in and authorities.
  • Loading branch information
KFilippopolitis authored Jul 4, 2024
1 parent 3e1bfd7 commit 04c18a4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
2 changes: 2 additions & 0 deletions config/application.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ logging:
root: {{ default .Env.LOG_LEVEL_FRAMEWORK "ERROR" }}
eu:
hbp: {{ default .Env.LOG_LEVEL "INFO" }}
file:
name: /var/log/portalbackend/portalbackend.log


### DATABASE CONFIGURATION ###
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package hbp.mip.configurations;

import hbp.mip.utils.Logger;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.security.authentication.event.AuthenticationSuccessEvent;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class AuthenticationEventListener {

@EventListener
public void handleAuthenticationSuccess(AuthenticationSuccessEvent event) {
Authentication authentication = event.getAuthentication();
String username = authentication.getName();
Logger logger = new Logger(username, "LOGGING IN");
logger.info("User " + username + " has logged in successfully");

// If you need to log additional details:
authentication.getAuthorities().forEach(authority ->
logger.info("User " + username + " has authority " + authority.getAuthority())
);
}
}
8 changes: 2 additions & 6 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
# Configuration for development purposes


### EMBEDDED SERVER CONFIGURATION ###
server:
servlet:
contextPath: "/services"
port: 8080
forward-headers-strategy: native


### LOG LEVELS ###
logging:
level:
root: "INFO"
eu:
hbp: "DEBUG"

file:
name: /var/log/portalbackend/portalbackend.log

### DATABASE CONFIGURATION ###
spring:
Expand Down Expand Up @@ -51,15 +50,13 @@ spring:
user-name-attribute: preferred_username
issuer-uri: http://172.17.0.1/auth/realms/MIP


### AUTHENTICATION ###
authentication:
enabled: 0
all_datasets_allowed_claim: research_dataset_all
all_experiments_allowed_claim: research_experiment_all
dataset_claim_prefix: research_dataset_


### EXTERNAL SERVICES ###
services:
algorithmsUpdateInterval: 100
Expand All @@ -68,7 +65,6 @@ services:
attributesUrl: "http://127.0.0.1:5000/data_models_attributes"
cdesMetadataUrl: "http://127.0.0.1:5000/cdes_metadata"


### EXTERNAL FILES ###
# Files are loaded from the resources
files:
Expand Down

0 comments on commit 04c18a4

Please sign in to comment.