[New] Added audits for login and logout
This commit is contained in:
parent
e123cbf47d
commit
9ca7b5f26f
|
@ -22,7 +22,11 @@ import java.util.Map;
|
||||||
|
|
||||||
import li.strolch.agent.api.ComponentContainer;
|
import li.strolch.agent.api.ComponentContainer;
|
||||||
import li.strolch.agent.api.StrolchComponent;
|
import li.strolch.agent.api.StrolchComponent;
|
||||||
|
import li.strolch.agent.api.StrolchRealm;
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
|
import li.strolch.model.audit.AccessType;
|
||||||
|
import li.strolch.model.audit.Audit;
|
||||||
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
import li.strolch.runtime.configuration.ComponentConfiguration;
|
import li.strolch.runtime.configuration.ComponentConfiguration;
|
||||||
import li.strolch.runtime.configuration.RuntimeConfiguration;
|
import li.strolch.runtime.configuration.RuntimeConfiguration;
|
||||||
import ch.eitchnet.privilege.base.AccessDeniedException;
|
import ch.eitchnet.privilege.base.AccessDeniedException;
|
||||||
|
@ -110,7 +114,15 @@ public class DefaultStrolchPrivilegeHandler extends StrolchComponent implements
|
||||||
public Certificate authenticate(String username, byte[] password) {
|
public Certificate authenticate(String username, byte[] password) {
|
||||||
assertContainerStarted();
|
assertContainerStarted();
|
||||||
try {
|
try {
|
||||||
return this.privilegeHandler.authenticate(username, password);
|
Certificate certificate = this.privilegeHandler.authenticate(username, password);
|
||||||
|
StrolchRealm realm = getContainer().getRealm(certificate);
|
||||||
|
try (StrolchTransaction tx = realm.openTx(certificate, getClass())) {
|
||||||
|
tx.setSuppressDoNothingLogging(true);
|
||||||
|
tx.setSuppressAudits(true);
|
||||||
|
Audit audit = tx.auditFrom(AccessType.CREATE, Certificate.class.getSimpleName(), username);
|
||||||
|
tx.getAuditTrail().add(tx, audit);
|
||||||
|
}
|
||||||
|
return certificate;
|
||||||
} catch (AccessDeniedException e) {
|
} catch (AccessDeniedException e) {
|
||||||
throw new StrolchException("Authentication credentials are invalid", e); //$NON-NLS-1$
|
throw new StrolchException("Authentication credentials are invalid", e); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
@ -131,7 +143,15 @@ public class DefaultStrolchPrivilegeHandler extends StrolchComponent implements
|
||||||
@Override
|
@Override
|
||||||
public boolean invalidateSession(Certificate certificate) {
|
public boolean invalidateSession(Certificate certificate) {
|
||||||
assertContainerStarted();
|
assertContainerStarted();
|
||||||
return this.privilegeHandler.invalidateSession(certificate);
|
boolean invalidateSession = this.privilegeHandler.invalidateSession(certificate);
|
||||||
|
StrolchRealm realm = getContainer().getRealm(certificate);
|
||||||
|
try (StrolchTransaction tx = realm.openTx(certificate, getClass())) {
|
||||||
|
tx.setSuppressDoNothingLogging(true);
|
||||||
|
tx.setSuppressAudits(true);
|
||||||
|
Audit audit = tx.auditFrom(AccessType.DELETE, Certificate.class.getSimpleName(), certificate.getUsername());
|
||||||
|
tx.getAuditTrail().add(tx, audit);
|
||||||
|
}
|
||||||
|
return invalidateSession;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue