Question: I am trying to add LDAP based authorisation to Kibana 3 without using Shield or other 3rd party tools.

Given the index name is `logstash-*`, my original thinking is to utilize rewriting rules in httpd, rewrite kibana request into `logstash-[ldap-usergroup]-*`, and prepare a set of index aliases in elasticsearch that with different filters, thus to achieve the authorisation at the LDAP user group level.

The problem I am facing currently, is how do I get the `usergroup` value after the authentication block and use it into the rewrites?

assume I have something like 

```
<Location />
AuthLDAPBindDN "CN=username, CN=Users, DC=domain, DC=com"
AuthLDAPBindPassword "Password for Kerberos auth user"
AuthLDAPURL "ldap(or ldaps)://fqdns or ip of ldap/adserver/CN=users,DC=domain,DC=com"
AuthType Basic
AuthBasicProvider ldap
AuthName "some text for login prompt"
require valid-user
</Location>
RewriteCond   %{LA-U:REMOTE_USER} !^$
RewriteRules  /es/(.*)logstash-([0-9]+.[0-9]+.[0-9]+)(.*) /es/$1%{LA-U:REMOTE_USER}-$2$3 [N]

```

ie. how do I make sure rather than the username, I can have a usergroup name value available before doing the rewrite? 

Borrowed some codes from here: thanks to them
<https://gist.github.com/kakbit/6192679>
<http://elasticsearch-users.115913.n3.nabble.com/LDAP-authentication-in-Kibana-td4057946.html>

Answer: 
C# has strong typing for a reason. Unless you have a valid reason (such as needing COM interop) to use the `dynamic` type, you should probably avoid it like the plague, or you'll risk turning compile-time problems into runtime problems. `dynamic` is powerful, but easy to abuse. Think long and hard about if you really *need* dynamic typing - if you think there is, there's a chance that you're approaching the problem wrong to begin with, and need to refactor your code.

To specifically answer your question - one potential use case was if you were writing serialisation code and needed to accept a deserialised object, for example a deserialised JSON structure from a web API request. Such methods would need to handle any type given to them, which is a situation in which using `dynamic` is better than the alternative (ie. a truck-load of reflection).

Another example I can think of would be interoperability with languages specifically on the Dynamic Language Runtime (eg. JavaScript, IronPython, IronRuby, ...), and needed to write a method accepting types from such languages.

From [Beginning Visual C# 2012 Programming](//www.wrox.com/WileyCDA/WroxTitle/Beginning-Visual-C-2012-Programming.productCd-1118314417.html):

> 
> For most C# code that you write, avoid the `dynamic` keyword. However, if a situation arises where you *need* to use it, use it and love it - and spare a thought for those poor programmers of the past who didn't have this powerful tool at their disposal.
> 
> 
>
**Duck Typing:**

> 
> Please you do this rather than asking who you are.
> 
> 
> 

**Example:**

> 
> Here coding should be simply define and execution. Example, here are
>  the things that I want the following object do something.
> 
> 
> 

```
    Please("Walk", new Dog());
    Please("Run", new Duck());
    Please("Fly", new Cup());
    Please("Fly", new Bird());
    Please("Fly", new Man());
    Please("Walk", new Man());
    Please("Run", new Man());

```

> 
> This is the result after excuting test.
> 
> 
> 

[![enter image description here](https://i.stack.imgur.com/mTenN.jpg)](https://i.stack.imgur.com/mTenN.jpg)

> 
> So, the above objects will do things that we requesting to do only.
>  Additional, I have added the question to ask them answer who they,
>  too. Here is the code in C#.
> 
> 
> 

```
private void Please(string Action, object Obj)
{
    MethodInfo method = Obj.GetType().GetMethod(Action, Type.EmptyTypes, null);
    if (method != null)
    {
        method.Invoke(Obj, new object[] { });
    }
    else
    {
        Console.WriteLine(string.Format("I can not {0} because {1}", Action, WhoAreYou(Obj)));
    }
}

private string WhoAreYou(object unknown)
{
    string question = "WhoAreYou";
    MethodInfo whoAreYou = unknown.GetType().GetMethod(question, Type.EmptyTypes, null);
    return whoAreYou.Invoke(unknown, new object[] { }).ToString();
}

```