-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add login support with the P4LOGINSSO variable.
- Loading branch information
1 parent
561b3e0
commit 6651425
Showing
15 changed files
with
284 additions
and
19 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
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
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
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
91 changes: 91 additions & 0 deletions
91
plugin/src/net/groboclown/idea/p4ic/v2/server/authentication/LoginSsoCallbackHandler.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,91 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.groboclown.idea.p4ic.v2.server.authentication; | ||
|
||
import com.intellij.execution.ExecutionException; | ||
import com.intellij.execution.configurations.GeneralCommandLine; | ||
import com.intellij.execution.process.CapturingProcessHandler; | ||
import com.intellij.execution.process.ProcessOutput; | ||
import com.intellij.execution.util.ExecUtil; | ||
import com.intellij.openapi.diagnostic.Logger; | ||
import com.intellij.openapi.util.SystemInfo; | ||
import com.perforce.p4java.server.callback.ISSOCallback; | ||
import net.groboclown.idea.p4ic.config.UserProjectPreferences; | ||
import net.groboclown.idea.p4ic.v2.server.connection.AlertManager; | ||
import net.groboclown.idea.p4ic.v2.ui.alerts.LoginSsoExecFailedHandler; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* Invokes the LOGINSSO command to extract the correct information from the | ||
*/ | ||
public class LoginSsoCallbackHandler implements ISSOCallback { | ||
private static final Logger LOG = Logger.getInstance(LoginSsoCallbackHandler.class); | ||
|
||
private final String loginSsoCmd; | ||
|
||
public LoginSsoCallbackHandler(@NotNull String loginSsoCmd) { | ||
this.loginSsoCmd = loginSsoCmd; | ||
} | ||
|
||
@Override | ||
public Status getSSOCredentials(StringBuffer credBuffer, String ssoKey, String userName) { | ||
try { | ||
GeneralCommandLine cmd = createCommandLine(); | ||
if (LOG.isDebugEnabled()) { | ||
LOG.debug("Running login sso command `" + cmd.getCommandLineString() + "`"); | ||
} | ||
ProcessOutput output = (new CapturingProcessHandler(cmd)).runProcess( | ||
UserProjectPreferences.getLockWaitTimeoutMillis(null) | ||
); | ||
if (output.getExitCode() != 0) { | ||
LOG.info("failed with exit code " + output.getExitCode()); | ||
LOG.info("stdout: " + output.getStdout()); | ||
LOG.info("stderr: " + output.getStderr()); | ||
final ExecutionException ex = new ExecutionException("Exit code " + output.getExitCode()); | ||
AlertManager.getInstance().addCriticalError( | ||
new LoginSsoExecFailedHandler( | ||
loginSsoCmd, output.getStdout(), output.getStderr(), ex), | ||
ex | ||
); | ||
return Status.FAIL; | ||
} | ||
credBuffer.append(output.getStdout()); | ||
return Status.PASS; | ||
} catch (ExecutionException e) { | ||
AlertManager.getInstance().addCriticalError( | ||
new LoginSsoExecFailedHandler(loginSsoCmd, null, null, e), | ||
e | ||
); | ||
return Status.FAIL; | ||
} | ||
} | ||
|
||
@NotNull | ||
private GeneralCommandLine createCommandLine() { | ||
GeneralCommandLine ret = new GeneralCommandLine(); | ||
if (SystemInfo.isWindows) { | ||
ret.setExePath(ExecUtil.getWindowsShellName()); | ||
ret.addParameters("/c", | ||
GeneralCommandLine.inescapableQuote(loginSsoCmd)); | ||
} else if (SystemInfo.isMac) { | ||
ret.setExePath(ExecUtil.getOpenCommandPath()); | ||
ret.addParameters("-a", loginSsoCmd); | ||
} else { | ||
ret.setExePath("/bin/sh"); | ||
ret.addParameters("-c", loginSsoCmd); | ||
} | ||
return ret; | ||
} | ||
} |
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
Oops, something went wrong.