AMO Wrappers for Securing Analysis Service Cube

Cube Permission Method

The method shown below is used to grant Read permission to the specified Role.


'Grant Cube Read Permission to a role

Public Function GrantCubeRead(ByVal parmRole As String) As Boolean

parmRole = parmRole.Trim()

If IsNullOrEmpty(parmRole) Then

Return False

End If

Try

Dim objRole As Role = Me.DatabaseObj.Roles.FindByName(parmRole)

Dim objCubePerm As CubePermission

If objRole Is Nothing Then

Return False

End If

If Me.CubeObj.CubePermissions.FindByRole(objRole.ID) Is Nothing Then

objCubePerm = Me.CubeObj.CubePermissions.Add(objRole.ID)

objCubePerm.Read = ReadAccess.Allowed

objCubePerm.Update(UpdateOptions.Default)

End If

Catch ServerNotFoundException As ConnectionException

Throw ServerNotFoundException

Catch ErrorAddingCubePermissionException As OperationException

Throw ErrorAddingCubePermissionException

Catch GenericAMOException As AmoException

Throw GenericAMOException

End Try

Return True

End Function

Dimension Permission Method

The method shown below is used to grant Read permission to all Cube Dimensions to the specified Role.


'Grant Read Permission to ALL Dimensions

Public Function GrantDimensionRead(ByVal parmRole As String) As Boolean

parmRole = parmRole.Trim()

Dim objDimension As Dimension

Dim objDimPerm As DimensionPermission

If IsNullOrEmpty(parmRole) Then

Return False

End If

Dim objRole As Role = Me.DatabaseObj.Roles.FindByName(parmRole)

If objRole Is Nothing Then

Return False

End If

Try

If Me.DatabaseObj.Dimensions.Count > 0 Then

For Each objDimension In DatabaseObj.Dimensions

If objDimension.DimensionPermissions.FindByRole(objRole.ID) Is Nothing Then

objDimPerm = objDimension.DimensionPermissions.Add(objRole.ID)

objDimPerm.Read = ReadAccess.Allowed

objDimPerm.Update(UpdateOptions.Default)

End If

Next

Else

Return True

End If

Catch ServerNotFoundException As ConnectionException

Throw ServerNotFoundException

Catch ErrorAddingDimPermissionException As OperationException

Throw ErrorAddingDimPermissionException

Catch GenericAMOException As AmoException

Throw GenericAMOException

End Try

Return True

End Function

Backup Utility Method

The AMO methods directly alter the Cube’s metadata. A wrongly issued command could cause ugly consequences. So it’s always better to backup the cube before running your AMO methods, especially during development and testing phase. The code shown below does exactly that. Call this as your first method before calling any of the other AMO methods.

IMPORTANT: The backup file name must have an .abf extension


'Backup Analysis Service Database

Public Sub BackupDatabase(ByVal parmFilePath As String)

Try

Me.DatabaseObj.Backup(parmFilePath, False)

Catch BackupException As OperationException

Throw BackupException

Catch GenericAMOException As AmoException

Throw GenericAMOException

End Try

End Sub

3 thoughts on “AMO Wrappers for Securing Analysis Service Cube

  1. I think speaking or writing it out loud made me think about it more. Then it downed on me to use SQL Profiler!

    … why didn’t I think of this before?!?!

    I’m proud and ashamed at the same time in finding out this simple answer to my own question.

  2. Hi,

    This question has been bugging me for a long time. How can you identify who are the currently connected users on your Analysis Services?

    Any insight would be appreciated.

    Thanks in advance

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s