Skip to content

Commit

Permalink
Add login support with the P4LOGINSSO variable.
Browse files Browse the repository at this point in the history
  • Loading branch information
groboclown committed May 12, 2017
1 parent 561b3e0 commit 6651425
Show file tree
Hide file tree
Showing 15 changed files with 284 additions and 19 deletions.
7 changes: 5 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@
### Overview

* Added support for loading "P4ENVIRO" from the Windows registry.
* Added support for logging in with the "P4LOGINSSO" value.
* Bug fixes.

### Details

* Added support for "P4ENVIRO" loaded from the Windows registry.
* Before, the Windows registry loader would not correctly read in the
`P4ENVIRO` setting from the Windows registry.
* Added support for logging in with the "P4LOGINSSO" value. (#147)
* If the user isn't logged in, but has the `P4LOGINSSO` value set,
then that is now used in the login dance. Before, the plugin would
ask the user for the password.
* Bug fixes.
* Fixed the Windows registry value loading (#146).
* Reverted back to component file locations being based at their
natural file locations, rather than at the project root (#148).
* Check the state of the P4LOGINSSO setting when determining whether
a login should be attempted. (#147)


## ::v0.8.6::
Expand Down
1 change: 1 addition & 0 deletions plugin/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<li><em>0.8.7</em>
<ol>
<li>Added support for "P4ENVIRO" loaded from the Windows registry.</li>
<li>Added support for logging in with the "P4LOGINSSO" value.</li>
<li>Fixed the Windows registry value loading.</li>
<li>Reverted back to component file locations being based at their
natural file locations, rather than at the project root.</li>
Expand Down
6 changes: 4 additions & 2 deletions plugin/src/net/groboclown/idea/p4ic/P4Bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ error.config.setup.problems=Configuration for {0} has problems\: {1}
configuration.problem.authticket=Missing authorization ticket location setting.
configuration.problem.authticket.exist=Authorization ticket file not found\: {0}
configuration.problem.trustticket.exist=Trusted Ticket file not found\: {0}
configuration.problem.loginsso.exist=Login SSO executable script not found\: {0}
configuration.problem.loginsso.exist=Login SSO executable script set but empty
configuration.problem.username=Missing username definition.
configuration.problem.clientname=Missing client name definition.
revision.list.rev=Rev \#
Expand Down Expand Up @@ -468,4 +468,6 @@ error.config.requires-password=Password required for server connection.
configuration.tab.properties=Connection Properties
user.prefs.socket-so-timeout=RPC SO Socket Ti&meout (in ms):
user.prefs.socket-so-timeout.tooltip=Increase this number if you see "SocketTimeoutException" problems.
error.revert.offline=Cannot revert files while offline.
error.revert.offline=Cannot revert files while offline.
error.loginsso.exec-failed=Failed to execute the P4LOGINSSO command `{0}`: {1}
error.loginsso.exec-failed.title=SSO Login Problem
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ boolean checkTrustTicketFile(@NotNull DataPart part) {
return checkTrustTicketFile(part, part.getTrustTicketFile());
}

boolean checkLoginSsoFile(@NotNull ConfigPart part, @Nullable File file) {
if (file != null && (! file.exists() || ! file.isFile())) {
boolean checkLoginSsoFile(@NotNull ConfigPart part, @Nullable String file) {
if (file != null && file.isEmpty()) {
problems.add(new ConfigProblem(part, false, "configuration.problem.loginsso.exist", file));
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import net.groboclown.idea.p4ic.config.ServerConfig;
import net.groboclown.idea.p4ic.config.UserProjectPreferences;
import net.groboclown.idea.p4ic.v2.extension.P4PluginVersion;
import net.groboclown.idea.p4ic.v2.server.authentication.LoginSsoCallbackHandler;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -119,14 +120,26 @@ public IOptionsServer createConnection(@NotNull ClientConfig clientConfig, @NotN
}
}
final IOptionsServer server = ServerFactory.getOptionsServer(uri, props, options);
if (clientConfig.getServerConfig().getServerName().isSecure()
&& clientConfig.getServerConfig().hasServerFingerprint()) {
postCreationSetup(server, clientConfig);
return server;
}

private void postCreationSetup(@NotNull IOptionsServer server, @NotNull ClientConfig clientConfig)
throws P4JavaException {
final ServerConfig serverConfig = clientConfig.getServerConfig();
if (serverConfig.getServerName().isSecure() && serverConfig.hasServerFingerprint()) {
if (LOG.isDebugEnabled()) {
LOG.debug("Setting server fingerprint to " + clientConfig.getServerConfig().getServerFingerprint());
LOG.debug("Setting server fingerprint to " + serverConfig.getServerFingerprint());
}
server.addTrust(clientConfig.getServerConfig().getServerFingerprint());
server.addTrust(serverConfig.getServerFingerprint());
}
if (serverConfig.hasLoginSso() && serverConfig.getLoginSso() != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("Setting up SSO login to execute `" + serverConfig.getLoginSso() + "`");
}
// TODO look into registering the sso key through user options.
server.registerSSOCallback(new LoginSsoCallbackHandler(serverConfig.getLoginSso()), null);
}
return server;
}

@NotNull
Expand Down
22 changes: 22 additions & 0 deletions plugin/src/net/groboclown/idea/p4ic/ui/RevertedFilesDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,28 @@ private List<String> exceptionDisplay(@NotNull final Collection<P4StatusMessage>
GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false));
}

/**
* @noinspection ALL
*/
private Font getFont1494608681498(String fontName, int style, int size, Font currentFont) {
if (currentFont == null) {
return null;
}
String resultName;
if (fontName == null) {
resultName = currentFont.getName();
} else {
Font testFont = new Font(fontName, Font.PLAIN, 10);
if (testFont.canDisplay('a') && testFont.canDisplay('1')) {
resultName = fontName;
} else {
resultName = currentFont.getName();
}
}
return new Font(resultName, style >= 0 ? style : currentFont.getStyle(),
size >= 0 ? size : currentFont.getSize());
}

/**
* @noinspection ALL
*/
Expand Down
22 changes: 22 additions & 0 deletions plugin/src/net/groboclown/idea/p4ic/ui/checkin/P4SubmitPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,28 @@ private String getJobIdFieldText() {
label2.setLabelFor(myJobStatus);
}

/**
* @noinspection ALL
*/
private Font getFont1494608681498(String fontName, int style, int size, Font currentFont) {
if (currentFont == null) {
return null;
}
String resultName;
if (fontName == null) {
resultName = currentFont.getName();
} else {
Font testFont = new Font(fontName, Font.PLAIN, 10);
if (testFont.canDisplay('a') && testFont.canDisplay('1')) {
resultName = fontName;
} else {
resultName = currentFont.getName();
}
}
return new Font(resultName, style >= 0 ? style : currentFont.getStyle(),
size >= 0 ? size : currentFont.getSize());
}

/**
* @noinspection ALL
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,10 @@ private static List toProblemMessages(ArrayList<ConfigProblem> problemMessages)
scrollPane1.setVerticalScrollBarPolicy(22);
panel4.add(scrollPane1, BorderLayout.CENTER);
resolvedValuesText = new JTextArea();
resolvedValuesText.setFont(UIManager.getFont("TextArea.font"));
Font resolvedValuesTextFont = UIManager.getFont("TextArea.font");
if (resolvedValuesTextFont != null) {
resolvedValuesText.setFont(resolvedValuesTextFont);
}
resolvedValuesText.setRows(8);
scrollPane1.setViewportView(resolvedValuesText);
final JPanel panel5 = new JPanel();
Expand All @@ -392,6 +395,28 @@ private static List toProblemMessages(ArrayList<ConfigProblem> problemMessages)
label1.setLabelFor(rootDirDropdownBox);
}

/**
* @noinspection ALL
*/
private Font getFont1494608681498(String fontName, int style, int size, Font currentFont) {
if (currentFont == null) {
return null;
}
String resultName;
if (fontName == null) {
resultName = currentFont.getName();
} else {
Font testFont = new Font(fontName, Font.PLAIN, 10);
if (testFont.canDisplay('a') && testFont.canDisplay('1')) {
resultName = fontName;
} else {
resultName = currentFont.getName();
}
}
return new Font(resultName, style >= 0 ? style : currentFont.getStyle(),
size >= 0 ? size : currentFont.getSize());
}

/**
* @noinspection ALL
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ private void createUIComponents() {
panel2.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black),
ResourceBundle.getBundle("net/groboclown/idea/p4ic/P4Bundle").getString("user.prefs.rev_display"),
TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION,
new Font(panel2.getFont().getName(), panel2.getFont().getStyle(), panel2.getFont().getSize())));
this.getFont1494608681498(null, -1, -1, panel2.getFont())));
myPreferRevisionNumber = new JRadioButton();
this.$$$loadButtonText$$$(myPreferRevisionNumber,
ResourceBundle.getBundle("net/groboclown/idea/p4ic/P4Bundle").getString("user.prefs.revision"));
Expand Down Expand Up @@ -289,6 +289,28 @@ private void createUIComponents() {
label2.setLabelFor(myMaxRetryAuthenticationSpinner);
}

/**
* @noinspection ALL
*/
private Font getFont1494608681498(String fontName, int style, int size, Font currentFont) {
if (currentFont == null) {
return null;
}
String resultName;
if (fontName == null) {
resultName = currentFont.getName();
} else {
Font testFont = new Font(fontName, Font.PLAIN, 10);
if (testFont.canDisplay('a') && testFont.canDisplay('1')) {
resultName = fontName;
} else {
resultName = currentFont.getName();
}
}
return new Font(resultName, style >= 0 ? style : currentFont.getStyle(),
size >= 0 ? size : currentFont.getSize());
}

/**
* @noinspection ALL
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ public class ConfigStackPanel
rootPanel.add(panel1, BorderLayout.NORTH);
panel1.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4), null));
final JLabel label1 = new JLabel();
label1.setFont(UIManager.getFont("TitledBorder.font"));
Font label1Font = UIManager.getFont("TitledBorder.font");
if (label1Font != null) {
label1.setFont(label1Font);
}
this.$$$loadLabelText$$$(label1,
ResourceBundle.getBundle("net/groboclown/idea/p4ic/P4Bundle").getString("configuration.stack.title"));
panel1.add(label1, BorderLayout.WEST);
Expand Down Expand Up @@ -236,7 +239,8 @@ ConfigPartPanel createPanel(@NotNull Project project, @Nullable ConfigPart part)
private final String title;
private final Icon icon;

ConfigPartType(@NotNull Class<? extends ConfigPart> partClass, @NotNull @NonNls String title, @NotNull Icon icon) {
ConfigPartType(@NotNull Class<? extends ConfigPart> partClass, @NotNull @NonNls String title,
@NotNull Icon icon) {
this.partClass = partClass;
this.title = title;
this.icon = icon;
Expand Down Expand Up @@ -303,7 +307,7 @@ public void run() {
for (ConfigPart part : parts) {
addConfigPart(part);
}
}
}
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ public JPanel getRootPanel() {
rootPanel = new JPanel();
rootPanel.setLayout(new BorderLayout(0, 0));
descriptionLabel = new JTextPane();
descriptionLabel.setFont(UIManager.getFont("Label.font"));
Font descriptionLabelFont = UIManager.getFont("Label.font");
if (descriptionLabelFont != null) {
descriptionLabel.setFont(descriptionLabelFont);
}
descriptionLabel.setText(
ResourceBundle.getBundle("net/groboclown/idea/p4ic/P4Bundle").getString("connection.env.description"));
rootPanel.add(descriptionLabel, BorderLayout.CENTER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public class PropertyConfigPanel
charsetField.setText(nullEmptyTrim(part.getDefaultCharset()));

loginSsoFieldLabel.setLabelFor(loginSsoField);
loginSsoField.setText(nullEmptyFile(project, part.getLoginSso()));
loginSsoField.setText(nullEmptyTrim(part.getLoginSso()));
loginSsoField.setButtonEnabled(true);
loginSsoField.addBrowseFolderListener(
P4Bundle.getString("configuration.properties.loginsso.chooser.title"),
Expand Down
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import net.groboclown.idea.p4ic.server.exceptions.P4LoginRequiresPasswordException;
import net.groboclown.idea.p4ic.server.exceptions.P4SSLException;
import net.groboclown.idea.p4ic.server.exceptions.P4VcsConnectionException;
import org.apache.http.auth.AUTH;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down
Loading

0 comments on commit 6651425

Please sign in to comment.