Showing posts with label Permission. Show all posts
Showing posts with label Permission. Show all posts

Saturday, July 18, 2015

RabbitMQ .NET client to connect to WSO2 MB with SSL.

Hi All,

WSO2 Message Broker 3.0.0 is a distributed message broker that provides reliable messaging both secured and unsecured.

This post will explain on how the RabbitMQ .NET client can be used to publish or subscribe to WSO2 Message Broker 3.0.0 securely.

Creating the Certificate

Go to "<MB_HOME>/repository/resources/security" folder and run the following command. This will create a "cert" file which is the certification file for SSL communication. "wso2carbon.jks" is the trust store file. So we are exporting the certificate from the trust store. The "keytool" command comes with the JDK distribution.

keytool -export -keystore wso2carbon.jks -storepass wso2carbon -file carbon.cert -alias localhost -keypass wso2carbon

The Code

You can use the same implementation as mentioned in [1][2]. Only difference is we have to set the following properties to the "ConnectionFactory" object.

........
........
// The connection factory to connect with the broker.
ConnectionFactory factory = new ConnectionFactory();

// AMQP URL to connect to the broker.
IProtocol protocol = Protocols.AMQP_0_9_1;
factory.VirtualHost = "/carbon";
factory.UserName = "admin";
factory.Password = "admin";
factory.HostName = "localhost";
// Port for SSL
factory.Port = 8672;
factory.Protocol = protocol;

// SSL configuration
factory.Ssl.Enabled = true;
factory.Ssl.CertPassphrase = "wso2carbon";
factory.Ssl.CertPath = @"C:\Users\wso2\Documents\wso2mb-3.0.0-ALPHA\repository\resources\security\carbon.cert";
factory.Ssl.ServerName = "localhost";
factory.Ssl.AcceptablePolicyErrors = System.Net.Security.SslPolicyErrors.RemoteCertificateChainErrors;
factory.Ssl.Version = System.Security.Authentication.SslProtocols.Tls;

using (IConnection conn = factory.CreateConnection())
{
    ............
    ............

Set the correct path for "factory.Ssl.CertPath" to the "cert" file we generated in the earlier step.

Thats all guys!. Click here to download the sample .NET project(VS2010).

References...

[1] - https://docs.wso2.com/display/MB300/Publishing+and+Receiving+Messages+from+a+Queue
[2] - https://docs.wso2.com/display/MB300/Publishing+and+Receiving+Messages+from+a+Topic
[3] - https://www.rabbitmq.com/ssl.html
[4] - http://pathberiya.blogspot.com/2010_08_01_archive.html

Sunday, May 24, 2015

Creating a New User in Cassandra Database

Introduction...

Hi All,

Recently I was working on user authentication of DSE(DataStax Enterprise[1]) Cassandra and I noticed that any username and password allowed me to access the cassandra cluster. So I looked into the docs and saw that there are several authenticators[2].

By default the used authenticator is the "org.apache.cassandra.auth.AllowAllAuthorizer" authenticator which allowed access with any username and password. So to create a user and grant permissions, you can follow these steps...

Steps...

Shutdown the Cassandra cluster(can use kill -9) if it is already running and the modify the cassandra.yaml file. If you are using DSE cassandra, it will reside in "<DSE_HOME>/resources/cassandra/conf/cassandra.yaml". Else if you are using Apache Cassandra, it will reside in "<APACHE_CASSANDRA_HOME>/conf/cassandra.yaml".

Modify the file in a way that "org.apache.cassandra.auth.AllowAllAuthorizer" authenticator is commented and add "org.apache.cassandra.auth.PasswordAuthenticator" authenticator[3].
#authenticator: AllowAllAuthenticator
authenticator: PasswordAuthenticator

By default, Cassandra has a user with username as "cassandra" and password as "cassandra" which can be used to create a new user using "cqlsh" tool[4]. Login using the "cqlsh" tool by executing the following command.

./cqlsh localhost -u cassandra -p cassandra

After the cqlsh console is opened, to get the current list of users run the following command.

list users;

To create a new user, run the following command. Here the username is "myUserName" and the password is "myPassword".

CREATE USER myUserName WITH PASSWORD 'myPassword' SUPERUSER;

The above user will get created with superuser privileges. The newly created user should be there when running the "list users;" command again.

Goodluck!!!

References...

[1] - http://www.datastax.com/products/products-index
[2] - http://docs.datastax.com/en/cassandra/1.2/cassandra/security/secure_config_native_authorize_t.html
[3] - http://www.datastax.com/dev/blog/a-quick-tour-of-internal-authentication-and-authorization-security-in-datastax-enterprise-and-apache-cassandra
[4] - http://docs.datastax.com/en/cassandra/1.2/cassandra/security/security_config_native_authenticate_t.html

Tuesday, December 4, 2012

Create Site Permission Groups and Add Users for SharePoint - Powershell

The following post is a PowerShell script to create or remove site level permission groups and add users to those group for SharePoint.
Function to create a permission group...

function Create-SPGroupInWeb  
{  
    param ($url, $groupName, $permissionLevel, $description)  
    try{
        $web = Get-SPWeb -Identity $url 
        if($web -ne $null){
            if ($web.SiteGroups[$groupName] -ne $null)  
            {  
                write-Host -f red "Group $groupName already exists!"
            }  
            else  
            {  
                $web.SiteGroups.Add($groupName, $web.Site.Owner, $web.Site.Owner, $description)  
                $group = $web.SiteGroups[$groupName]  
                $roleAssignment = new-object Microsoft.SharePoint.SPRoleAssignment($group)  
                $roleDefinition = $web.Site.RootWeb.RoleDefinitions[$permissionLevel]  
                $roleAssignment.RoleDefinitionBindings.Add($roleDefinition)  
                $web.RoleAssignments.Add($roleAssignment)  
                $web.Update()  
                write-Host "Group $groupName created successfully" 
            }  

            $web.Dispose() 
        }
    }
    catch [System.Exception]
    {
        write-host -f red $_.Exception.ToString()
    }
}

Function to remove permission groups by name...
function Remove-SPGroupInWeb  
{  
    param ([string]$url, [string]$groupName)  
    try{
        $web = Get-SPWeb -Identity $url 
        if($web -ne $null){
            if($web.SiteGroups[$groupName] -ne $null){
                write-Host -f yellow "Removing site group $groupName"
                $web.SiteGroups.Remove($groupName)
            }
            $web.Update()
            $web.Dispose() 
        }
    }
    catch [System.Exception]
    {
        write-host -f red $_.Exception.ToString()
    }
}

Function to add users to the group...
function Add-User
{
    param ($url, $groupName, $userName) 
    try{
        $web = Get-SPWeb $url
        if($web -ne $null){
            $MyGrp = $web.SiteGroups[$groupName]
            $user = $web.Site.RootWeb.EnsureUser($userName)
            $MyGrp.AddUser($user)
            write-Host "$userName added to $groupName" 
            $web.Update()
            $web.Dispose()
        }
    }
    catch [System.Exception]
    {
        write-host -f red $_.Exception.ToString()
    }
}

How to call the functions...
Remove-SPGroupInWeb -url "http://my-webApp:port/" -groupName "New Group"

Create-SPGroupInWeb -url "http://my-webApp:port/" -groupName "New Group" -permissionLevel "Read" -description "My New Group Description"

Add-User -url "http://my-webApp:port/" -groupName "New Group"-userName "domain\myUserName" 


As for the permission level of the group your going to create, For full control, send "Full Control" as the permissionLevel parameter. Running this code directly in SharePoint Management Shell wont be a problem.
Incase you are running it on Windows PowerShell, run this command as well... "Add-PSSnapin "Microsoft.SharePoint.PowerShell"


If you have any questions. I'll be glad to reply with what ever I know :) .