forked from keycloak/keycloak
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added event listener for temporary admin account logging
Signed-off-by: Peter Zaoral <[email protected]>
- Loading branch information
Showing
7 changed files
with
97 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,8 +33,6 @@ | |
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import static org.keycloak.services.managers.ApplianceBootstrap.TEMP_ADMIN_ATTR_NAME; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Marek Posolda</a> | ||
*/ | ||
|
@@ -98,9 +96,6 @@ public Response processFlow() { | |
} | ||
|
||
logger.debugv("Client {0} authenticated by {1}", client.getClientId(), factory.getId()); | ||
if (Boolean.parseBoolean(client.getAttribute(TEMP_ADMIN_ATTR_NAME))) { | ||
logger.warn(client.getClientId() + " is a temporary admin service account. To harden security, create a permanent account and delete the temporary one."); | ||
} | ||
processor.getEvent().detail(Details.CLIENT_AUTH_METHOD, factory.getId()); | ||
return null; | ||
} | ||
|
51 changes: 51 additions & 0 deletions
51
...ces/src/main/java/org/keycloak/events/log/TemporaryAdminAccountEventListenerProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package org.keycloak.events.log; | ||
|
||
import org.jboss.logging.Logger; | ||
import org.keycloak.events.Event; | ||
import org.keycloak.events.EventListenerProvider; | ||
import org.keycloak.events.EventType; | ||
import org.keycloak.events.admin.AdminEvent; | ||
import org.keycloak.models.ClientModel; | ||
import org.keycloak.models.KeycloakSession; | ||
import org.keycloak.models.RealmModel; | ||
import org.keycloak.models.RealmProvider; | ||
import org.keycloak.models.UserModel; | ||
|
||
import static org.keycloak.services.managers.ApplianceBootstrap.TEMP_ADMIN_ATTR_NAME; | ||
|
||
public class TemporaryAdminAccountEventListenerProvider implements EventListenerProvider { | ||
|
||
private static final Logger log = Logger.getLogger(TemporaryAdminAccountEventListenerProvider.class); | ||
|
||
private final KeycloakSession session; | ||
private final RealmProvider realmModel; | ||
|
||
public TemporaryAdminAccountEventListenerProvider(KeycloakSession session) { | ||
this.session = session; | ||
this.realmModel = session.realms(); | ||
} | ||
|
||
@Override | ||
public void onEvent(Event event) { | ||
RealmModel realm = this.realmModel.getRealm(event.getRealmId()); | ||
UserModel user = this.session.users().getUserById(realm, event.getUserId()); | ||
ClientModel client = this.session.clients().getClientByClientId(realm, event.getClientId()); | ||
|
||
if (EventType.LOGIN.equals(event.getType()) && Boolean.parseBoolean(user.getFirstAttribute(TEMP_ADMIN_ATTR_NAME))) { | ||
log.warn(user.getUsername() + " is a temporary admin user account. To harden security, create a permanent account and delete the temporary one."); | ||
} | ||
|
||
if (EventType.CLIENT_LOGIN.equals(event.getType()) && Boolean.parseBoolean(client.getAttribute(TEMP_ADMIN_ATTR_NAME))) { | ||
log.warn(client.getClientId() + " is a temporary admin service account. To harden security, create a permanent account and delete the temporary one."); | ||
} | ||
} | ||
|
||
@Override | ||
public void onEvent(AdminEvent adminEvent, boolean b) { | ||
} | ||
|
||
@Override | ||
public void close() { | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
.../main/java/org/keycloak/events/log/TemporaryAdminAccountEventListenerProviderFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.keycloak.events.log; | ||
|
||
import org.keycloak.Config; | ||
import org.keycloak.events.EventListenerProvider; | ||
import org.keycloak.events.EventListenerProviderFactory; | ||
import org.keycloak.models.KeycloakSession; | ||
import org.keycloak.models.KeycloakSessionFactory; | ||
|
||
public class TemporaryAdminAccountEventListenerProviderFactory implements EventListenerProviderFactory { | ||
|
||
public static final String ID = "temp-admin-account"; | ||
|
||
@Override | ||
public EventListenerProvider create(KeycloakSession keycloakSession) { | ||
return new TemporaryAdminAccountEventListenerProvider(keycloakSession); | ||
} | ||
|
||
@Override | ||
public void init(Config.Scope scope) { | ||
|
||
} | ||
|
||
@Override | ||
public void postInit(KeycloakSessionFactory keycloakSessionFactory) { | ||
|
||
} | ||
|
||
@Override | ||
public void close() { | ||
|
||
} | ||
|
||
@Override | ||
public String getId() { | ||
return ID; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters