This example shows how to create a dll file that will augment 
security in SalesLogix by wrapping around the existing security of 
Saleslogix.  This modifies sql statements as they come through the 
SalesLogix Provider.  So you have: If this table is in the join, add to 
the where clause.  In the example below, a user is only allowed to see 
contacts where they are set as the Contact’s Account Manager 
(Contact.AccountManagerID Field).
- Open up visual studio and create a new project. 
- File -> New Project - Visual Basic -> Class library. 
 
 - Add a project reference to "SLXDBEngine 1.0 type library." 
- Right Click the Project in the Solution Explorer -> Add Reference -> COM Tab -> "SLXDBEngine 1.0 type library." 
 
 - Add new item to project -> class named VBSecurityBroker.vb  (Case sensitive) 
- Right Click the Project in the Solution Explorer -> Add -> New Item -> Class
 - In Class, select all and paste code snippet over current text.  See below for Code Snippet. 
 
 - Add new Class called VBQuerySecurity.vb 
- Right Click the Project in the Solution Explorer -> Add -> New Item -> Class
 - In Class, select all and paste code snippet over current text.  See below for Code Snippet.
 - Insert your custom code into the VBQuerySecurity.vb code where it says "'''YOUR SECURITY CODE GOES HERE" 
 
 - Delete class1
 - Save all and build. 
- Look for build succeeded in the lower left corner. 
 
 - View files in My DocumentsVS2005Projects...Debug.  We are worried about  ProjectName.dll and ProjectName.pdb. 
- Copy both files into C:Program FilesSaleslogix 
 
 - Create a new .udl file to connect to your target SalesLogix database. 
- Right click on the desktop and create a new text file.
 - Rename the text file Saleslogix.udl.  (Or any name you would like to use.)
 - Double click the file and fill in the information, making sure to use the SalesLogix OLE DB Provider.
 - Copy udl file to C:Program FilesSaleslogix. 
 
 - Create or edit an existing .xml file. 
- The class file .xml file code is below.
 - Update the xml code to match your Project Name and a new SalesLogix ID.
 - Copy xml file to C:Program FilesSaleslogix. 
 
 - Copy Interop.SLXDBEngineLib.dll, PluginWrapper.dll, and SLXPluginBuilder.exe to C:Program FilesSaleslogix. 
- I found these files in the Sage SalesLogix class files.  They can  also be found our built with the files in the SalesLogix DVD's SDK  Examples folder. 
 
 - Open cmd prompt. 
- cd C:Program FilesSaleslogix
 - Run: "slxPluginBuilder.exe -n SLXDemo.dll" 
- Creates wrapper for the dll, "DLLName.tlb" 
 
 - Run: "slxproviderplugin.exe -m SLXDemo.xml --udl new.udl" 
- Inserts the value into db and sets it up to run when security is needed.
 - Case sensitive
 - This information is stored in the SLXOLEDBPLUGIN table. 
- Can set SLXOLEDBPLUGIN.ENABLED to false if we want to turn off security plugin. 
 
 - The plugin(dll) security information is stored in the SLXOLEDBPLUGINDATA table.  
 
 
 - Log in and see if changes took effect.
 
Imports System
Imports System.Runtime.InteropServices
Imports SLXDBEngineLib
Imports System.Diagnostics
_
Public Class VbSecurityBroker : Implements ISLXSecurityBroker
    Dim m_securityInit As SLXSECURITYINIT
    Public Function GetSecurityObject(ByVal pSQLQuery As SLXDBEngineLib.SLXSQLQuery) _
            As ISLXQuerySecurity Implements ISLXSecurityBroker.GetSecurityObject
        If pSQLQuery.SQLType = SLXDBEngineLib.SLXSQLTYPE.SQLTYPE_SELECT Then
            Dim result As ISLXQuerySecurity = New VbQuerySecurity(m_securityInit, pSQLQuery)
            Return result
        Else
            Return Nothing
        End If
    End Function
    Public Sub Initialize(ByRef pSecurityInit As SLXDBEngineLib.SLXSECURITYINIT) _
        Implements SLXDBEngineLib.ISLXSecurityBroker.Initialize
        m_securityInit = pSecurityInit
    End Sub
    Public Sub Uninitialize() Implements SLXDBEngineLib.ISLXSecurityBroker.Uninitialize
    End Sub
End Class
vbQuerySecurity.vb Code Snippet:
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Runtime.InteropServices
Imports SLXDBEngineLib
Imports System.Diagnostics
Public Class VbQuerySecurity : Implements ISLXQuerySecurity
    Dim m_sqlQuery As SLXSQLQuery
    Dim m_securityInit As SLXSECURITYINIT
    Public Sub New(ByVal securityInit As SLXSECURITYINIT, ByVal sqlQuery As SLXSQLQuery)
        m_securityInit = securityInit
        m_sqlQuery = sqlQuery
    End Sub
    Public Function Secure() As QRYSECRESULT Implements ISLXQuerySecurity.Secure
        Dim res As QRYSECRESULT = QRYSECRESULT.QRYSEC_OK
        Dim cond As String
        Dim qSelect As SLXSelect = CType(m_sqlQuery, SLXSelect)
        If qSelect Is Nothing Then Return res
        For Each stmt As SelectStmt In qSelect.SelectStmts
            For Each join As SQLJoin In stmt.SQLFrom.SQLJoins
     '''YOUR SECURITY CODE GOES HERE
     '''EXAMPLE:
     '''If join.Name = "CONTACT" Then
          '''cond = String.Format("{0}.ACCOUNTMANAGERID = '{1}'", join.Alias, '''m_securityInit.SLXUserID)
          '''stmt.SQLWhere.AddConditionFromString(cond, '''SLXSQL_CONDITIONAL.SQLCONDITION_AND)
     End If
            Next
        Next
        Return res
    End Function
End Class
 
      
   
            Posted in: