Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add login failure logs #726

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.radarbase.management.security.Constants;
import org.radarbase.management.config.audit.AuditEventConverter;
import org.radarbase.management.domain.PersistentAuditEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.audit.AuditEvent;
import org.springframework.boot.actuate.audit.AuditEventRepository;
Expand All @@ -19,6 +21,7 @@
*/
@Repository
public class CustomAuditEventRepository implements AuditEventRepository {
private static final Logger logger = LoggerFactory.getLogger(CustomAuditEventRepository.class);

private static final String AUTHORIZATION_FAILURE = "AUTHORIZATION_FAILURE";

Expand All @@ -40,16 +43,19 @@ public List<AuditEvent> find(String principal, Instant after, String type) {
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void add(AuditEvent event) {
if (!AUTHORIZATION_FAILURE.equals(event.getType())
var eventType = event.getType();
if (!AUTHORIZATION_FAILURE.equals(eventType)
&& !Constants.ANONYMOUS_USER.equals(event.getPrincipal())) {

PersistentAuditEvent persistentAuditEvent = new PersistentAuditEvent();
persistentAuditEvent.setPrincipal(event.getPrincipal());
persistentAuditEvent.setAuditEventType(event.getType());
persistentAuditEvent.setAuditEventType(eventType);
persistentAuditEvent.setAuditEventDate(LocalDateTime.ofInstant(event.getTimestamp(),
ZoneId.systemDefault()));
persistentAuditEvent.setData(auditEventConverter.convertDataToStrings(event.getData()));
persistenceAuditEventRepository.save(persistentAuditEvent);
}
if (eventType != null && eventType.endsWith("_FAILURE")) {
logger.warn("Login failure: {}", event);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public TokenDTO fetchToken(String tokenName) throws MalformedURLException {
}
return result;
} else {
throw new RequestGoneException("Token already fetched or expired. ",
throw new RequestGoneException("Token " + tokenName + " already fetched or expired. ",
META_TOKEN, "error.TokenCannotBeSent");
}
}
Expand Down