Action executed in 0.000 all posts   articles   bookmarks   polls   tag cloud

Mocking Active Directory with OpenLDAP

OpenLDAP logo

For work, our production server uses Active Directory (AD) for authentication and authorization to use our app. Users may belong to several groups to be granted access to different parts of the app. To mock this out for development I installed OpenLDAP and extended the schema enough to match what we need.

Our code queries the sAMAccountName attribute of users, which belongs to the Microsoft securityPrincipal objectClass. Instead of enabling the entire schema, which gave me errors, I enabled just the objectClass and attributes my application needs.

attributetype ( 1.2.840.113556.1.4.221
    NAME 'sAMAccountName'
    EQUALITY caseIgnoreMatch
    SYNTAX ''

attributetype ( 1.2.840.113556.1.2.102
    NAME 'memberOf'
    EQUALITY caseIgnoreMatch
    SYNTAX '')

objectclass ( 1.2.840.113556.1.5.6
    NAME 'securityPrincipal'
    SUP top
    MUST (sAMAccountName)
    MAY (memberOf))

This says there's attribute named sAMAccountName of type (SYNTAX) string which occurs once. Checking equality will ignore case. There's also a memberOf attribute, but it's permitted multiple times. Finally there's an objectclass called securityPrincipal which MUST contain sAMAccountName and MAY contain memberOfs.

Create this file and save it in /etc/ldap/schema/ms.schema.

Create a file schema_convert.conf like this.

include /etc/ldap/schema/ms.schema

Follow the steps here: Modifying the slapd Configuration Database.

Using phpLDAPadmin, add Generic: User Account, save, then edit. Add object class securityPrincipal. This will prompt you to fill out sAMAccountName. In our application we set the username part of our Kerberos principals. Then "Add new attribute" and select memberOf. Finally set the name of the group the member belongs to.

Now or app may perform the queries it needs, just as it would in production.

// Find the user
ldap_search( $ad, $basedn,"(samaccountName={$samaccountname})", array('dn;) );
// Get their groups
ldap_read( $ad, $userdn, '(objectclass=securityPrincipal)', 'memberof' );

How To Install and Configure OpenLDAP and phpLDAPadmin on Ubuntu 16.04 is an excellent article for reference.

ACPS Redistricting

Alexandria district blocks

Given the ugly nature of congressional districts, and even one elementary school district in Northern Alexandria, when I heard ACPS was redistricting their elementary schools, I became concerned. I started a project on GitHub to do my own analysis. It's been a fair amount of work, but GIS is fun.

My goal is to model the placement of K-5 students in Alexandria and build districts that minimized distance travelled. Also the assignments must be "stable", where "stable" means there's no 2 kids that would want to swap schools based on distance.

I'm using data from Census, Alexandria GIS, and OpenStreetMap. And I'm using the PostGIS extension to PostgreSQL for spatial analysis.

In an earlier districting project I measured distance as the crow flies, in order to build congressional districts. The issue with that is it completely ignored natural barriers like the Chesapeake Bay. So for this project, I'll use pgRouting to measure distance one would drive to school.

I hope to build a solution a problem that lies between the "single source shortest path" and "all-pairs shortest path" problems. For now I'm leaning towards something like a memoized A* algorithm.

As for the assignments, I'm not sure what to use yet. This problem is unlike k-means because both the location and the capacity of schools is fixed. I'm considering the Stable Marriable Problem (or NRMP), the Assignment Problem, and Hopcroft-Karp Algorithm.

If you're interested, please feel free to fork the project and contribute to it.

How You Can Help with Hurricane Patricia

HOT OSM Hurricane Patricia

Hurricane Patricia made landfall in Mexico 7pm today. Do you wonder how you could possibly help out? One way is through building a better map for relief workers.

OpenStreetMap is a global map built by citizen mappers similar to the way Wikipedia is built. With about 1 hour of training, you can also edit the map in a way that would help the people of Mexico in this disaster.

Prepare by learning about OpenStreetMap.

Then join the Humanitarian OpenStreetMap Team on the front line with a Hurricane Patricia task.

If you have any questions, please email me.

Double-Struck Header Title

double struck b

I was amazed to see that the default font in Chrome doesn't have glyphs for the double struck characters in Unicode used for special sets of numbers in math. The header title on this blog was using them, so it was important to me that it was right. My solution is odd, but works very well.

Instead of searching for some widely available font that did have these glyphs rendered, i created my own font. I knew that the DejaVu Sans font on my laptop had them.

I could have just shared this font as a web font and be done with it. But there was still one issue bothering me. I highly doubt that machines recognize the double struck B as a B. So i created a new font with just the letters and digits and used the double struck glyphs from DejeVu Sans. Now you can copy my header title into some a document and get Brian DeRocher.

Switching from inline-block to flex

Holy Grail Layout by Mozilla

While disliking CSS floats, i though i achieved the nirvana of page layout by using display: inline-block. Then i found display: flex.

Both the left side navigation and the right side main content were inline-blocks with the left side width: 20% and the right side width: 80%. I just had to make sure there was no margin on these elements and there was no white space between the elements. So often i had code like this <div><div class='left'>menu</div><div class='main'>content</div></div>; or for forms like this: <div class='form_style'><label>name</label><div><input/></div></div>.

Now i'm using display: flex. It's pretty well supported among all browsers. It easy to support responsive layouts. I'm looking forward to finding and switching to a flex based grid.

Reference: Using CSS flexible boxes

Counting Bubbles and the Poisson Distribution

brewing bubble count poisson graph

I've been counting the number of bubbles seen per minute in the 2 beers i'm currently brewing. After putting them on a chart, it seemed to me they look like a poisson distribution. I'll let you decide for yourself.