This commit is contained in:
Bill Burke 2018-03-19 16:47:13 -04:00
parent 4bba11cd94
commit 8926837a3e
5 changed files with 36 additions and 39 deletions

View file

@ -84,38 +84,19 @@ public class KcinitDriver {
public void mainCmd(String[] args) throws Exception {
this.args = Arrays.copyOf(args, args.length);
for (String arg : args) {
if (!arg.startsWith("-")) break;
if (arg.equals("-f") || arg.equals("-force")) {
forceLogin = true;
this.args = Arrays.copyOfRange(this.args, 1, this.args.length);
} else if (arg.equals("-browser") || arg.equals("-b")) {
browserLogin = true;
this.args = Arrays.copyOfRange(this.args, 1, this.args.length);
} else {
System.err.println("Illegal argument: " + arg);
printHelp();
System.exit(1);
}
}
this.args = args;
if (args.length == 0) {
login();
return;
}
if (args[0].startsWith("-")) {
login();
printHelp();
return;
}
if (args[0].equalsIgnoreCase("token")) {
//System.err.println("executing token");
token();
} else if (args[0].equalsIgnoreCase("login")) {
login();
} else if (args[0].equalsIgnoreCase("logout")) {
logout();
} else if (args[0].equalsIgnoreCase("env")) {
@ -402,8 +383,7 @@ public class KcinitDriver {
public void printHelp() {
KeycloakInstalled.console().writer().println("Commands:");
KeycloakInstalled.console().writer().println(" no arguments is a login");
KeycloakInstalled.console().writer().println(" no argument with -f forces login");
KeycloakInstalled.console().writer().println(" login [-f] -f forces login");
KeycloakInstalled.console().writer().println(" logout");
KeycloakInstalled.console().writer().println(" token [client] - print access token of desired client. Defaults to default master client. Will print either 'error', 'not-allowed', or 'login-required' on error.");
KeycloakInstalled.console().writer().println(" install - Install this utility. Will store in $HOME/.keycloak/kcinit unless " + KC_LOGIN_CONFIG_PATH + " env var is set");
@ -647,8 +627,23 @@ public class KcinitDriver {
public void login() throws Exception {
checkEnv();
this.args = Arrays.copyOfRange(this.args, 1, this.args.length);
for (String arg : args) {
if (arg.equals("-f") || arg.equals("-force")) {
forceLogin = true;
this.args = Arrays.copyOfRange(this.args, 1, this.args.length);
} else if (arg.equals("-browser") || arg.equals("-b")) {
browserLogin = true;
this.args = Arrays.copyOfRange(this.args, 1, this.args.length);
} else {
System.err.println("Illegal argument: " + arg);
printHelp();
System.exit(1);
}
}
String masterClient = getMasterClient();
if (!forceLogin() && readToken(masterClient) != null) {
if (!forceLogin && readToken(masterClient) != null) {
KeycloakInstalled.console().writer().println("Already logged in. `kcinit -f` to force relogin");
return;
}

View file

@ -462,8 +462,6 @@ public class KeycloakInstalled {
//System.err.println("initial request");
Response response = client.target(authUrl).request().get();
while (true) {
System.err.println("looping");
if (response.getStatus() == 403) {
if (response.getMediaType() != null) {
String splash = response.readEntity(String.class);
@ -471,6 +469,7 @@ public class KeycloakInstalled {
} else {
System.err.println("Forbidden to login");
}
return false;
} else if (response.getStatus() == 401) {
String authenticationHeader = response.getHeaderString(HttpHeaders.WWW_AUTHENTICATE);
if (authenticationHeader == null) {

View file

@ -164,12 +164,11 @@ public class LogoutEndpoint {
*
* returns 204 if successful, 400 if not with a json error response.
*
* @param authorizationHeader
* @return
*/
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response logoutToken(final @HeaderParam(HttpHeaders.AUTHORIZATION) String authorizationHeader) {
public Response logoutToken() {
MultivaluedMap<String, String> form = request.getDecodedFormParameters();
checkSsl();

View file

@ -125,7 +125,7 @@ public class KcinitTest extends AbstractTestRealmKeycloakTest {
UserModel user = session.users().addUser(realm, "bburke");
session.userCredentialManager().updateCredential(realm, user, UserCredentialModel.password("password"));
user.setEnabled(true);
user.setEmail("patriot1burke@gmail.com");
user.setEmail("p@p.com");
user.addRequiredAction(UserModel.RequiredAction.UPDATE_PASSWORD);
user.addRequiredAction(UserModel.RequiredAction.CONFIGURE_TOTP);
user.addRequiredAction(UserModel.RequiredAction.VERIFY_EMAIL);
@ -151,7 +151,7 @@ public class KcinitTest extends AbstractTestRealmKeycloakTest {
smtp.put("replyTo", "reply-to@keycloak.org");
smtp.put("ssl", "true");
smtp.put("auth", "true");
smtp.put("user", "****");
smtp.put("user", "*****");
smtp.put("password", "****");
realm.setSmtpConfig(smtp);
@ -194,7 +194,7 @@ public class KcinitTest extends AbstractTestRealmKeycloakTest {
testInstall();
// login
KcinitExec exe = KcinitExec.newBuilder()
.argsLine("")
.argsLine("login")
.executeAsync();
exe.waitForStderr("Username:");
exe.sendLine("wburke");
@ -258,7 +258,7 @@ public class KcinitTest extends AbstractTestRealmKeycloakTest {
testInstall();
KcinitExec exe = KcinitExec.newBuilder()
.argsLine("")
.argsLine("login")
.executeAsync();
exe.waitForStderr("Username:");
exe.sendLine("wburke");
@ -288,7 +288,7 @@ public class KcinitTest extends AbstractTestRealmKeycloakTest {
//Thread.sleep(100000000);
KcinitExec exe = KcinitExec.newBuilder()
.argsLine("")
.argsLine("login")
.executeAsync();
try {
exe.waitForStderr("Username:");
@ -327,7 +327,7 @@ public class KcinitTest extends AbstractTestRealmKeycloakTest {
testInstall();
KcinitExec exe = KcinitExec.newBuilder()
.argsLine("")
.argsLine("login")
.executeAsync();
exe.waitForStderr("Username:");
exe.sendLine("wburke");
@ -343,7 +343,7 @@ public class KcinitTest extends AbstractTestRealmKeycloakTest {
Assert.assertEquals(0, exe.stdoutLines().size());
exe = KcinitExec.newBuilder()
.argsLine("-f")
.argsLine("login -f")
.executeAsync();
exe.waitForStderr("Username:");
exe.sendLine("wburke");
@ -383,7 +383,7 @@ public class KcinitTest extends AbstractTestRealmKeycloakTest {
testInstall();
KcinitExec exe = KcinitExec.newBuilder()
.argsLine("")
.argsLine("login")
.executeAsync();
exe.waitForStderr("Username:");
exe.sendLine("wburke");
@ -427,7 +427,7 @@ public class KcinitTest extends AbstractTestRealmKeycloakTest {
Assert.assertEquals(0, exe.exitCode());
exe = KcinitExec.newBuilder()
.argsLine("")
.argsLine("login")
.executeAsync();
exe.waitForStderr("Username:");
exe.sendLine("wburke");
@ -465,7 +465,7 @@ public class KcinitTest extends AbstractTestRealmKeycloakTest {
testInstall();
KcinitExec exe = KcinitExec.newBuilder()
.argsLine("")
.argsLine("login")
.executeAsync();
exe.waitForStderr("Username:");
exe.sendLine("test-user@localhost");

View file

@ -25,3 +25,7 @@ ${msg("loginTotpManualStep3")}
</#if>
Enter in your one time password so we can verify you have installed it correctly.