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.
Add status option to kcadm for validity (keycloak#32883)
Closes keycloak#23179 Signed-off-by: Keshav Deshpande <[email protected]>
- Loading branch information
1 parent
89ed021
commit 4e23b45
Showing
3 changed files
with
40 additions
and
4 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 |
---|---|---|
|
@@ -19,8 +19,16 @@ | |
import org.keycloak.client.admin.cli.KcAdmMain; | ||
import org.keycloak.client.cli.common.BaseConfigCredentialsCmd; | ||
|
||
import org.keycloak.client.cli.config.ConfigData; | ||
import picocli.CommandLine; | ||
import picocli.CommandLine.Command; | ||
|
||
import static java.lang.System.currentTimeMillis; | ||
import static org.keycloak.client.cli.util.AuthUtil.AUTH_BUFFER_TIME; | ||
import static org.keycloak.client.cli.util.ConfigUtil.credentialsAvailable; | ||
import static org.keycloak.client.cli.util.ConfigUtil.loadConfig; | ||
import static org.keycloak.client.cli.util.IoUtil.printOut; | ||
|
||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Marko Strukelj</a> | ||
|
@@ -32,4 +40,26 @@ public ConfigCredentialsCmd() { | |
super(KcAdmMain.COMMAND_STATE); | ||
} | ||
|
||
@CommandLine.Option(names = "--status", description = "Validity of the connection with server") | ||
boolean status; | ||
|
||
@Override | ||
protected boolean nothingToDo() { | ||
return super.nothingToDo() && !status; | ||
} | ||
|
||
@Override | ||
public void process() { | ||
if (status) { | ||
ConfigData config = loadConfig(); | ||
long now = currentTimeMillis(); | ||
if (credentialsAvailable(config) && now + AUTH_BUFFER_TIME < config.sessionRealmConfigData().getExpiresAt()) { | ||
printOut("Logged in (server: " + config.getServerUrl() + ", realm: " + config.getRealm() + ", expired: false, timeToExpiry: " + (config.sessionRealmConfigData().getExpiresAt() - now) / 1000 + "s from now)"); | ||
} else { | ||
printOut("You are not logged in"); | ||
} | ||
} else { | ||
super.process(); | ||
} | ||
} | ||
} |
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