Skip to content

Commit 1ef6a8a

Browse files
Authentication enhancement - Support for username password based authentication (#8)
1. Added username + password support where instead of browser, plugin prompts for credentials 2. Fixed issue that token expiration logic was flawed. Now, when token actually expires, it will be renewed using refresh token.
1 parent 14c2bea commit 1ef6a8a

25 files changed

Lines changed: 2865 additions & 218 deletions

Common/Code/Constants.cs

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,34 @@
11
namespace Common
22
{
3-
public class Constants
4-
{
5-
public const string COL_NAME_NUMBER = "No.";
6-
public const string COL_NAME_STATUS = "Status";
7-
public const string COL_NAME_SOURCE_FOLDER = "Source Folder";
8-
public const string COL_NAME_SOURCE_FILE_NAME = "Source Filename";
9-
public const string COL_NAME_SOURCE_LINE = "Source Line";
10-
public const string COL_NAME_SOURCE_OBJECT = "Source Object";
11-
public const string COL_NAME_DEST_FOLDER = "Destination Folder";
12-
public const string COL_NAME_DEST_FILE_NAME = "Destination Filename";
13-
public const string COL_NAME_DEST_LINE = "Destination Line";
14-
public const string COL_NAME_DEST_OBJECT = "Destination Object";
15-
public const string COL_NAME_SHOW_PATH = "Result State";
16-
public const string COL_NAME_SEVERITY = "Severity";
17-
public const string COL_NAME_ASSIGN = "Assigned User";
18-
public const string COL_NAME_REMARK = "Comment";
3+
public class Constants
4+
{
5+
#region AuthTypeUserpassword
6+
7+
public const string AuthenticationaType_DefaultValue = "access_control";
8+
public const string AuthenticationaType_UserNamePassword = "username_password";
9+
10+
public const string USERNAME_KEY = "username";
11+
public const string PASSWORD_KEY = "password";
12+
public const string PASSWORD_GRANT_TYPE = "password";
13+
public const string CLIENT_SECRET_KEY = "client_secret";
14+
public const string SCOPE_VALUE_CREDS = "sast_api sast-permissions access_control_api sast_rest_api offline_access";
15+
16+
#endregion AuthTypeUserpassword
17+
18+
public const string COL_NAME_NUMBER = "No.";
19+
public const string COL_NAME_STATUS = "Status";
20+
public const string COL_NAME_SOURCE_FOLDER = "Source Folder";
21+
public const string COL_NAME_SOURCE_FILE_NAME = "Source Filename";
22+
public const string COL_NAME_SOURCE_LINE = "Source Line";
23+
public const string COL_NAME_SOURCE_OBJECT = "Source Object";
24+
public const string COL_NAME_DEST_FOLDER = "Destination Folder";
25+
public const string COL_NAME_DEST_FILE_NAME = "Destination Filename";
26+
public const string COL_NAME_DEST_LINE = "Destination Line";
27+
public const string COL_NAME_DEST_OBJECT = "Destination Object";
28+
public const string COL_NAME_SHOW_PATH = "Result State";
29+
public const string COL_NAME_SEVERITY = "Severity";
30+
public const string COL_NAME_ASSIGN = "Assigned User";
31+
public const string COL_NAME_REMARK = "Comment";
1932

2033
public const string ERR_TITLE = "Error Message";
2134
public const string ERR_UNKNOWN = "Cannot establish connection with the server. Unknown error.";
@@ -24,6 +37,8 @@ public class Constants
2437

2538
public const string CLIENT_ID_KEY = "client_id";
2639
public const string CLIENT_VALUE = "ide_client";
40+
public const string CLIENT_VALUE_ROPC = "resource_owner_client";
41+
public const string CLIENT_SECRET_ROPC = "014DF517-39D1-4453-B7B3-9930C563627C";
2742
public const string SCOPE_KEY = "scope";
2843
public const string CODE_KEY = "code";
2944
public const string GRANT_TYPE_KEY = "grant_type";

Common/Common.csproj.user

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
4+
<StartArguments>/rootsuffix Exp</StartArguments>
5+
<StartAction>Program</StartAction>
6+
<StartProgram>C:\Program Files %28x86%29\Microsoft Visual Studio\2019\Professional\Common7\IDE\devenv.exe</StartProgram>
7+
<StartWorkingDirectory>C:\Program Files %28x86%29\Microsoft Visual Studio\2019\Professional\Common7\IDE\</StartWorkingDirectory>
8+
</PropertyGroup>
9+
</Project>

CxViewerAction/CommonActions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ public void ExecuteSystemCommand(string commandName, string args)
185185
/// <returns></returns>
186186
public Entities.Project GetSelectedProject()
187187
{
188+
Logger.Create().Debug("GetSelectedProject(): Find selected project.");
188189
string projectName, projectPath;
189190
Array projects = (Array)_applicationObject.ActiveSolutionProjects;
190191

@@ -193,6 +194,7 @@ public Entities.Project GetSelectedProject()
193194
//Context menu are displayed on project item in solution explorer
194195
if (_applicationObject.SelectedItems != null)
195196
{
197+
Logger.Create().Debug("Looping for SelectedItems ");
196198
foreach (SelectedItem selectedItem in _applicationObject.SelectedItems)
197199
{
198200
if (selectedItem.ProjectItem != null)

CxViewerAction/CxViewerAction.csproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,12 @@
393393
<Compile Include="Views\Shapes\TableLayout.cs">
394394
<SubType>Component</SubType>
395395
</Compile>
396+
<Compile Include="Views\SubmitUserFrm.cs">
397+
<SubType>Form</SubType>
398+
</Compile>
399+
<Compile Include="Views\SubmitUserFrm.designer.cs">
400+
<DependentUpon>SubmitUserFrm.cs</DependentUpon>
401+
</Compile>
396402
<Compile Include="Views\UploadFrm.cs">
397403
<SubType>Form</SubType>
398404
</Compile>
@@ -602,6 +608,9 @@
602608
<DependentUpon>ScanProcessFrm.cs</DependentUpon>
603609
<SubType>Designer</SubType>
604610
</EmbeddedResource>
611+
<EmbeddedResource Include="Views\SubmitUserFrm.resx">
612+
<DependentUpon>SubmitUserFrm.cs</DependentUpon>
613+
</EmbeddedResource>
605614
<EmbeddedResource Include="Views\UploadFrm.resx">
606615
<DependentUpon>UploadFrm.cs</DependentUpon>
607616
<SubType>Designer</SubType>

CxViewerAction/Entities/LoginData.cs

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class LoginData : IEntity
2424
#region [Private Constants]
2525

2626
/// <summary>
27-
/// Full service path url format
27+
/// Full service path url format
2828
/// </summary>
2929
private const string _baseFormat = "http{0}://{1}";
3030
private const string _servicePathFormat = "{0}/Cxwebinterface/CxWsResolver.asmx";
@@ -36,7 +36,8 @@ public class LoginData : IEntity
3636
private string _serverDomain = null;
3737
private string _server = null;
3838
private string _serverBaseUri = null;
39-
private bool _ssl = false;
39+
private bool _ssl = false;
40+
private string _authenticationType = "access_control";
4041

4142
private EntityId _id;
4243
private bool _isLogging;
@@ -57,15 +58,15 @@ public class LoginData : IEntity
5758
private bool _disableConnectionOptimizations = false;
5859

5960
SerializableDictionary<string, string> _perspectives;
60-
61+
6162
private List<BindProject> bindedProjects;
62-
private bool _saveSastScan;
63-
private bool _manageResultsComment;
64-
private bool _manageResultsExploitability;
63+
private bool _saveSastScan;
64+
private bool _manageResultsComment;
65+
private bool _manageResultsExploitability;
6566

66-
#endregion
67+
#endregion
6768

68-
#region [ Constructors ]
69+
#region [ Constructors ]
6970

7071
private static LoginData loginDataInstance;
7172

@@ -139,7 +140,7 @@ public string Server
139140
return string.Format(_servicePathFormat, _serverBaseUri);
140141
}
141142
set { _server = value; }
142-
}
143+
}
143144

144145
public string ServerBaseUri
145146
{
@@ -171,6 +172,16 @@ public bool Ssl
171172
set { _ssl = value; }
172173
}
173174

175+
/// <summary>
176+
/// Gets or sets value indicating that Authenticationa Type Log in Form Or User Submit Form throw htts protocol
177+
/// </summary>
178+
public string AuthenticationType
179+
{
180+
get { return _authenticationType; }
181+
set { _authenticationType = value; }
182+
}
183+
184+
174185
/// <summary>
175186
/// Get or set Entity prorepty
176187
/// </summary>
@@ -233,8 +244,8 @@ public string UnboundRunID
233244
{
234245
get { return unboundRunID; }
235246
set { unboundRunID = value; }
236-
}
237-
247+
}
248+
238249
public List<BindProject> BindedProjects
239250
{
240251
get { return bindedProjects; }
@@ -260,19 +271,19 @@ public bool DisableConnectionOptimizations
260271
set { _disableConnectionOptimizations = value; }
261272
}
262273

263-
public bool SaveSastScan { get => _saveSastScan; set => _saveSastScan = value; }
264-
public bool ManageResultsComment { get => _manageResultsComment; set => _manageResultsComment = value; }
265-
public bool ManageResultsExploitability { get => _manageResultsExploitability; set => _manageResultsExploitability = value; }
274+
public bool SaveSastScan { get => _saveSastScan; set => _saveSastScan = value; }
275+
public bool ManageResultsComment { get => _manageResultsComment; set => _manageResultsComment = value; }
276+
public bool ManageResultsExploitability { get => _manageResultsExploitability; set => _manageResultsExploitability = value; }
266277

267-
#endregion [ Properties ]
278+
#endregion [ Properties ]
268279

269-
#region [ Public Methods ]
280+
#region [ Public Methods ]
270281

271-
/// <summary>
272-
/// Verify if user enter all data to start auth verification
273-
/// </summary>
274-
/// <returns></returns>
275-
public bool CanLog()
282+
/// <summary>
283+
/// Verify if user enter all data to start auth verification
284+
/// </summary>
285+
/// <returns></returns>
286+
public bool CanLog()
276287
{
277288
return (String.IsNullOrEmpty(this.Server)) ? false : true;
278289
}
@@ -298,7 +309,7 @@ public void AddProjectPerspective(string project, string perspective)
298309
Perspectives.Add(project, perspective);
299310
}
300311

301-
312+
302313

303314
/// <summary>
304315
/// Clear user auth data

CxViewerAction/Helpers/BackgroundWorkerHelper.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ public bool DoWork(string message)
112112
{
113113
try
114114
{
115+
Logger.Create().Debug("DoWork" + message);
116+
115117
if (Invoke(message, waitView) || canceling)
116118
{
117119
success = true;
@@ -153,7 +155,8 @@ public bool DoWork(string message)
153155
{
154156
try
155157
{
156-
ErrorFrm frmError = new ErrorFrm(errorMessage, delegate(object o, EventArgs e) { executionResult = Invoke("Reconnection...", waitView); }, _doReloginFunc);
158+
Logger.Create().Debug("DoWork - Reconnection " + message);
159+
ErrorFrm frmError = new ErrorFrm(errorMessage, delegate (object o, EventArgs e) { executionResult = Invoke("Reconnection...", waitView); }, _doReloginFunc);
157160
DialogResult res = frmError.ShowDialog();
158161

159162
if (res == DialogResult.Cancel)

CxViewerAction/Helpers/BindProjectHelper.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ static void BindSelectedProject(LoginResult loginResult, Entities.Project projec
153153
isThrewError = true;
154154
return;
155155
}
156+
Logger.Create().Debug("Getting project display data.");
156157
cxWSResponseProjectsDisplayData = client.ServiceClient.GetProjectsDisplayData(loginResult.SessionId);
158+
Logger.Create().Debug("Received project display data. Count "+ cxWSResponseProjectsDisplayData.projectList.Length);
157159

158160
}, loginResult.AuthenticationData.ReconnectInterval * 1000, loginResult.AuthenticationData.ReconnectCount);
159161

@@ -229,7 +231,7 @@ static void BindSelectedProject(LoginResult loginResult, Entities.Project projec
229231
isNewProject = true;
230232
}
231233

232-
234+
Logger.Create().Info("Getting Scans display data for selected project " + selectedProjectId);
233235
CxWSResponseScansDisplayData cxWSResponseScansDisplayData = PerspectiveHelper.GetScansDisplayData(selectedProjectId);
234236
if (cxWSResponseScansDisplayData.ScanList.Length == 0)
235237
{
@@ -239,6 +241,7 @@ static void BindSelectedProject(LoginResult loginResult, Entities.Project projec
239241
return;
240242
}
241243

244+
Logger.Create().Info("Received Scans display data for selected project. Count " + cxWSResponseScansDisplayData.ScanList.Length);
242245
foreach (ScanDisplayData item in cxWSResponseScansDisplayData.ScanList)
243246
{
244247

CxViewerAction/Helpers/ConfigurationHelper.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using CxViewerAction.CxVSWebService;
1+
using Common;
2+
using CxViewerAction.CxVSWebService;
23
using CxViewerAction.Entities.WebServiceEntity;
34
using CxViewerAction.Services;
45
using System;
@@ -11,6 +12,7 @@ internal class ConfigurationHelper : IConfigurationHelper
1112
{
1213
public ConfigurationResult GetConfigurationList(string sessionId, BackgroundWorkerHelper bg, CxWebServiceClient client)
1314
{
15+
Logger.Create().Debug("Getting configuration list.");
1416
ConfigurationResult configuration = null;
1517
bg.DoWorkFunc = delegate(object obj)
1618
{
@@ -31,6 +33,7 @@ public ConfigurationResult GetConfigurationList(string sessionId, BackgroundWork
3133
if (!bg.DoWork("Receive Configuration list..."))
3234
return null;
3335

36+
Logger.Create().Debug("Configuration list received. " + configuration.ToString());
3437
return configuration;
3538
}
3639
}

0 commit comments

Comments
 (0)