James Moger edited this page Jul 8, 2016 · 2 revisions

About

Fathom-Security provides support for multiple authentication realms and an authorization infrastructure.

The core authorization design of Apache Shiro was harvested & married to the core authentication design of Gitblit to form a similar but significantly lighterweight security infrastructure.

A complete authentication and authorization model will include declarations of:

Realms : Realms are sources of Accounts and potentially Roles and Permissions. Realms are interrogated during the authentication process.

Accounts : Accounts represent a username-password pair. They may also include additional metadata such as display name, email addresses, Roles, and Permissions.

Roles : Roles are a named grouping of specific Permissions.

Permissions : Permissions are allowed application actions.

Installation

Add the Fathom-Security artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security</artifactId>
<version>${fathom.version}</version>
</dependency>

Layout

YourApp
└── src
└── main
└── java
└── conf
└── realms.conf

Configuration

Fathom-Security is configured by the HOCON resource config file conf/realms.conf.

# Configured Realms.# Realms will be tried in the order specified until an authentication is successful.realms: []
# If you have multiple Realms and are creating aggregate Accounts you# may cache the aggregate/assembled accounts in the SecurityManager.## Configure the aggregated Account time-to-live (TTL) in minutes and the maximum# number of aggregated accounts to keep cached.# A TTL of 0 disables this cache.cacheTtl: 0cacheMax: 100

Specifying an Alternate Realms Config File

You may specify alternate realms config files in your conf/default.conf resource config file.

security.configurationFile = "classpath:conf/realms.conf"dev.security.configurationFile = "classpath:conf/realms-dev.conf"test.security.configurationFile = "classpath:conf/realms-test.conf"

Usage

Fathom-Security provides a singleton instance of a SecurityManagerservice. This service contains all loaded Realms, Accounts, Roles, and Permissions.

@InjectSecurityManagersecurityManager;
publicAccountlogin(Stringusername, Stringpassword) {
StandardCredentialscredentials = newStandardCredentials(username, password);
Accountaccount = securityManager.authenticate(credentials);
returnaccount;
}

Accounts

Account usernames are specified to be global across all realms. Fathom-Security will collect and merge account definitions across all defined realms to create an aggregate account. This is necessary because not all realms are able to provide full account metadata, roles, permissions, and tokens.

For example, the account named james is assumed to represent the same person across all defined realms so that if james authenticates against a PAM Realm, his account metadata, roles, and permissions can be collected from the jamesaccount defined in a File Realm, JDBC Realm, etc.

Permissions

Permissions are allowed application actions. Permissions can be specified as a simple action (e.g. view) or as a granular, colon-delimited action (e.g. employees:view:5). Granular permissions may be assigned with up to three components: domain:action:instance.

# Permit viewing employees 5 and 10
employees:view:5,10
# Permit viewing all employees (these are equivalent)
employees:view:*
employees:view
# Permit updating employees 5 and 10
employees:update:5,10
# Permit all actions on employee 5
employees:*:5
# Permit adding and deleting any employee (these are equivalent)
employees:add,delete:*
employees:add,delete
# Permit all actions on all employees and contractors
employees,contractors:*

Roles

Roles may be specified on an account. Roles may also be defined to have explicit permissions. The primary value of a role is that it allows you to forgo maintaining the same set of permissions on multiple accounts. Instead you can maintain a single set of permissions in the role definition and assign this role to multiple accounts.

In the example below, the adminaccount has two assigned roles. The administratorrole is explicitly defined with the *permission, while the testerrole has no definition and therefore has no explicit permissions. The frankaccount has been assigned the normalrole and is only granted the secure:viewpermission.

accounts: [
{
username: "admin"roles: ["administrator", "tester"]
permissions: ["powers:speed,strength,agility"]
}
{
username: "frank"roles: ["normal"]
}
{
username: "joe"roles: ["normal"]
disabled: true
}
]
roles: {
administrator: ["*"]
normal: ["secure:view"]
}

Tokens

Tokens may be specified on an account. Tokens are both powerful and dangerous because a token is an authentication alias for an Account. You might use a token in a request header of a RESTful API route.

!!! Note Because a token is an alias for an Account, each token must be unique across all realms.

accounts: [
{
username: "frank"roles: ["normal"]
tokens: ["cafebabe","deadbeef"]
}
]

Authorization

Account instances have many methods to enforce authorization for a particular action.

publicvoidupdate(Employeeemployee) {
Accountaccount = getAccount();
if (account.hasRole("administrator") || account.isPermitted("employee:update")) {
employeeDao.update(employee);
}
}

You can also enforce authorization with methods that throw an AuthorizationException rather than returning a boolean status.

publicvoidupdate(Employeeemployee) {
Accountaccount = getAccount();
account.checkPermission("employee:update");
employeeDao.update(employee);
}

Disabling Accounts

In the above example the joeaccount is disabled.

accounts: [
{
username: "joe"disabled: true
}
]

In this case the SecurityManager will not allow the joeaccount to authenticate.

Realms

There are many realm integrations available for Fathom.

RealmModule
Memorycom.gitblit.fathom:fathom-security
Filecom.gitblit.fathom:fathom-security
Htpasswdcom.gitblit.fathom:fathom-security-htpasswd
Keycloakcom.gitblit.fathom:fathom-security-keycloak
LDAPcom.gitblit.fathom:fathom-security-ldap
JDBCcom.gitblit.fathom:fathom-security-jdbc
Rediscom.gitblit.fathom:fathom-security-redis
PAMcom.gitblit.fathom:fathom-security-pam
Windowscom.gitblit.fathom:fathom-security-windows

Memory Realm

The Memory Realm defines Accounts & Roles within the conf/realms.conf resource file.

Accounts and Roles are loaded only once on startup.

Configuration

conf/realms.conf

realms: [
{
# MEMORY REALM# All Accounts and Roles are loaded from this definition and cached in a ConcurrentHashMap.name: "Memory Realm"type: "fathom.realm.MemoryRealm"accounts: [
{
name: "Administrator"username: "admin"password: "admin"emailAddresses: ["fathom@gitblit.com"]
roles: ["administrator"]
permissions: ["powers:speed,strength,agility"]
}
{name: "User", username: "user", password: "user", roles: ["normal"], disabled: true}
{name: "Guest", username: "guest", password: "guest"}
# assign metadata and a role to an htpasswd account
{name: "Luke Skywalker", username: "red5", roles: ["normal"]}
# assign a role to an ldap account
{username: "UserOne", roles: ["normal"]}
]
## Defined Roles are named and have an array of Permissions.#roles: {
administrator: ["*"]
normal: ["secure:view"]
}
}
]

File Realm

The File Realm defines Accounts & Roles in an external HOCON file.

This realm will hot-reload on modification to the HOCON file.

Configuration

conf/realms.conf

realms: [
{
# FILE REALM# All Accounts and Roles are loaded from this definition and cached in a ConcurrentHashMap.name: "File Realm"type: "fathom.realm.FileRealm"file: "classpath:conf/users.conf"
}
]

conf/users.conf

accounts: [
{
name: "Administrator"username: "admin"password: "admin"emailAddresses: ["fathom@gitblit.com"]
roles: ["administrator"]
permissions: ["powers:speed,strength,agility"]
}
{name: "User", username: "user", password: "user", roles: ["normal"], disabled: true}
{name: "Guest", username: "guest", password: "guest"}
# assign metadata and a role to an htpasswd account
{name: "Luke Skywalker", username: "red5", roles: ["normal"]}
# assign a role to an ldap account
{username: "UserOne", roles: ["normal"]}
]
## Defined Roles are named and have an array of Permissions.#roles: {
administrator: ["*"]
normal: ["secure:view"]
}

Htpasswd Realm

The Htpasswd Realm defines partial Accounts (username & password) in an htpasswd file.

This realm will hot-reload on modification to the htpasswd file.

!!! Note You may only authenticate against an Htpasswd Realm. This realm does not support persistence of authorization data.

Installation

Add the Fathom-Security-Htpasswd artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-htpasswd</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# HTPASSWD REALMname: "Htpasswd Realm"type: "fathom.realm.htpasswd.HtpasswdRealm"file: "classpath:conf/users.htpasswd"allowClearPasswords: false
}
]

Keycloak Realm

The Keycloak Realm allows you to authenticate and, optionally, authorize requests using your Keycloak identity management server.

Installation

Add the Fathom-Security-Keycloak artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-keycloak</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

There are two parts to configuring your Keycloak integration.

  1. You'll need a conf/keycloak.json file which your Keycloak realm will provide to you via the admin ui.
  2. You need to configure conf/realms.conf to specify add the fathom.realm.keycloak.KeycloakRealm.

conf/realms.conf

realms: [
{
# KEYCLOAK REALM# Authenticates credentials from an Keycloak server.name: "My Keycloak Realm"type: "fathom.realm.keycloak.KeycloakRealm"file: "classpath:conf/keycloak.json"
}
]

Usage

See Fathom-REST Security.


LDAP Realm

The LDAP Realm allows you to integrate authentication and authorization with your LDAP server.

!!! Note You may authenticate and authorize using LDAP-sourced data but Role definitions are not currently supported by the LDAP Realm.

Installation

Add the Fathom-Security-LDAP artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-ldap</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# LDAP REALM# Authenticates credentials from an LDAP server.# This is a CachingRealm which may optionally configure an expiring cache.name: "UnboundID LDAP"type: "fathom.realm.ldap.LdapRealm"url: "ldap://localhost:1389"username: "cn=Directory Manager"password: "password"# LDAP search syntax for looking up accounts.accountBase: "OU=Users,OU=UserControl,OU=MyOrganization,DC=MyDomain"accountPattern: "(&(objectClass=person)(sAMAccountName=${username}))"# LDAP search syntax for looking up groups.# LDAP group names are mapped to Roles.# Roles can be optionally mapped to permissions.groupBase: "OU=Groups,OU=UserControl,OU=MyOrganization,DC=MyDomain"groupMemberPattern: "(&(objectClass=group)(member=${dn}))"# Members of these LDAP Groups are given "*" administrator permissions.# Invidual accounts can be specified with the "@" prefixadminGroups: ["@UserThree", "Git_Admins", "Git Admins"]
# Mapping controls for account name and email address extraction.# These may be an attribute name or can be a complex expression.nameMapping: "displayName"emailMapping: "email"# Configure the cached Account time-to-live (TTL) in minutes and the maximum# number of accounts to keep cached.# A TTL of 0 disables this cache.cacheTtl: 0cacheMax: 100
}
]

JDBC Realm

The JDBC Realm allows you to integrate authentication and authorization with an SQL database.

Installation

Add the Fathom-Security-JDBC artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-jdbc</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# JDBC/SQL REALM# Authenticates credentials from an SQL datasource.# This is a CachingRealm which may optionally configure an expiring cache.name: "H2 Realm"type: "fathom.realm.jdbc.JdbcRealm"url: "jdbc:h2:mem:fathom"username: ""password: ""# Specify a script to run on startup of the Realm.# This script creates our tables and populates some data.startScript: "classpath:conf/realm.sql"# Specify an account query and column mappings to populate Account metadata.## This optional mapping only works for the table (or view) referenced in the# accountQuery.accountQuery: "select * from accounts where username=?"nameMapping: "name"passwordMapping: "password"# Email address column mapping if your addresses are in the same table as your accounts.# This value may be delimited by a comma or semi-colon to support multiple addresses.emailMapping: "email"# A Role column mapping if your roles are in the same table as your accounts.# This value may be delimited by a comma or semi-colon to support multiple roles.roleMapping: ""# A Permission column mapping if your permissions are in the same table as your accounts.# This value may be delimited by a semi-colon to support multiple permissions.permissionMapping: ""# Specify an account roles query.# This is useful if your roles are defined in a separate table from your accounts.## The first column of the ResultSet must be a String role name.# The String role name may be delimited by a comma or semi-colon to support multiple roles.accountRolesQuery: "select role from account_roles where username=?"# Specify an account permissions query.# This is useful if your permissions are defined in a separate table from your accounts.## The first column of the ResultSet must be a String permission value.# The String permission value may be delimited by a semi-colon to support multiple permissions.accountPermissionsQuery: "select permission from account_permissions where username=?"# Specify a defined roles query.# Defined roles specify permissions for a role name.## The first column of the ResultSet must be a String role name.# The second column of the ResultSet must be a String permission value.# The String definition value may be delimited by a semi-colon to support multiple permissions.definedRolesQuery: "select role, definition from defined_roles"# Configure the cached Account time-to-live (TTL) in minutes and the maximum# number of accounts to keep cached.# A TTL of 0 disables this cache.cacheTtl: 0cacheMax: 100# fathom-security-jdbc supports HikariCP# see http://brettwooldridge.github.io/HikariCP/hikariCP {
connectionTimeout: 5000registerMbeans: true
}
}
]

Redis Realm

The Redis Realm allows you to integrate authentication and authorization with a Redis server.

!!! Note You may authenticate and authorize using Redis-sourced data but Role definitions are not currently supported by the Redis Realm.

Installation

Add the Fathom-Security-Redis artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-redis</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# REDIS REALMname: "Redis Realm"type: "fathom.realm.redis.RedisRealm"# Specify the url to the Redis databaseurl: "redis://localhost:6379/8"# The password for the Redis server, if neededpassword: ""# Specify the key mappings for account and role lookupspasswordMapping: "fathom:${username}:password"nameMapping: "fathom:${username}:name"emailMapping: "fathom:${username}:email"roleMapping: "fathom:${username}:roles"permissionMapping: "fathom:${username}:permissions"
}
]

PAM Realm

The PAM Realm allows you to authenticate against the local accounts on a Linux/Unix/OSX machine.

!!! Note You may only authenticate against a PAM Realm. This realm does not support persistence of authorization data.

Installation

Add the Fathom-Security-PAM artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-pam</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# PAM REALMname: "PAM Realm"type: "fathom.realm.pam.PamRealm"serviceName: "system-auth"
}
]

Windows Realm

The Windows Realm allows you to authenticate against the local accounts on a Windows machine.

!!! Note You may only authenticate against a Windows Realm. This realm does not support persistence of authorization data.

Installation

Add the Fathom-Security-Windows artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-windows</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# WINDOWS REALMname: "Windows Realm"type: "fathom.realm.windows.WindowsRealm"defaultDomain: ""allowGuests: falseadminGroups: [ "BUILTIN\Administrators" ]
}
]

Clone this wiki locally

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content
James Moger edited this page Jul 8, 2016 · 2 revisions

About

Fathom-Security provides support for multiple authentication realms and an authorization infrastructure.

The core authorization design of Apache Shiro was harvested & married to the core authentication design of Gitblit to form a similar but significantly lighterweight security infrastructure.

A complete authentication and authorization model will include declarations of:

Realms : Realms are sources of Accounts and potentially Roles and Permissions. Realms are interrogated during the authentication process.

Accounts : Accounts represent a username-password pair. They may also include additional metadata such as display name, email addresses, Roles, and Permissions.

Roles : Roles are a named grouping of specific Permissions.

Permissions : Permissions are allowed application actions.

Installation

Add the Fathom-Security artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security</artifactId>
<version>${fathom.version}</version>
</dependency>

Layout

YourApp
└── src
└── main
└── java
└── conf
└── realms.conf

Configuration

Fathom-Security is configured by the HOCON resource config file conf/realms.conf.

# Configured Realms.# Realms will be tried in the order specified until an authentication is successful.realms: []
# If you have multiple Realms and are creating aggregate Accounts you# may cache the aggregate/assembled accounts in the SecurityManager.## Configure the aggregated Account time-to-live (TTL) in minutes and the maximum# number of aggregated accounts to keep cached.# A TTL of 0 disables this cache.cacheTtl: 0cacheMax: 100

Specifying an Alternate Realms Config File

You may specify alternate realms config files in your conf/default.conf resource config file.

security.configurationFile = "classpath:conf/realms.conf"dev.security.configurationFile = "classpath:conf/realms-dev.conf"test.security.configurationFile = "classpath:conf/realms-test.conf"

Usage

Fathom-Security provides a singleton instance of a SecurityManagerservice. This service contains all loaded Realms, Accounts, Roles, and Permissions.

@InjectSecurityManagersecurityManager;
publicAccountlogin(Stringusername, Stringpassword) {
StandardCredentialscredentials = newStandardCredentials(username, password);
Accountaccount = securityManager.authenticate(credentials);
returnaccount;
}

Accounts

Account usernames are specified to be global across all realms. Fathom-Security will collect and merge account definitions across all defined realms to create an aggregate account. This is necessary because not all realms are able to provide full account metadata, roles, permissions, and tokens.

For example, the account named james is assumed to represent the same person across all defined realms so that if james authenticates against a PAM Realm, his account metadata, roles, and permissions can be collected from the jamesaccount defined in a File Realm, JDBC Realm, etc.

Permissions

Permissions are allowed application actions. Permissions can be specified as a simple action (e.g. view) or as a granular, colon-delimited action (e.g. employees:view:5). Granular permissions may be assigned with up to three components: domain:action:instance.

# Permit viewing employees 5 and 10
employees:view:5,10
# Permit viewing all employees (these are equivalent)
employees:view:*
employees:view
# Permit updating employees 5 and 10
employees:update:5,10
# Permit all actions on employee 5
employees:*:5
# Permit adding and deleting any employee (these are equivalent)
employees:add,delete:*
employees:add,delete
# Permit all actions on all employees and contractors
employees,contractors:*

Roles

Roles may be specified on an account. Roles may also be defined to have explicit permissions. The primary value of a role is that it allows you to forgo maintaining the same set of permissions on multiple accounts. Instead you can maintain a single set of permissions in the role definition and assign this role to multiple accounts.

In the example below, the adminaccount has two assigned roles. The administratorrole is explicitly defined with the *permission, while the testerrole has no definition and therefore has no explicit permissions. The frankaccount has been assigned the normalrole and is only granted the secure:viewpermission.

accounts: [
{
username: "admin"roles: ["administrator", "tester"]
permissions: ["powers:speed,strength,agility"]
}
{
username: "frank"roles: ["normal"]
}
{
username: "joe"roles: ["normal"]
disabled: true
}
]
roles: {
administrator: ["*"]
normal: ["secure:view"]
}

Tokens

Tokens may be specified on an account. Tokens are both powerful and dangerous because a token is an authentication alias for an Account. You might use a token in a request header of a RESTful API route.

!!! Note Because a token is an alias for an Account, each token must be unique across all realms.

accounts: [
{
username: "frank"roles: ["normal"]
tokens: ["cafebabe","deadbeef"]
}
]

Authorization

Account instances have many methods to enforce authorization for a particular action.

publicvoidupdate(Employeeemployee) {
Accountaccount = getAccount();
if (account.hasRole("administrator") || account.isPermitted("employee:update")) {
employeeDao.update(employee);
}
}

You can also enforce authorization with methods that throw an AuthorizationException rather than returning a boolean status.

publicvoidupdate(Employeeemployee) {
Accountaccount = getAccount();
account.checkPermission("employee:update");
employeeDao.update(employee);
}

Disabling Accounts

In the above example the joeaccount is disabled.

accounts: [
{
username: "joe"disabled: true
}
]

In this case the SecurityManager will not allow the joeaccount to authenticate.

Realms

There are many realm integrations available for Fathom.

RealmModule
Memorycom.gitblit.fathom:fathom-security
Filecom.gitblit.fathom:fathom-security
Htpasswdcom.gitblit.fathom:fathom-security-htpasswd
Keycloakcom.gitblit.fathom:fathom-security-keycloak
LDAPcom.gitblit.fathom:fathom-security-ldap
JDBCcom.gitblit.fathom:fathom-security-jdbc
Rediscom.gitblit.fathom:fathom-security-redis
PAMcom.gitblit.fathom:fathom-security-pam
Windowscom.gitblit.fathom:fathom-security-windows

Memory Realm

The Memory Realm defines Accounts & Roles within the conf/realms.conf resource file.

Accounts and Roles are loaded only once on startup.

Configuration

conf/realms.conf

realms: [
{
# MEMORY REALM# All Accounts and Roles are loaded from this definition and cached in a ConcurrentHashMap.name: "Memory Realm"type: "fathom.realm.MemoryRealm"accounts: [
{
name: "Administrator"username: "admin"password: "admin"emailAddresses: ["fathom@gitblit.com"]
roles: ["administrator"]
permissions: ["powers:speed,strength,agility"]
}
{name: "User", username: "user", password: "user", roles: ["normal"], disabled: true}
{name: "Guest", username: "guest", password: "guest"}
# assign metadata and a role to an htpasswd account
{name: "Luke Skywalker", username: "red5", roles: ["normal"]}
# assign a role to an ldap account
{username: "UserOne", roles: ["normal"]}
]
## Defined Roles are named and have an array of Permissions.#roles: {
administrator: ["*"]
normal: ["secure:view"]
}
}
]

File Realm

The File Realm defines Accounts & Roles in an external HOCON file.

This realm will hot-reload on modification to the HOCON file.

Configuration

conf/realms.conf

realms: [
{
# FILE REALM# All Accounts and Roles are loaded from this definition and cached in a ConcurrentHashMap.name: "File Realm"type: "fathom.realm.FileRealm"file: "classpath:conf/users.conf"
}
]

conf/users.conf

accounts: [
{
name: "Administrator"username: "admin"password: "admin"emailAddresses: ["fathom@gitblit.com"]
roles: ["administrator"]
permissions: ["powers:speed,strength,agility"]
}
{name: "User", username: "user", password: "user", roles: ["normal"], disabled: true}
{name: "Guest", username: "guest", password: "guest"}
# assign metadata and a role to an htpasswd account
{name: "Luke Skywalker", username: "red5", roles: ["normal"]}
# assign a role to an ldap account
{username: "UserOne", roles: ["normal"]}
]
## Defined Roles are named and have an array of Permissions.#roles: {
administrator: ["*"]
normal: ["secure:view"]
}

Htpasswd Realm

The Htpasswd Realm defines partial Accounts (username & password) in an htpasswd file.

This realm will hot-reload on modification to the htpasswd file.

!!! Note You may only authenticate against an Htpasswd Realm. This realm does not support persistence of authorization data.

Installation

Add the Fathom-Security-Htpasswd artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-htpasswd</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# HTPASSWD REALMname: "Htpasswd Realm"type: "fathom.realm.htpasswd.HtpasswdRealm"file: "classpath:conf/users.htpasswd"allowClearPasswords: false
}
]

Keycloak Realm

The Keycloak Realm allows you to authenticate and, optionally, authorize requests using your Keycloak identity management server.

Installation

Add the Fathom-Security-Keycloak artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-keycloak</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

There are two parts to configuring your Keycloak integration.

  1. You'll need a conf/keycloak.json file which your Keycloak realm will provide to you via the admin ui.
  2. You need to configure conf/realms.conf to specify add the fathom.realm.keycloak.KeycloakRealm.

conf/realms.conf

realms: [
{
# KEYCLOAK REALM# Authenticates credentials from an Keycloak server.name: "My Keycloak Realm"type: "fathom.realm.keycloak.KeycloakRealm"file: "classpath:conf/keycloak.json"
}
]

Usage

See Fathom-REST Security.


LDAP Realm

The LDAP Realm allows you to integrate authentication and authorization with your LDAP server.

!!! Note You may authenticate and authorize using LDAP-sourced data but Role definitions are not currently supported by the LDAP Realm.

Installation

Add the Fathom-Security-LDAP artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-ldap</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# LDAP REALM# Authenticates credentials from an LDAP server.# This is a CachingRealm which may optionally configure an expiring cache.name: "UnboundID LDAP"type: "fathom.realm.ldap.LdapRealm"url: "ldap://localhost:1389"username: "cn=Directory Manager"password: "password"# LDAP search syntax for looking up accounts.accountBase: "OU=Users,OU=UserControl,OU=MyOrganization,DC=MyDomain"accountPattern: "(&(objectClass=person)(sAMAccountName=${username}))"# LDAP search syntax for looking up groups.# LDAP group names are mapped to Roles.# Roles can be optionally mapped to permissions.groupBase: "OU=Groups,OU=UserControl,OU=MyOrganization,DC=MyDomain"groupMemberPattern: "(&(objectClass=group)(member=${dn}))"# Members of these LDAP Groups are given "*" administrator permissions.# Invidual accounts can be specified with the "@" prefixadminGroups: ["@UserThree", "Git_Admins", "Git Admins"]
# Mapping controls for account name and email address extraction.# These may be an attribute name or can be a complex expression.nameMapping: "displayName"emailMapping: "email"# Configure the cached Account time-to-live (TTL) in minutes and the maximum# number of accounts to keep cached.# A TTL of 0 disables this cache.cacheTtl: 0cacheMax: 100
}
]

JDBC Realm

The JDBC Realm allows you to integrate authentication and authorization with an SQL database.

Installation

Add the Fathom-Security-JDBC artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-jdbc</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# JDBC/SQL REALM# Authenticates credentials from an SQL datasource.# This is a CachingRealm which may optionally configure an expiring cache.name: "H2 Realm"type: "fathom.realm.jdbc.JdbcRealm"url: "jdbc:h2:mem:fathom"username: ""password: ""# Specify a script to run on startup of the Realm.# This script creates our tables and populates some data.startScript: "classpath:conf/realm.sql"# Specify an account query and column mappings to populate Account metadata.## This optional mapping only works for the table (or view) referenced in the# accountQuery.accountQuery: "select * from accounts where username=?"nameMapping: "name"passwordMapping: "password"# Email address column mapping if your addresses are in the same table as your accounts.# This value may be delimited by a comma or semi-colon to support multiple addresses.emailMapping: "email"# A Role column mapping if your roles are in the same table as your accounts.# This value may be delimited by a comma or semi-colon to support multiple roles.roleMapping: ""# A Permission column mapping if your permissions are in the same table as your accounts.# This value may be delimited by a semi-colon to support multiple permissions.permissionMapping: ""# Specify an account roles query.# This is useful if your roles are defined in a separate table from your accounts.## The first column of the ResultSet must be a String role name.# The String role name may be delimited by a comma or semi-colon to support multiple roles.accountRolesQuery: "select role from account_roles where username=?"# Specify an account permissions query.# This is useful if your permissions are defined in a separate table from your accounts.## The first column of the ResultSet must be a String permission value.# The String permission value may be delimited by a semi-colon to support multiple permissions.accountPermissionsQuery: "select permission from account_permissions where username=?"# Specify a defined roles query.# Defined roles specify permissions for a role name.## The first column of the ResultSet must be a String role name.# The second column of the ResultSet must be a String permission value.# The String definition value may be delimited by a semi-colon to support multiple permissions.definedRolesQuery: "select role, definition from defined_roles"# Configure the cached Account time-to-live (TTL) in minutes and the maximum# number of accounts to keep cached.# A TTL of 0 disables this cache.cacheTtl: 0cacheMax: 100# fathom-security-jdbc supports HikariCP# see http://brettwooldridge.github.io/HikariCP/hikariCP {
connectionTimeout: 5000registerMbeans: true
}
}
]

Redis Realm

The Redis Realm allows you to integrate authentication and authorization with a Redis server.

!!! Note You may authenticate and authorize using Redis-sourced data but Role definitions are not currently supported by the Redis Realm.

Installation

Add the Fathom-Security-Redis artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-redis</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# REDIS REALMname: "Redis Realm"type: "fathom.realm.redis.RedisRealm"# Specify the url to the Redis databaseurl: "redis://localhost:6379/8"# The password for the Redis server, if neededpassword: ""# Specify the key mappings for account and role lookupspasswordMapping: "fathom:${username}:password"nameMapping: "fathom:${username}:name"emailMapping: "fathom:${username}:email"roleMapping: "fathom:${username}:roles"permissionMapping: "fathom:${username}:permissions"
}
]

PAM Realm

The PAM Realm allows you to authenticate against the local accounts on a Linux/Unix/OSX machine.

!!! Note You may only authenticate against a PAM Realm. This realm does not support persistence of authorization data.

Installation

Add the Fathom-Security-PAM artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-pam</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# PAM REALMname: "PAM Realm"type: "fathom.realm.pam.PamRealm"serviceName: "system-auth"
}
]

Windows Realm

The Windows Realm allows you to authenticate against the local accounts on a Windows machine.

!!! Note You may only authenticate against a Windows Realm. This realm does not support persistence of authorization data.

Installation

Add the Fathom-Security-Windows artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-windows</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# WINDOWS REALMname: "Windows Realm"type: "fathom.realm.windows.WindowsRealm"defaultDomain: ""allowGuests: falseadminGroups: [ "BUILTIN\Administrators" ]
}
]

Clone this wiki locally

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
James Moger edited this page Jul 8, 2016 · 2 revisions

About

Fathom-Security provides support for multiple authentication realms and an authorization infrastructure.

The core authorization design of Apache Shiro was harvested & married to the core authentication design of Gitblit to form a similar but significantly lighterweight security infrastructure.

A complete authentication and authorization model will include declarations of:

Realms : Realms are sources of Accounts and potentially Roles and Permissions. Realms are interrogated during the authentication process.

Accounts : Accounts represent a username-password pair. They may also include additional metadata such as display name, email addresses, Roles, and Permissions.

Roles : Roles are a named grouping of specific Permissions.

Permissions : Permissions are allowed application actions.

Installation

Add the Fathom-Security artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security</artifactId>
<version>${fathom.version}</version>
</dependency>

Layout

YourApp
└── src
└── main
└── java
└── conf
└── realms.conf

Configuration

Fathom-Security is configured by the HOCON resource config file conf/realms.conf.

# Configured Realms.# Realms will be tried in the order specified until an authentication is successful.realms: []
# If you have multiple Realms and are creating aggregate Accounts you# may cache the aggregate/assembled accounts in the SecurityManager.## Configure the aggregated Account time-to-live (TTL) in minutes and the maximum# number of aggregated accounts to keep cached.# A TTL of 0 disables this cache.cacheTtl: 0cacheMax: 100

Specifying an Alternate Realms Config File

You may specify alternate realms config files in your conf/default.conf resource config file.

security.configurationFile = "classpath:conf/realms.conf"dev.security.configurationFile = "classpath:conf/realms-dev.conf"test.security.configurationFile = "classpath:conf/realms-test.conf"

Usage

Fathom-Security provides a singleton instance of a SecurityManagerservice. This service contains all loaded Realms, Accounts, Roles, and Permissions.

@InjectSecurityManagersecurityManager;
publicAccountlogin(Stringusername, Stringpassword) {
StandardCredentialscredentials = newStandardCredentials(username, password);
Accountaccount = securityManager.authenticate(credentials);
returnaccount;
}

Accounts

Account usernames are specified to be global across all realms. Fathom-Security will collect and merge account definitions across all defined realms to create an aggregate account. This is necessary because not all realms are able to provide full account metadata, roles, permissions, and tokens.

For example, the account named james is assumed to represent the same person across all defined realms so that if james authenticates against a PAM Realm, his account metadata, roles, and permissions can be collected from the jamesaccount defined in a File Realm, JDBC Realm, etc.

Permissions

Permissions are allowed application actions. Permissions can be specified as a simple action (e.g. view) or as a granular, colon-delimited action (e.g. employees:view:5). Granular permissions may be assigned with up to three components: domain:action:instance.

# Permit viewing employees 5 and 10
employees:view:5,10
# Permit viewing all employees (these are equivalent)
employees:view:*
employees:view
# Permit updating employees 5 and 10
employees:update:5,10
# Permit all actions on employee 5
employees:*:5
# Permit adding and deleting any employee (these are equivalent)
employees:add,delete:*
employees:add,delete
# Permit all actions on all employees and contractors
employees,contractors:*

Roles

Roles may be specified on an account. Roles may also be defined to have explicit permissions. The primary value of a role is that it allows you to forgo maintaining the same set of permissions on multiple accounts. Instead you can maintain a single set of permissions in the role definition and assign this role to multiple accounts.

In the example below, the adminaccount has two assigned roles. The administratorrole is explicitly defined with the *permission, while the testerrole has no definition and therefore has no explicit permissions. The frankaccount has been assigned the normalrole and is only granted the secure:viewpermission.

accounts: [
{
username: "admin"roles: ["administrator", "tester"]
permissions: ["powers:speed,strength,agility"]
}
{
username: "frank"roles: ["normal"]
}
{
username: "joe"roles: ["normal"]
disabled: true
}
]
roles: {
administrator: ["*"]
normal: ["secure:view"]
}

Tokens

Tokens may be specified on an account. Tokens are both powerful and dangerous because a token is an authentication alias for an Account. You might use a token in a request header of a RESTful API route.

!!! Note Because a token is an alias for an Account, each token must be unique across all realms.

accounts: [
{
username: "frank"roles: ["normal"]
tokens: ["cafebabe","deadbeef"]
}
]

Authorization

Account instances have many methods to enforce authorization for a particular action.

publicvoidupdate(Employeeemployee) {
Accountaccount = getAccount();
if (account.hasRole("administrator") || account.isPermitted("employee:update")) {
employeeDao.update(employee);
}
}

You can also enforce authorization with methods that throw an AuthorizationException rather than returning a boolean status.

publicvoidupdate(Employeeemployee) {
Accountaccount = getAccount();
account.checkPermission("employee:update");
employeeDao.update(employee);
}

Disabling Accounts

In the above example the joeaccount is disabled.

accounts: [
{
username: "joe"disabled: true
}
]

In this case the SecurityManager will not allow the joeaccount to authenticate.

Realms

There are many realm integrations available for Fathom.

RealmModule
Memorycom.gitblit.fathom:fathom-security
Filecom.gitblit.fathom:fathom-security
Htpasswdcom.gitblit.fathom:fathom-security-htpasswd
Keycloakcom.gitblit.fathom:fathom-security-keycloak
LDAPcom.gitblit.fathom:fathom-security-ldap
JDBCcom.gitblit.fathom:fathom-security-jdbc
Rediscom.gitblit.fathom:fathom-security-redis
PAMcom.gitblit.fathom:fathom-security-pam
Windowscom.gitblit.fathom:fathom-security-windows

Memory Realm

The Memory Realm defines Accounts & Roles within the conf/realms.conf resource file.

Accounts and Roles are loaded only once on startup.

Configuration

conf/realms.conf

realms: [
{
# MEMORY REALM# All Accounts and Roles are loaded from this definition and cached in a ConcurrentHashMap.name: "Memory Realm"type: "fathom.realm.MemoryRealm"accounts: [
{
name: "Administrator"username: "admin"password: "admin"emailAddresses: ["fathom@gitblit.com"]
roles: ["administrator"]
permissions: ["powers:speed,strength,agility"]
}
{name: "User", username: "user", password: "user", roles: ["normal"], disabled: true}
{name: "Guest", username: "guest", password: "guest"}
# assign metadata and a role to an htpasswd account
{name: "Luke Skywalker", username: "red5", roles: ["normal"]}
# assign a role to an ldap account
{username: "UserOne", roles: ["normal"]}
]
## Defined Roles are named and have an array of Permissions.#roles: {
administrator: ["*"]
normal: ["secure:view"]
}
}
]

File Realm

The File Realm defines Accounts & Roles in an external HOCON file.

This realm will hot-reload on modification to the HOCON file.

Configuration

conf/realms.conf

realms: [
{
# FILE REALM# All Accounts and Roles are loaded from this definition and cached in a ConcurrentHashMap.name: "File Realm"type: "fathom.realm.FileRealm"file: "classpath:conf/users.conf"
}
]

conf/users.conf

accounts: [
{
name: "Administrator"username: "admin"password: "admin"emailAddresses: ["fathom@gitblit.com"]
roles: ["administrator"]
permissions: ["powers:speed,strength,agility"]
}
{name: "User", username: "user", password: "user", roles: ["normal"], disabled: true}
{name: "Guest", username: "guest", password: "guest"}
# assign metadata and a role to an htpasswd account
{name: "Luke Skywalker", username: "red5", roles: ["normal"]}
# assign a role to an ldap account
{username: "UserOne", roles: ["normal"]}
]
## Defined Roles are named and have an array of Permissions.#roles: {
administrator: ["*"]
normal: ["secure:view"]
}

Htpasswd Realm

The Htpasswd Realm defines partial Accounts (username & password) in an htpasswd file.

This realm will hot-reload on modification to the htpasswd file.

!!! Note You may only authenticate against an Htpasswd Realm. This realm does not support persistence of authorization data.

Installation

Add the Fathom-Security-Htpasswd artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-htpasswd</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# HTPASSWD REALMname: "Htpasswd Realm"type: "fathom.realm.htpasswd.HtpasswdRealm"file: "classpath:conf/users.htpasswd"allowClearPasswords: false
}
]

Keycloak Realm

The Keycloak Realm allows you to authenticate and, optionally, authorize requests using your Keycloak identity management server.

Installation

Add the Fathom-Security-Keycloak artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-keycloak</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

There are two parts to configuring your Keycloak integration.

  1. You'll need a conf/keycloak.json file which your Keycloak realm will provide to you via the admin ui.
  2. You need to configure conf/realms.conf to specify add the fathom.realm.keycloak.KeycloakRealm.

conf/realms.conf

realms: [
{
# KEYCLOAK REALM# Authenticates credentials from an Keycloak server.name: "My Keycloak Realm"type: "fathom.realm.keycloak.KeycloakRealm"file: "classpath:conf/keycloak.json"
}
]

Usage

See Fathom-REST Security.


LDAP Realm

The LDAP Realm allows you to integrate authentication and authorization with your LDAP server.

!!! Note You may authenticate and authorize using LDAP-sourced data but Role definitions are not currently supported by the LDAP Realm.

Installation

Add the Fathom-Security-LDAP artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-ldap</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# LDAP REALM# Authenticates credentials from an LDAP server.# This is a CachingRealm which may optionally configure an expiring cache.name: "UnboundID LDAP"type: "fathom.realm.ldap.LdapRealm"url: "ldap://localhost:1389"username: "cn=Directory Manager"password: "password"# LDAP search syntax for looking up accounts.accountBase: "OU=Users,OU=UserControl,OU=MyOrganization,DC=MyDomain"accountPattern: "(&(objectClass=person)(sAMAccountName=${username}))"# LDAP search syntax for looking up groups.# LDAP group names are mapped to Roles.# Roles can be optionally mapped to permissions.groupBase: "OU=Groups,OU=UserControl,OU=MyOrganization,DC=MyDomain"groupMemberPattern: "(&(objectClass=group)(member=${dn}))"# Members of these LDAP Groups are given "*" administrator permissions.# Invidual accounts can be specified with the "@" prefixadminGroups: ["@UserThree", "Git_Admins", "Git Admins"]
# Mapping controls for account name and email address extraction.# These may be an attribute name or can be a complex expression.nameMapping: "displayName"emailMapping: "email"# Configure the cached Account time-to-live (TTL) in minutes and the maximum# number of accounts to keep cached.# A TTL of 0 disables this cache.cacheTtl: 0cacheMax: 100
}
]

JDBC Realm

The JDBC Realm allows you to integrate authentication and authorization with an SQL database.

Installation

Add the Fathom-Security-JDBC artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-jdbc</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# JDBC/SQL REALM# Authenticates credentials from an SQL datasource.# This is a CachingRealm which may optionally configure an expiring cache.name: "H2 Realm"type: "fathom.realm.jdbc.JdbcRealm"url: "jdbc:h2:mem:fathom"username: ""password: ""# Specify a script to run on startup of the Realm.# This script creates our tables and populates some data.startScript: "classpath:conf/realm.sql"# Specify an account query and column mappings to populate Account metadata.## This optional mapping only works for the table (or view) referenced in the# accountQuery.accountQuery: "select * from accounts where username=?"nameMapping: "name"passwordMapping: "password"# Email address column mapping if your addresses are in the same table as your accounts.# This value may be delimited by a comma or semi-colon to support multiple addresses.emailMapping: "email"# A Role column mapping if your roles are in the same table as your accounts.# This value may be delimited by a comma or semi-colon to support multiple roles.roleMapping: ""# A Permission column mapping if your permissions are in the same table as your accounts.# This value may be delimited by a semi-colon to support multiple permissions.permissionMapping: ""# Specify an account roles query.# This is useful if your roles are defined in a separate table from your accounts.## The first column of the ResultSet must be a String role name.# The String role name may be delimited by a comma or semi-colon to support multiple roles.accountRolesQuery: "select role from account_roles where username=?"# Specify an account permissions query.# This is useful if your permissions are defined in a separate table from your accounts.## The first column of the ResultSet must be a String permission value.# The String permission value may be delimited by a semi-colon to support multiple permissions.accountPermissionsQuery: "select permission from account_permissions where username=?"# Specify a defined roles query.# Defined roles specify permissions for a role name.## The first column of the ResultSet must be a String role name.# The second column of the ResultSet must be a String permission value.# The String definition value may be delimited by a semi-colon to support multiple permissions.definedRolesQuery: "select role, definition from defined_roles"# Configure the cached Account time-to-live (TTL) in minutes and the maximum# number of accounts to keep cached.# A TTL of 0 disables this cache.cacheTtl: 0cacheMax: 100# fathom-security-jdbc supports HikariCP# see http://brettwooldridge.github.io/HikariCP/hikariCP {
connectionTimeout: 5000registerMbeans: true
}
}
]

Redis Realm

The Redis Realm allows you to integrate authentication and authorization with a Redis server.

!!! Note You may authenticate and authorize using Redis-sourced data but Role definitions are not currently supported by the Redis Realm.

Installation

Add the Fathom-Security-Redis artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-redis</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# REDIS REALMname: "Redis Realm"type: "fathom.realm.redis.RedisRealm"# Specify the url to the Redis databaseurl: "redis://localhost:6379/8"# The password for the Redis server, if neededpassword: ""# Specify the key mappings for account and role lookupspasswordMapping: "fathom:${username}:password"nameMapping: "fathom:${username}:name"emailMapping: "fathom:${username}:email"roleMapping: "fathom:${username}:roles"permissionMapping: "fathom:${username}:permissions"
}
]

PAM Realm

The PAM Realm allows you to authenticate against the local accounts on a Linux/Unix/OSX machine.

!!! Note You may only authenticate against a PAM Realm. This realm does not support persistence of authorization data.

Installation

Add the Fathom-Security-PAM artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-pam</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# PAM REALMname: "PAM Realm"type: "fathom.realm.pam.PamRealm"serviceName: "system-auth"
}
]

Windows Realm

The Windows Realm allows you to authenticate against the local accounts on a Windows machine.

!!! Note You may only authenticate against a Windows Realm. This realm does not support persistence of authorization data.

Installation

Add the Fathom-Security-Windows artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-windows</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# WINDOWS REALMname: "Windows Realm"type: "fathom.realm.windows.WindowsRealm"defaultDomain: ""allowGuests: falseadminGroups: [ "BUILTIN\Administrators" ]
}
]

Clone this wiki locally

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
James Moger edited this page Jul 8, 2016 · 2 revisions

About

Fathom-Security provides support for multiple authentication realms and an authorization infrastructure.

The core authorization design of Apache Shiro was harvested & married to the core authentication design of Gitblit to form a similar but significantly lighterweight security infrastructure.

A complete authentication and authorization model will include declarations of:

Realms : Realms are sources of Accounts and potentially Roles and Permissions. Realms are interrogated during the authentication process.

Accounts : Accounts represent a username-password pair. They may also include additional metadata such as display name, email addresses, Roles, and Permissions.

Roles : Roles are a named grouping of specific Permissions.

Permissions : Permissions are allowed application actions.

Installation

Add the Fathom-Security artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security</artifactId>
<version>${fathom.version}</version>
</dependency>

Layout

YourApp
└── src
└── main
└── java
└── conf
└── realms.conf

Configuration

Fathom-Security is configured by the HOCON resource config file conf/realms.conf.

# Configured Realms.# Realms will be tried in the order specified until an authentication is successful.realms: []
# If you have multiple Realms and are creating aggregate Accounts you# may cache the aggregate/assembled accounts in the SecurityManager.## Configure the aggregated Account time-to-live (TTL) in minutes and the maximum# number of aggregated accounts to keep cached.# A TTL of 0 disables this cache.cacheTtl: 0cacheMax: 100

Specifying an Alternate Realms Config File

You may specify alternate realms config files in your conf/default.conf resource config file.

security.configurationFile = "classpath:conf/realms.conf"dev.security.configurationFile = "classpath:conf/realms-dev.conf"test.security.configurationFile = "classpath:conf/realms-test.conf"

Usage

Fathom-Security provides a singleton instance of a SecurityManagerservice. This service contains all loaded Realms, Accounts, Roles, and Permissions.

@InjectSecurityManagersecurityManager;
publicAccountlogin(Stringusername, Stringpassword) {
StandardCredentialscredentials = newStandardCredentials(username, password);
Accountaccount = securityManager.authenticate(credentials);
returnaccount;
}

Accounts

Account usernames are specified to be global across all realms. Fathom-Security will collect and merge account definitions across all defined realms to create an aggregate account. This is necessary because not all realms are able to provide full account metadata, roles, permissions, and tokens.

For example, the account named james is assumed to represent the same person across all defined realms so that if james authenticates against a PAM Realm, his account metadata, roles, and permissions can be collected from the jamesaccount defined in a File Realm, JDBC Realm, etc.

Permissions

Permissions are allowed application actions. Permissions can be specified as a simple action (e.g. view) or as a granular, colon-delimited action (e.g. employees:view:5). Granular permissions may be assigned with up to three components: domain:action:instance.

# Permit viewing employees 5 and 10
employees:view:5,10
# Permit viewing all employees (these are equivalent)
employees:view:*
employees:view
# Permit updating employees 5 and 10
employees:update:5,10
# Permit all actions on employee 5
employees:*:5
# Permit adding and deleting any employee (these are equivalent)
employees:add,delete:*
employees:add,delete
# Permit all actions on all employees and contractors
employees,contractors:*

Roles

Roles may be specified on an account. Roles may also be defined to have explicit permissions. The primary value of a role is that it allows you to forgo maintaining the same set of permissions on multiple accounts. Instead you can maintain a single set of permissions in the role definition and assign this role to multiple accounts.

In the example below, the adminaccount has two assigned roles. The administratorrole is explicitly defined with the *permission, while the testerrole has no definition and therefore has no explicit permissions. The frankaccount has been assigned the normalrole and is only granted the secure:viewpermission.

accounts: [
{
username: "admin"roles: ["administrator", "tester"]
permissions: ["powers:speed,strength,agility"]
}
{
username: "frank"roles: ["normal"]
}
{
username: "joe"roles: ["normal"]
disabled: true
}
]
roles: {
administrator: ["*"]
normal: ["secure:view"]
}

Tokens

Tokens may be specified on an account. Tokens are both powerful and dangerous because a token is an authentication alias for an Account. You might use a token in a request header of a RESTful API route.

!!! Note Because a token is an alias for an Account, each token must be unique across all realms.

accounts: [
{
username: "frank"roles: ["normal"]
tokens: ["cafebabe","deadbeef"]
}
]

Authorization

Account instances have many methods to enforce authorization for a particular action.

publicvoidupdate(Employeeemployee) {
Accountaccount = getAccount();
if (account.hasRole("administrator") || account.isPermitted("employee:update")) {
employeeDao.update(employee);
}
}

You can also enforce authorization with methods that throw an AuthorizationException rather than returning a boolean status.

publicvoidupdate(Employeeemployee) {
Accountaccount = getAccount();
account.checkPermission("employee:update");
employeeDao.update(employee);
}

Disabling Accounts

In the above example the joeaccount is disabled.

accounts: [
{
username: "joe"disabled: true
}
]

In this case the SecurityManager will not allow the joeaccount to authenticate.

Realms

There are many realm integrations available for Fathom.

RealmModule
Memorycom.gitblit.fathom:fathom-security
Filecom.gitblit.fathom:fathom-security
Htpasswdcom.gitblit.fathom:fathom-security-htpasswd
Keycloakcom.gitblit.fathom:fathom-security-keycloak
LDAPcom.gitblit.fathom:fathom-security-ldap
JDBCcom.gitblit.fathom:fathom-security-jdbc
Rediscom.gitblit.fathom:fathom-security-redis
PAMcom.gitblit.fathom:fathom-security-pam
Windowscom.gitblit.fathom:fathom-security-windows

Memory Realm

The Memory Realm defines Accounts & Roles within the conf/realms.conf resource file.

Accounts and Roles are loaded only once on startup.

Configuration

conf/realms.conf

realms: [
{
# MEMORY REALM# All Accounts and Roles are loaded from this definition and cached in a ConcurrentHashMap.name: "Memory Realm"type: "fathom.realm.MemoryRealm"accounts: [
{
name: "Administrator"username: "admin"password: "admin"emailAddresses: ["fathom@gitblit.com"]
roles: ["administrator"]
permissions: ["powers:speed,strength,agility"]
}
{name: "User", username: "user", password: "user", roles: ["normal"], disabled: true}
{name: "Guest", username: "guest", password: "guest"}
# assign metadata and a role to an htpasswd account
{name: "Luke Skywalker", username: "red5", roles: ["normal"]}
# assign a role to an ldap account
{username: "UserOne", roles: ["normal"]}
]
## Defined Roles are named and have an array of Permissions.#roles: {
administrator: ["*"]
normal: ["secure:view"]
}
}
]

File Realm

The File Realm defines Accounts & Roles in an external HOCON file.

This realm will hot-reload on modification to the HOCON file.

Configuration

conf/realms.conf

realms: [
{
# FILE REALM# All Accounts and Roles are loaded from this definition and cached in a ConcurrentHashMap.name: "File Realm"type: "fathom.realm.FileRealm"file: "classpath:conf/users.conf"
}
]

conf/users.conf

accounts: [
{
name: "Administrator"username: "admin"password: "admin"emailAddresses: ["fathom@gitblit.com"]
roles: ["administrator"]
permissions: ["powers:speed,strength,agility"]
}
{name: "User", username: "user", password: "user", roles: ["normal"], disabled: true}
{name: "Guest", username: "guest", password: "guest"}
# assign metadata and a role to an htpasswd account
{name: "Luke Skywalker", username: "red5", roles: ["normal"]}
# assign a role to an ldap account
{username: "UserOne", roles: ["normal"]}
]
## Defined Roles are named and have an array of Permissions.#roles: {
administrator: ["*"]
normal: ["secure:view"]
}

Htpasswd Realm

The Htpasswd Realm defines partial Accounts (username & password) in an htpasswd file.

This realm will hot-reload on modification to the htpasswd file.

!!! Note You may only authenticate against an Htpasswd Realm. This realm does not support persistence of authorization data.

Installation

Add the Fathom-Security-Htpasswd artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-htpasswd</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# HTPASSWD REALMname: "Htpasswd Realm"type: "fathom.realm.htpasswd.HtpasswdRealm"file: "classpath:conf/users.htpasswd"allowClearPasswords: false
}
]

Keycloak Realm

The Keycloak Realm allows you to authenticate and, optionally, authorize requests using your Keycloak identity management server.

Installation

Add the Fathom-Security-Keycloak artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-keycloak</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

There are two parts to configuring your Keycloak integration.

  1. You'll need a conf/keycloak.json file which your Keycloak realm will provide to you via the admin ui.
  2. You need to configure conf/realms.conf to specify add the fathom.realm.keycloak.KeycloakRealm.

conf/realms.conf

realms: [
{
# KEYCLOAK REALM# Authenticates credentials from an Keycloak server.name: "My Keycloak Realm"type: "fathom.realm.keycloak.KeycloakRealm"file: "classpath:conf/keycloak.json"
}
]

Usage

See Fathom-REST Security.


LDAP Realm

The LDAP Realm allows you to integrate authentication and authorization with your LDAP server.

!!! Note You may authenticate and authorize using LDAP-sourced data but Role definitions are not currently supported by the LDAP Realm.

Installation

Add the Fathom-Security-LDAP artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-ldap</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# LDAP REALM# Authenticates credentials from an LDAP server.# This is a CachingRealm which may optionally configure an expiring cache.name: "UnboundID LDAP"type: "fathom.realm.ldap.LdapRealm"url: "ldap://localhost:1389"username: "cn=Directory Manager"password: "password"# LDAP search syntax for looking up accounts.accountBase: "OU=Users,OU=UserControl,OU=MyOrganization,DC=MyDomain"accountPattern: "(&(objectClass=person)(sAMAccountName=${username}))"# LDAP search syntax for looking up groups.# LDAP group names are mapped to Roles.# Roles can be optionally mapped to permissions.groupBase: "OU=Groups,OU=UserControl,OU=MyOrganization,DC=MyDomain"groupMemberPattern: "(&(objectClass=group)(member=${dn}))"# Members of these LDAP Groups are given "*" administrator permissions.# Invidual accounts can be specified with the "@" prefixadminGroups: ["@UserThree", "Git_Admins", "Git Admins"]
# Mapping controls for account name and email address extraction.# These may be an attribute name or can be a complex expression.nameMapping: "displayName"emailMapping: "email"# Configure the cached Account time-to-live (TTL) in minutes and the maximum# number of accounts to keep cached.# A TTL of 0 disables this cache.cacheTtl: 0cacheMax: 100
}
]

JDBC Realm

The JDBC Realm allows you to integrate authentication and authorization with an SQL database.

Installation

Add the Fathom-Security-JDBC artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-jdbc</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# JDBC/SQL REALM# Authenticates credentials from an SQL datasource.# This is a CachingRealm which may optionally configure an expiring cache.name: "H2 Realm"type: "fathom.realm.jdbc.JdbcRealm"url: "jdbc:h2:mem:fathom"username: ""password: ""# Specify a script to run on startup of the Realm.# This script creates our tables and populates some data.startScript: "classpath:conf/realm.sql"# Specify an account query and column mappings to populate Account metadata.## This optional mapping only works for the table (or view) referenced in the# accountQuery.accountQuery: "select * from accounts where username=?"nameMapping: "name"passwordMapping: "password"# Email address column mapping if your addresses are in the same table as your accounts.# This value may be delimited by a comma or semi-colon to support multiple addresses.emailMapping: "email"# A Role column mapping if your roles are in the same table as your accounts.# This value may be delimited by a comma or semi-colon to support multiple roles.roleMapping: ""# A Permission column mapping if your permissions are in the same table as your accounts.# This value may be delimited by a semi-colon to support multiple permissions.permissionMapping: ""# Specify an account roles query.# This is useful if your roles are defined in a separate table from your accounts.## The first column of the ResultSet must be a String role name.# The String role name may be delimited by a comma or semi-colon to support multiple roles.accountRolesQuery: "select role from account_roles where username=?"# Specify an account permissions query.# This is useful if your permissions are defined in a separate table from your accounts.## The first column of the ResultSet must be a String permission value.# The String permission value may be delimited by a semi-colon to support multiple permissions.accountPermissionsQuery: "select permission from account_permissions where username=?"# Specify a defined roles query.# Defined roles specify permissions for a role name.## The first column of the ResultSet must be a String role name.# The second column of the ResultSet must be a String permission value.# The String definition value may be delimited by a semi-colon to support multiple permissions.definedRolesQuery: "select role, definition from defined_roles"# Configure the cached Account time-to-live (TTL) in minutes and the maximum# number of accounts to keep cached.# A TTL of 0 disables this cache.cacheTtl: 0cacheMax: 100# fathom-security-jdbc supports HikariCP# see http://brettwooldridge.github.io/HikariCP/hikariCP {
connectionTimeout: 5000registerMbeans: true
}
}
]

Redis Realm

The Redis Realm allows you to integrate authentication and authorization with a Redis server.

!!! Note You may authenticate and authorize using Redis-sourced data but Role definitions are not currently supported by the Redis Realm.

Installation

Add the Fathom-Security-Redis artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-redis</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# REDIS REALMname: "Redis Realm"type: "fathom.realm.redis.RedisRealm"# Specify the url to the Redis databaseurl: "redis://localhost:6379/8"# The password for the Redis server, if neededpassword: ""# Specify the key mappings for account and role lookupspasswordMapping: "fathom:${username}:password"nameMapping: "fathom:${username}:name"emailMapping: "fathom:${username}:email"roleMapping: "fathom:${username}:roles"permissionMapping: "fathom:${username}:permissions"
}
]

PAM Realm

The PAM Realm allows you to authenticate against the local accounts on a Linux/Unix/OSX machine.

!!! Note You may only authenticate against a PAM Realm. This realm does not support persistence of authorization data.

Installation

Add the Fathom-Security-PAM artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-pam</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# PAM REALMname: "PAM Realm"type: "fathom.realm.pam.PamRealm"serviceName: "system-auth"
}
]

Windows Realm

The Windows Realm allows you to authenticate against the local accounts on a Windows machine.

!!! Note You may only authenticate against a Windows Realm. This realm does not support persistence of authorization data.

Installation

Add the Fathom-Security-Windows artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-windows</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# WINDOWS REALMname: "Windows Realm"type: "fathom.realm.windows.WindowsRealm"defaultDomain: ""allowGuests: falseadminGroups: [ "BUILTIN\Administrators" ]
}
]

Clone this wiki locally

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
James Moger edited this page Jul 8, 2016 · 2 revisions

About

Fathom-Security provides support for multiple authentication realms and an authorization infrastructure.

The core authorization design of Apache Shiro was harvested & married to the core authentication design of Gitblit to form a similar but significantly lighterweight security infrastructure.

A complete authentication and authorization model will include declarations of:

Realms : Realms are sources of Accounts and potentially Roles and Permissions. Realms are interrogated during the authentication process.

Accounts : Accounts represent a username-password pair. They may also include additional metadata such as display name, email addresses, Roles, and Permissions.

Roles : Roles are a named grouping of specific Permissions.

Permissions : Permissions are allowed application actions.

Installation

Add the Fathom-Security artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security</artifactId>
<version>${fathom.version}</version>
</dependency>

Layout

YourApp
└── src
└── main
└── java
└── conf
└── realms.conf

Configuration

Fathom-Security is configured by the HOCON resource config file conf/realms.conf.

# Configured Realms.# Realms will be tried in the order specified until an authentication is successful.realms: []
# If you have multiple Realms and are creating aggregate Accounts you# may cache the aggregate/assembled accounts in the SecurityManager.## Configure the aggregated Account time-to-live (TTL) in minutes and the maximum# number of aggregated accounts to keep cached.# A TTL of 0 disables this cache.cacheTtl: 0cacheMax: 100

Specifying an Alternate Realms Config File

You may specify alternate realms config files in your conf/default.conf resource config file.

security.configurationFile = "classpath:conf/realms.conf"dev.security.configurationFile = "classpath:conf/realms-dev.conf"test.security.configurationFile = "classpath:conf/realms-test.conf"

Usage

Fathom-Security provides a singleton instance of a SecurityManagerservice. This service contains all loaded Realms, Accounts, Roles, and Permissions.

@InjectSecurityManagersecurityManager;
publicAccountlogin(Stringusername, Stringpassword) {
StandardCredentialscredentials = newStandardCredentials(username, password);
Accountaccount = securityManager.authenticate(credentials);
returnaccount;
}

Accounts

Account usernames are specified to be global across all realms. Fathom-Security will collect and merge account definitions across all defined realms to create an aggregate account. This is necessary because not all realms are able to provide full account metadata, roles, permissions, and tokens.

For example, the account named james is assumed to represent the same person across all defined realms so that if james authenticates against a PAM Realm, his account metadata, roles, and permissions can be collected from the jamesaccount defined in a File Realm, JDBC Realm, etc.

Permissions

Permissions are allowed application actions. Permissions can be specified as a simple action (e.g. view) or as a granular, colon-delimited action (e.g. employees:view:5). Granular permissions may be assigned with up to three components: domain:action:instance.

# Permit viewing employees 5 and 10
employees:view:5,10
# Permit viewing all employees (these are equivalent)
employees:view:*
employees:view
# Permit updating employees 5 and 10
employees:update:5,10
# Permit all actions on employee 5
employees:*:5
# Permit adding and deleting any employee (these are equivalent)
employees:add,delete:*
employees:add,delete
# Permit all actions on all employees and contractors
employees,contractors:*

Roles

Roles may be specified on an account. Roles may also be defined to have explicit permissions. The primary value of a role is that it allows you to forgo maintaining the same set of permissions on multiple accounts. Instead you can maintain a single set of permissions in the role definition and assign this role to multiple accounts.

In the example below, the adminaccount has two assigned roles. The administratorrole is explicitly defined with the *permission, while the testerrole has no definition and therefore has no explicit permissions. The frankaccount has been assigned the normalrole and is only granted the secure:viewpermission.

accounts: [
{
username: "admin"roles: ["administrator", "tester"]
permissions: ["powers:speed,strength,agility"]
}
{
username: "frank"roles: ["normal"]
}
{
username: "joe"roles: ["normal"]
disabled: true
}
]
roles: {
administrator: ["*"]
normal: ["secure:view"]
}

Tokens

Tokens may be specified on an account. Tokens are both powerful and dangerous because a token is an authentication alias for an Account. You might use a token in a request header of a RESTful API route.

!!! Note Because a token is an alias for an Account, each token must be unique across all realms.

accounts: [
{
username: "frank"roles: ["normal"]
tokens: ["cafebabe","deadbeef"]
}
]

Authorization

Account instances have many methods to enforce authorization for a particular action.

publicvoidupdate(Employeeemployee) {
Accountaccount = getAccount();
if (account.hasRole("administrator") || account.isPermitted("employee:update")) {
employeeDao.update(employee);
}
}

You can also enforce authorization with methods that throw an AuthorizationException rather than returning a boolean status.

publicvoidupdate(Employeeemployee) {
Accountaccount = getAccount();
account.checkPermission("employee:update");
employeeDao.update(employee);
}

Disabling Accounts

In the above example the joeaccount is disabled.

accounts: [
{
username: "joe"disabled: true
}
]

In this case the SecurityManager will not allow the joeaccount to authenticate.

Realms

There are many realm integrations available for Fathom.

RealmModule
Memorycom.gitblit.fathom:fathom-security
Filecom.gitblit.fathom:fathom-security
Htpasswdcom.gitblit.fathom:fathom-security-htpasswd
Keycloakcom.gitblit.fathom:fathom-security-keycloak
LDAPcom.gitblit.fathom:fathom-security-ldap
JDBCcom.gitblit.fathom:fathom-security-jdbc
Rediscom.gitblit.fathom:fathom-security-redis
PAMcom.gitblit.fathom:fathom-security-pam
Windowscom.gitblit.fathom:fathom-security-windows

Memory Realm

The Memory Realm defines Accounts & Roles within the conf/realms.conf resource file.

Accounts and Roles are loaded only once on startup.

Configuration

conf/realms.conf

realms: [
{
# MEMORY REALM# All Accounts and Roles are loaded from this definition and cached in a ConcurrentHashMap.name: "Memory Realm"type: "fathom.realm.MemoryRealm"accounts: [
{
name: "Administrator"username: "admin"password: "admin"emailAddresses: ["fathom@gitblit.com"]
roles: ["administrator"]
permissions: ["powers:speed,strength,agility"]
}
{name: "User", username: "user", password: "user", roles: ["normal"], disabled: true}
{name: "Guest", username: "guest", password: "guest"}
# assign metadata and a role to an htpasswd account
{name: "Luke Skywalker", username: "red5", roles: ["normal"]}
# assign a role to an ldap account
{username: "UserOne", roles: ["normal"]}
]
## Defined Roles are named and have an array of Permissions.#roles: {
administrator: ["*"]
normal: ["secure:view"]
}
}
]

File Realm

The File Realm defines Accounts & Roles in an external HOCON file.

This realm will hot-reload on modification to the HOCON file.

Configuration

conf/realms.conf

realms: [
{
# FILE REALM# All Accounts and Roles are loaded from this definition and cached in a ConcurrentHashMap.name: "File Realm"type: "fathom.realm.FileRealm"file: "classpath:conf/users.conf"
}
]

conf/users.conf

accounts: [
{
name: "Administrator"username: "admin"password: "admin"emailAddresses: ["fathom@gitblit.com"]
roles: ["administrator"]
permissions: ["powers:speed,strength,agility"]
}
{name: "User", username: "user", password: "user", roles: ["normal"], disabled: true}
{name: "Guest", username: "guest", password: "guest"}
# assign metadata and a role to an htpasswd account
{name: "Luke Skywalker", username: "red5", roles: ["normal"]}
# assign a role to an ldap account
{username: "UserOne", roles: ["normal"]}
]
## Defined Roles are named and have an array of Permissions.#roles: {
administrator: ["*"]
normal: ["secure:view"]
}

Htpasswd Realm

The Htpasswd Realm defines partial Accounts (username & password) in an htpasswd file.

This realm will hot-reload on modification to the htpasswd file.

!!! Note You may only authenticate against an Htpasswd Realm. This realm does not support persistence of authorization data.

Installation

Add the Fathom-Security-Htpasswd artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-htpasswd</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# HTPASSWD REALMname: "Htpasswd Realm"type: "fathom.realm.htpasswd.HtpasswdRealm"file: "classpath:conf/users.htpasswd"allowClearPasswords: false
}
]

Keycloak Realm

The Keycloak Realm allows you to authenticate and, optionally, authorize requests using your Keycloak identity management server.

Installation

Add the Fathom-Security-Keycloak artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-keycloak</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

There are two parts to configuring your Keycloak integration.

  1. You'll need a conf/keycloak.json file which your Keycloak realm will provide to you via the admin ui.
  2. You need to configure conf/realms.conf to specify add the fathom.realm.keycloak.KeycloakRealm.

conf/realms.conf

realms: [
{
# KEYCLOAK REALM# Authenticates credentials from an Keycloak server.name: "My Keycloak Realm"type: "fathom.realm.keycloak.KeycloakRealm"file: "classpath:conf/keycloak.json"
}
]

Usage

See Fathom-REST Security.


LDAP Realm

The LDAP Realm allows you to integrate authentication and authorization with your LDAP server.

!!! Note You may authenticate and authorize using LDAP-sourced data but Role definitions are not currently supported by the LDAP Realm.

Installation

Add the Fathom-Security-LDAP artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-ldap</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# LDAP REALM# Authenticates credentials from an LDAP server.# This is a CachingRealm which may optionally configure an expiring cache.name: "UnboundID LDAP"type: "fathom.realm.ldap.LdapRealm"url: "ldap://localhost:1389"username: "cn=Directory Manager"password: "password"# LDAP search syntax for looking up accounts.accountBase: "OU=Users,OU=UserControl,OU=MyOrganization,DC=MyDomain"accountPattern: "(&(objectClass=person)(sAMAccountName=${username}))"# LDAP search syntax for looking up groups.# LDAP group names are mapped to Roles.# Roles can be optionally mapped to permissions.groupBase: "OU=Groups,OU=UserControl,OU=MyOrganization,DC=MyDomain"groupMemberPattern: "(&(objectClass=group)(member=${dn}))"# Members of these LDAP Groups are given "*" administrator permissions.# Invidual accounts can be specified with the "@" prefixadminGroups: ["@UserThree", "Git_Admins", "Git Admins"]
# Mapping controls for account name and email address extraction.# These may be an attribute name or can be a complex expression.nameMapping: "displayName"emailMapping: "email"# Configure the cached Account time-to-live (TTL) in minutes and the maximum# number of accounts to keep cached.# A TTL of 0 disables this cache.cacheTtl: 0cacheMax: 100
}
]

JDBC Realm

The JDBC Realm allows you to integrate authentication and authorization with an SQL database.

Installation

Add the Fathom-Security-JDBC artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-jdbc</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# JDBC/SQL REALM# Authenticates credentials from an SQL datasource.# This is a CachingRealm which may optionally configure an expiring cache.name: "H2 Realm"type: "fathom.realm.jdbc.JdbcRealm"url: "jdbc:h2:mem:fathom"username: ""password: ""# Specify a script to run on startup of the Realm.# This script creates our tables and populates some data.startScript: "classpath:conf/realm.sql"# Specify an account query and column mappings to populate Account metadata.## This optional mapping only works for the table (or view) referenced in the# accountQuery.accountQuery: "select * from accounts where username=?"nameMapping: "name"passwordMapping: "password"# Email address column mapping if your addresses are in the same table as your accounts.# This value may be delimited by a comma or semi-colon to support multiple addresses.emailMapping: "email"# A Role column mapping if your roles are in the same table as your accounts.# This value may be delimited by a comma or semi-colon to support multiple roles.roleMapping: ""# A Permission column mapping if your permissions are in the same table as your accounts.# This value may be delimited by a semi-colon to support multiple permissions.permissionMapping: ""# Specify an account roles query.# This is useful if your roles are defined in a separate table from your accounts.## The first column of the ResultSet must be a String role name.# The String role name may be delimited by a comma or semi-colon to support multiple roles.accountRolesQuery: "select role from account_roles where username=?"# Specify an account permissions query.# This is useful if your permissions are defined in a separate table from your accounts.## The first column of the ResultSet must be a String permission value.# The String permission value may be delimited by a semi-colon to support multiple permissions.accountPermissionsQuery: "select permission from account_permissions where username=?"# Specify a defined roles query.# Defined roles specify permissions for a role name.## The first column of the ResultSet must be a String role name.# The second column of the ResultSet must be a String permission value.# The String definition value may be delimited by a semi-colon to support multiple permissions.definedRolesQuery: "select role, definition from defined_roles"# Configure the cached Account time-to-live (TTL) in minutes and the maximum# number of accounts to keep cached.# A TTL of 0 disables this cache.cacheTtl: 0cacheMax: 100# fathom-security-jdbc supports HikariCP# see http://brettwooldridge.github.io/HikariCP/hikariCP {
connectionTimeout: 5000registerMbeans: true
}
}
]

Redis Realm

The Redis Realm allows you to integrate authentication and authorization with a Redis server.

!!! Note You may authenticate and authorize using Redis-sourced data but Role definitions are not currently supported by the Redis Realm.

Installation

Add the Fathom-Security-Redis artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-redis</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# REDIS REALMname: "Redis Realm"type: "fathom.realm.redis.RedisRealm"# Specify the url to the Redis databaseurl: "redis://localhost:6379/8"# The password for the Redis server, if neededpassword: ""# Specify the key mappings for account and role lookupspasswordMapping: "fathom:${username}:password"nameMapping: "fathom:${username}:name"emailMapping: "fathom:${username}:email"roleMapping: "fathom:${username}:roles"permissionMapping: "fathom:${username}:permissions"
}
]

PAM Realm

The PAM Realm allows you to authenticate against the local accounts on a Linux/Unix/OSX machine.

!!! Note You may only authenticate against a PAM Realm. This realm does not support persistence of authorization data.

Installation

Add the Fathom-Security-PAM artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-pam</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# PAM REALMname: "PAM Realm"type: "fathom.realm.pam.PamRealm"serviceName: "system-auth"
}
]

Windows Realm

The Windows Realm allows you to authenticate against the local accounts on a Windows machine.

!!! Note You may only authenticate against a Windows Realm. This realm does not support persistence of authorization data.

Installation

Add the Fathom-Security-Windows artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-windows</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# WINDOWS REALMname: "Windows Realm"type: "fathom.realm.windows.WindowsRealm"defaultDomain: ""allowGuests: falseadminGroups: [ "BUILTIN\Administrators" ]
}
]

Clone this wiki locally

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
James Moger edited this page Jul 8, 2016 · 2 revisions

About

Fathom-Security provides support for multiple authentication realms and an authorization infrastructure.

The core authorization design of Apache Shiro was harvested & married to the core authentication design of Gitblit to form a similar but significantly lighterweight security infrastructure.

A complete authentication and authorization model will include declarations of:

Realms : Realms are sources of Accounts and potentially Roles and Permissions. Realms are interrogated during the authentication process.

Accounts : Accounts represent a username-password pair. They may also include additional metadata such as display name, email addresses, Roles, and Permissions.

Roles : Roles are a named grouping of specific Permissions.

Permissions : Permissions are allowed application actions.

Installation

Add the Fathom-Security artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security</artifactId>
<version>${fathom.version}</version>
</dependency>

Layout

YourApp
└── src
└── main
└── java
└── conf
└── realms.conf

Configuration

Fathom-Security is configured by the HOCON resource config file conf/realms.conf.

# Configured Realms.# Realms will be tried in the order specified until an authentication is successful.realms: []
# If you have multiple Realms and are creating aggregate Accounts you# may cache the aggregate/assembled accounts in the SecurityManager.## Configure the aggregated Account time-to-live (TTL) in minutes and the maximum# number of aggregated accounts to keep cached.# A TTL of 0 disables this cache.cacheTtl: 0cacheMax: 100

Specifying an Alternate Realms Config File

You may specify alternate realms config files in your conf/default.conf resource config file.

security.configurationFile = "classpath:conf/realms.conf"dev.security.configurationFile = "classpath:conf/realms-dev.conf"test.security.configurationFile = "classpath:conf/realms-test.conf"

Usage

Fathom-Security provides a singleton instance of a SecurityManagerservice. This service contains all loaded Realms, Accounts, Roles, and Permissions.

@InjectSecurityManagersecurityManager;
publicAccountlogin(Stringusername, Stringpassword) {
StandardCredentialscredentials = newStandardCredentials(username, password);
Accountaccount = securityManager.authenticate(credentials);
returnaccount;
}

Accounts

Account usernames are specified to be global across all realms. Fathom-Security will collect and merge account definitions across all defined realms to create an aggregate account. This is necessary because not all realms are able to provide full account metadata, roles, permissions, and tokens.

For example, the account named james is assumed to represent the same person across all defined realms so that if james authenticates against a PAM Realm, his account metadata, roles, and permissions can be collected from the jamesaccount defined in a File Realm, JDBC Realm, etc.

Permissions

Permissions are allowed application actions. Permissions can be specified as a simple action (e.g. view) or as a granular, colon-delimited action (e.g. employees:view:5). Granular permissions may be assigned with up to three components: domain:action:instance.

# Permit viewing employees 5 and 10
employees:view:5,10
# Permit viewing all employees (these are equivalent)
employees:view:*
employees:view
# Permit updating employees 5 and 10
employees:update:5,10
# Permit all actions on employee 5
employees:*:5
# Permit adding and deleting any employee (these are equivalent)
employees:add,delete:*
employees:add,delete
# Permit all actions on all employees and contractors
employees,contractors:*

Roles

Roles may be specified on an account. Roles may also be defined to have explicit permissions. The primary value of a role is that it allows you to forgo maintaining the same set of permissions on multiple accounts. Instead you can maintain a single set of permissions in the role definition and assign this role to multiple accounts.

In the example below, the adminaccount has two assigned roles. The administratorrole is explicitly defined with the *permission, while the testerrole has no definition and therefore has no explicit permissions. The frankaccount has been assigned the normalrole and is only granted the secure:viewpermission.

accounts: [
{
username: "admin"roles: ["administrator", "tester"]
permissions: ["powers:speed,strength,agility"]
}
{
username: "frank"roles: ["normal"]
}
{
username: "joe"roles: ["normal"]
disabled: true
}
]
roles: {
administrator: ["*"]
normal: ["secure:view"]
}

Tokens

Tokens may be specified on an account. Tokens are both powerful and dangerous because a token is an authentication alias for an Account. You might use a token in a request header of a RESTful API route.

!!! Note Because a token is an alias for an Account, each token must be unique across all realms.

accounts: [
{
username: "frank"roles: ["normal"]
tokens: ["cafebabe","deadbeef"]
}
]

Authorization

Account instances have many methods to enforce authorization for a particular action.

publicvoidupdate(Employeeemployee) {
Accountaccount = getAccount();
if (account.hasRole("administrator") || account.isPermitted("employee:update")) {
employeeDao.update(employee);
}
}

You can also enforce authorization with methods that throw an AuthorizationException rather than returning a boolean status.

publicvoidupdate(Employeeemployee) {
Accountaccount = getAccount();
account.checkPermission("employee:update");
employeeDao.update(employee);
}

Disabling Accounts

In the above example the joeaccount is disabled.

accounts: [
{
username: "joe"disabled: true
}
]

In this case the SecurityManager will not allow the joeaccount to authenticate.

Realms

There are many realm integrations available for Fathom.

RealmModule
Memorycom.gitblit.fathom:fathom-security
Filecom.gitblit.fathom:fathom-security
Htpasswdcom.gitblit.fathom:fathom-security-htpasswd
Keycloakcom.gitblit.fathom:fathom-security-keycloak
LDAPcom.gitblit.fathom:fathom-security-ldap
JDBCcom.gitblit.fathom:fathom-security-jdbc
Rediscom.gitblit.fathom:fathom-security-redis
PAMcom.gitblit.fathom:fathom-security-pam
Windowscom.gitblit.fathom:fathom-security-windows

Memory Realm

The Memory Realm defines Accounts & Roles within the conf/realms.conf resource file.

Accounts and Roles are loaded only once on startup.

Configuration

conf/realms.conf

realms: [
{
# MEMORY REALM# All Accounts and Roles are loaded from this definition and cached in a ConcurrentHashMap.name: "Memory Realm"type: "fathom.realm.MemoryRealm"accounts: [
{
name: "Administrator"username: "admin"password: "admin"emailAddresses: ["fathom@gitblit.com"]
roles: ["administrator"]
permissions: ["powers:speed,strength,agility"]
}
{name: "User", username: "user", password: "user", roles: ["normal"], disabled: true}
{name: "Guest", username: "guest", password: "guest"}
# assign metadata and a role to an htpasswd account
{name: "Luke Skywalker", username: "red5", roles: ["normal"]}
# assign a role to an ldap account
{username: "UserOne", roles: ["normal"]}
]
## Defined Roles are named and have an array of Permissions.#roles: {
administrator: ["*"]
normal: ["secure:view"]
}
}
]

File Realm

The File Realm defines Accounts & Roles in an external HOCON file.

This realm will hot-reload on modification to the HOCON file.

Configuration

conf/realms.conf

realms: [
{
# FILE REALM# All Accounts and Roles are loaded from this definition and cached in a ConcurrentHashMap.name: "File Realm"type: "fathom.realm.FileRealm"file: "classpath:conf/users.conf"
}
]

conf/users.conf

accounts: [
{
name: "Administrator"username: "admin"password: "admin"emailAddresses: ["fathom@gitblit.com"]
roles: ["administrator"]
permissions: ["powers:speed,strength,agility"]
}
{name: "User", username: "user", password: "user", roles: ["normal"], disabled: true}
{name: "Guest", username: "guest", password: "guest"}
# assign metadata and a role to an htpasswd account
{name: "Luke Skywalker", username: "red5", roles: ["normal"]}
# assign a role to an ldap account
{username: "UserOne", roles: ["normal"]}
]
## Defined Roles are named and have an array of Permissions.#roles: {
administrator: ["*"]
normal: ["secure:view"]
}

Htpasswd Realm

The Htpasswd Realm defines partial Accounts (username & password) in an htpasswd file.

This realm will hot-reload on modification to the htpasswd file.

!!! Note You may only authenticate against an Htpasswd Realm. This realm does not support persistence of authorization data.

Installation

Add the Fathom-Security-Htpasswd artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-htpasswd</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# HTPASSWD REALMname: "Htpasswd Realm"type: "fathom.realm.htpasswd.HtpasswdRealm"file: "classpath:conf/users.htpasswd"allowClearPasswords: false
}
]

Keycloak Realm

The Keycloak Realm allows you to authenticate and, optionally, authorize requests using your Keycloak identity management server.

Installation

Add the Fathom-Security-Keycloak artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-keycloak</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

There are two parts to configuring your Keycloak integration.

  1. You'll need a conf/keycloak.json file which your Keycloak realm will provide to you via the admin ui.
  2. You need to configure conf/realms.conf to specify add the fathom.realm.keycloak.KeycloakRealm.

conf/realms.conf

realms: [
{
# KEYCLOAK REALM# Authenticates credentials from an Keycloak server.name: "My Keycloak Realm"type: "fathom.realm.keycloak.KeycloakRealm"file: "classpath:conf/keycloak.json"
}
]

Usage

See Fathom-REST Security.


LDAP Realm

The LDAP Realm allows you to integrate authentication and authorization with your LDAP server.

!!! Note You may authenticate and authorize using LDAP-sourced data but Role definitions are not currently supported by the LDAP Realm.

Installation

Add the Fathom-Security-LDAP artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-ldap</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# LDAP REALM# Authenticates credentials from an LDAP server.# This is a CachingRealm which may optionally configure an expiring cache.name: "UnboundID LDAP"type: "fathom.realm.ldap.LdapRealm"url: "ldap://localhost:1389"username: "cn=Directory Manager"password: "password"# LDAP search syntax for looking up accounts.accountBase: "OU=Users,OU=UserControl,OU=MyOrganization,DC=MyDomain"accountPattern: "(&(objectClass=person)(sAMAccountName=${username}))"# LDAP search syntax for looking up groups.# LDAP group names are mapped to Roles.# Roles can be optionally mapped to permissions.groupBase: "OU=Groups,OU=UserControl,OU=MyOrganization,DC=MyDomain"groupMemberPattern: "(&(objectClass=group)(member=${dn}))"# Members of these LDAP Groups are given "*" administrator permissions.# Invidual accounts can be specified with the "@" prefixadminGroups: ["@UserThree", "Git_Admins", "Git Admins"]
# Mapping controls for account name and email address extraction.# These may be an attribute name or can be a complex expression.nameMapping: "displayName"emailMapping: "email"# Configure the cached Account time-to-live (TTL) in minutes and the maximum# number of accounts to keep cached.# A TTL of 0 disables this cache.cacheTtl: 0cacheMax: 100
}
]

JDBC Realm

The JDBC Realm allows you to integrate authentication and authorization with an SQL database.

Installation

Add the Fathom-Security-JDBC artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-jdbc</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# JDBC/SQL REALM# Authenticates credentials from an SQL datasource.# This is a CachingRealm which may optionally configure an expiring cache.name: "H2 Realm"type: "fathom.realm.jdbc.JdbcRealm"url: "jdbc:h2:mem:fathom"username: ""password: ""# Specify a script to run on startup of the Realm.# This script creates our tables and populates some data.startScript: "classpath:conf/realm.sql"# Specify an account query and column mappings to populate Account metadata.## This optional mapping only works for the table (or view) referenced in the# accountQuery.accountQuery: "select * from accounts where username=?"nameMapping: "name"passwordMapping: "password"# Email address column mapping if your addresses are in the same table as your accounts.# This value may be delimited by a comma or semi-colon to support multiple addresses.emailMapping: "email"# A Role column mapping if your roles are in the same table as your accounts.# This value may be delimited by a comma or semi-colon to support multiple roles.roleMapping: ""# A Permission column mapping if your permissions are in the same table as your accounts.# This value may be delimited by a semi-colon to support multiple permissions.permissionMapping: ""# Specify an account roles query.# This is useful if your roles are defined in a separate table from your accounts.## The first column of the ResultSet must be a String role name.# The String role name may be delimited by a comma or semi-colon to support multiple roles.accountRolesQuery: "select role from account_roles where username=?"# Specify an account permissions query.# This is useful if your permissions are defined in a separate table from your accounts.## The first column of the ResultSet must be a String permission value.# The String permission value may be delimited by a semi-colon to support multiple permissions.accountPermissionsQuery: "select permission from account_permissions where username=?"# Specify a defined roles query.# Defined roles specify permissions for a role name.## The first column of the ResultSet must be a String role name.# The second column of the ResultSet must be a String permission value.# The String definition value may be delimited by a semi-colon to support multiple permissions.definedRolesQuery: "select role, definition from defined_roles"# Configure the cached Account time-to-live (TTL) in minutes and the maximum# number of accounts to keep cached.# A TTL of 0 disables this cache.cacheTtl: 0cacheMax: 100# fathom-security-jdbc supports HikariCP# see http://brettwooldridge.github.io/HikariCP/hikariCP {
connectionTimeout: 5000registerMbeans: true
}
}
]

Redis Realm

The Redis Realm allows you to integrate authentication and authorization with a Redis server.

!!! Note You may authenticate and authorize using Redis-sourced data but Role definitions are not currently supported by the Redis Realm.

Installation

Add the Fathom-Security-Redis artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-redis</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# REDIS REALMname: "Redis Realm"type: "fathom.realm.redis.RedisRealm"# Specify the url to the Redis databaseurl: "redis://localhost:6379/8"# The password for the Redis server, if neededpassword: ""# Specify the key mappings for account and role lookupspasswordMapping: "fathom:${username}:password"nameMapping: "fathom:${username}:name"emailMapping: "fathom:${username}:email"roleMapping: "fathom:${username}:roles"permissionMapping: "fathom:${username}:permissions"
}
]

PAM Realm

The PAM Realm allows you to authenticate against the local accounts on a Linux/Unix/OSX machine.

!!! Note You may only authenticate against a PAM Realm. This realm does not support persistence of authorization data.

Installation

Add the Fathom-Security-PAM artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-pam</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# PAM REALMname: "PAM Realm"type: "fathom.realm.pam.PamRealm"serviceName: "system-auth"
}
]

Windows Realm

The Windows Realm allows you to authenticate against the local accounts on a Windows machine.

!!! Note You may only authenticate against a Windows Realm. This realm does not support persistence of authorization data.

Installation

Add the Fathom-Security-Windows artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-windows</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# WINDOWS REALMname: "Windows Realm"type: "fathom.realm.windows.WindowsRealm"defaultDomain: ""allowGuests: falseadminGroups: [ "BUILTIN\Administrators" ]
}
]

Clone this wiki locally

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
James Moger edited this page Jul 8, 2016 · 2 revisions

About

Fathom-Security provides support for multiple authentication realms and an authorization infrastructure.

The core authorization design of Apache Shiro was harvested & married to the core authentication design of Gitblit to form a similar but significantly lighterweight security infrastructure.

A complete authentication and authorization model will include declarations of:

Realms : Realms are sources of Accounts and potentially Roles and Permissions. Realms are interrogated during the authentication process.

Accounts : Accounts represent a username-password pair. They may also include additional metadata such as display name, email addresses, Roles, and Permissions.

Roles : Roles are a named grouping of specific Permissions.

Permissions : Permissions are allowed application actions.

Installation

Add the Fathom-Security artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security</artifactId>
<version>${fathom.version}</version>
</dependency>

Layout

YourApp
└── src
└── main
└── java
└── conf
└── realms.conf

Configuration

Fathom-Security is configured by the HOCON resource config file conf/realms.conf.

# Configured Realms.# Realms will be tried in the order specified until an authentication is successful.realms: []
# If you have multiple Realms and are creating aggregate Accounts you# may cache the aggregate/assembled accounts in the SecurityManager.## Configure the aggregated Account time-to-live (TTL) in minutes and the maximum# number of aggregated accounts to keep cached.# A TTL of 0 disables this cache.cacheTtl: 0cacheMax: 100

Specifying an Alternate Realms Config File

You may specify alternate realms config files in your conf/default.conf resource config file.

security.configurationFile = "classpath:conf/realms.conf"dev.security.configurationFile = "classpath:conf/realms-dev.conf"test.security.configurationFile = "classpath:conf/realms-test.conf"

Usage

Fathom-Security provides a singleton instance of a SecurityManagerservice. This service contains all loaded Realms, Accounts, Roles, and Permissions.

@InjectSecurityManagersecurityManager;
publicAccountlogin(Stringusername, Stringpassword) {
StandardCredentialscredentials = newStandardCredentials(username, password);
Accountaccount = securityManager.authenticate(credentials);
returnaccount;
}

Accounts

Account usernames are specified to be global across all realms. Fathom-Security will collect and merge account definitions across all defined realms to create an aggregate account. This is necessary because not all realms are able to provide full account metadata, roles, permissions, and tokens.

For example, the account named james is assumed to represent the same person across all defined realms so that if james authenticates against a PAM Realm, his account metadata, roles, and permissions can be collected from the jamesaccount defined in a File Realm, JDBC Realm, etc.

Permissions

Permissions are allowed application actions. Permissions can be specified as a simple action (e.g. view) or as a granular, colon-delimited action (e.g. employees:view:5). Granular permissions may be assigned with up to three components: domain:action:instance.

# Permit viewing employees 5 and 10
employees:view:5,10
# Permit viewing all employees (these are equivalent)
employees:view:*
employees:view
# Permit updating employees 5 and 10
employees:update:5,10
# Permit all actions on employee 5
employees:*:5
# Permit adding and deleting any employee (these are equivalent)
employees:add,delete:*
employees:add,delete
# Permit all actions on all employees and contractors
employees,contractors:*

Roles

Roles may be specified on an account. Roles may also be defined to have explicit permissions. The primary value of a role is that it allows you to forgo maintaining the same set of permissions on multiple accounts. Instead you can maintain a single set of permissions in the role definition and assign this role to multiple accounts.

In the example below, the adminaccount has two assigned roles. The administratorrole is explicitly defined with the *permission, while the testerrole has no definition and therefore has no explicit permissions. The frankaccount has been assigned the normalrole and is only granted the secure:viewpermission.

accounts: [
{
username: "admin"roles: ["administrator", "tester"]
permissions: ["powers:speed,strength,agility"]
}
{
username: "frank"roles: ["normal"]
}
{
username: "joe"roles: ["normal"]
disabled: true
}
]
roles: {
administrator: ["*"]
normal: ["secure:view"]
}

Tokens

Tokens may be specified on an account. Tokens are both powerful and dangerous because a token is an authentication alias for an Account. You might use a token in a request header of a RESTful API route.

!!! Note Because a token is an alias for an Account, each token must be unique across all realms.

accounts: [
{
username: "frank"roles: ["normal"]
tokens: ["cafebabe","deadbeef"]
}
]

Authorization

Account instances have many methods to enforce authorization for a particular action.

publicvoidupdate(Employeeemployee) {
Accountaccount = getAccount();
if (account.hasRole("administrator") || account.isPermitted("employee:update")) {
employeeDao.update(employee);
}
}

You can also enforce authorization with methods that throw an AuthorizationException rather than returning a boolean status.

publicvoidupdate(Employeeemployee) {
Accountaccount = getAccount();
account.checkPermission("employee:update");
employeeDao.update(employee);
}

Disabling Accounts

In the above example the joeaccount is disabled.

accounts: [
{
username: "joe"disabled: true
}
]

In this case the SecurityManager will not allow the joeaccount to authenticate.

Realms

There are many realm integrations available for Fathom.

RealmModule
Memorycom.gitblit.fathom:fathom-security
Filecom.gitblit.fathom:fathom-security
Htpasswdcom.gitblit.fathom:fathom-security-htpasswd
Keycloakcom.gitblit.fathom:fathom-security-keycloak
LDAPcom.gitblit.fathom:fathom-security-ldap
JDBCcom.gitblit.fathom:fathom-security-jdbc
Rediscom.gitblit.fathom:fathom-security-redis
PAMcom.gitblit.fathom:fathom-security-pam
Windowscom.gitblit.fathom:fathom-security-windows

Memory Realm

The Memory Realm defines Accounts & Roles within the conf/realms.conf resource file.

Accounts and Roles are loaded only once on startup.

Configuration

conf/realms.conf

realms: [
{
# MEMORY REALM# All Accounts and Roles are loaded from this definition and cached in a ConcurrentHashMap.name: "Memory Realm"type: "fathom.realm.MemoryRealm"accounts: [
{
name: "Administrator"username: "admin"password: "admin"emailAddresses: ["fathom@gitblit.com"]
roles: ["administrator"]
permissions: ["powers:speed,strength,agility"]
}
{name: "User", username: "user", password: "user", roles: ["normal"], disabled: true}
{name: "Guest", username: "guest", password: "guest"}
# assign metadata and a role to an htpasswd account
{name: "Luke Skywalker", username: "red5", roles: ["normal"]}
# assign a role to an ldap account
{username: "UserOne", roles: ["normal"]}
]
## Defined Roles are named and have an array of Permissions.#roles: {
administrator: ["*"]
normal: ["secure:view"]
}
}
]

File Realm

The File Realm defines Accounts & Roles in an external HOCON file.

This realm will hot-reload on modification to the HOCON file.

Configuration

conf/realms.conf

realms: [
{
# FILE REALM# All Accounts and Roles are loaded from this definition and cached in a ConcurrentHashMap.name: "File Realm"type: "fathom.realm.FileRealm"file: "classpath:conf/users.conf"
}
]

conf/users.conf

accounts: [
{
name: "Administrator"username: "admin"password: "admin"emailAddresses: ["fathom@gitblit.com"]
roles: ["administrator"]
permissions: ["powers:speed,strength,agility"]
}
{name: "User", username: "user", password: "user", roles: ["normal"], disabled: true}
{name: "Guest", username: "guest", password: "guest"}
# assign metadata and a role to an htpasswd account
{name: "Luke Skywalker", username: "red5", roles: ["normal"]}
# assign a role to an ldap account
{username: "UserOne", roles: ["normal"]}
]
## Defined Roles are named and have an array of Permissions.#roles: {
administrator: ["*"]
normal: ["secure:view"]
}

Htpasswd Realm

The Htpasswd Realm defines partial Accounts (username & password) in an htpasswd file.

This realm will hot-reload on modification to the htpasswd file.

!!! Note You may only authenticate against an Htpasswd Realm. This realm does not support persistence of authorization data.

Installation

Add the Fathom-Security-Htpasswd artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-htpasswd</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# HTPASSWD REALMname: "Htpasswd Realm"type: "fathom.realm.htpasswd.HtpasswdRealm"file: "classpath:conf/users.htpasswd"allowClearPasswords: false
}
]

Keycloak Realm

The Keycloak Realm allows you to authenticate and, optionally, authorize requests using your Keycloak identity management server.

Installation

Add the Fathom-Security-Keycloak artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-keycloak</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

There are two parts to configuring your Keycloak integration.

  1. You'll need a conf/keycloak.json file which your Keycloak realm will provide to you via the admin ui.
  2. You need to configure conf/realms.conf to specify add the fathom.realm.keycloak.KeycloakRealm.

conf/realms.conf

realms: [
{
# KEYCLOAK REALM# Authenticates credentials from an Keycloak server.name: "My Keycloak Realm"type: "fathom.realm.keycloak.KeycloakRealm"file: "classpath:conf/keycloak.json"
}
]

Usage

See Fathom-REST Security.


LDAP Realm

The LDAP Realm allows you to integrate authentication and authorization with your LDAP server.

!!! Note You may authenticate and authorize using LDAP-sourced data but Role definitions are not currently supported by the LDAP Realm.

Installation

Add the Fathom-Security-LDAP artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-ldap</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# LDAP REALM# Authenticates credentials from an LDAP server.# This is a CachingRealm which may optionally configure an expiring cache.name: "UnboundID LDAP"type: "fathom.realm.ldap.LdapRealm"url: "ldap://localhost:1389"username: "cn=Directory Manager"password: "password"# LDAP search syntax for looking up accounts.accountBase: "OU=Users,OU=UserControl,OU=MyOrganization,DC=MyDomain"accountPattern: "(&(objectClass=person)(sAMAccountName=${username}))"# LDAP search syntax for looking up groups.# LDAP group names are mapped to Roles.# Roles can be optionally mapped to permissions.groupBase: "OU=Groups,OU=UserControl,OU=MyOrganization,DC=MyDomain"groupMemberPattern: "(&(objectClass=group)(member=${dn}))"# Members of these LDAP Groups are given "*" administrator permissions.# Invidual accounts can be specified with the "@" prefixadminGroups: ["@UserThree", "Git_Admins", "Git Admins"]
# Mapping controls for account name and email address extraction.# These may be an attribute name or can be a complex expression.nameMapping: "displayName"emailMapping: "email"# Configure the cached Account time-to-live (TTL) in minutes and the maximum# number of accounts to keep cached.# A TTL of 0 disables this cache.cacheTtl: 0cacheMax: 100
}
]

JDBC Realm

The JDBC Realm allows you to integrate authentication and authorization with an SQL database.

Installation

Add the Fathom-Security-JDBC artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-jdbc</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# JDBC/SQL REALM# Authenticates credentials from an SQL datasource.# This is a CachingRealm which may optionally configure an expiring cache.name: "H2 Realm"type: "fathom.realm.jdbc.JdbcRealm"url: "jdbc:h2:mem:fathom"username: ""password: ""# Specify a script to run on startup of the Realm.# This script creates our tables and populates some data.startScript: "classpath:conf/realm.sql"# Specify an account query and column mappings to populate Account metadata.## This optional mapping only works for the table (or view) referenced in the# accountQuery.accountQuery: "select * from accounts where username=?"nameMapping: "name"passwordMapping: "password"# Email address column mapping if your addresses are in the same table as your accounts.# This value may be delimited by a comma or semi-colon to support multiple addresses.emailMapping: "email"# A Role column mapping if your roles are in the same table as your accounts.# This value may be delimited by a comma or semi-colon to support multiple roles.roleMapping: ""# A Permission column mapping if your permissions are in the same table as your accounts.# This value may be delimited by a semi-colon to support multiple permissions.permissionMapping: ""# Specify an account roles query.# This is useful if your roles are defined in a separate table from your accounts.## The first column of the ResultSet must be a String role name.# The String role name may be delimited by a comma or semi-colon to support multiple roles.accountRolesQuery: "select role from account_roles where username=?"# Specify an account permissions query.# This is useful if your permissions are defined in a separate table from your accounts.## The first column of the ResultSet must be a String permission value.# The String permission value may be delimited by a semi-colon to support multiple permissions.accountPermissionsQuery: "select permission from account_permissions where username=?"# Specify a defined roles query.# Defined roles specify permissions for a role name.## The first column of the ResultSet must be a String role name.# The second column of the ResultSet must be a String permission value.# The String definition value may be delimited by a semi-colon to support multiple permissions.definedRolesQuery: "select role, definition from defined_roles"# Configure the cached Account time-to-live (TTL) in minutes and the maximum# number of accounts to keep cached.# A TTL of 0 disables this cache.cacheTtl: 0cacheMax: 100# fathom-security-jdbc supports HikariCP# see http://brettwooldridge.github.io/HikariCP/hikariCP {
connectionTimeout: 5000registerMbeans: true
}
}
]

Redis Realm

The Redis Realm allows you to integrate authentication and authorization with a Redis server.

!!! Note You may authenticate and authorize using Redis-sourced data but Role definitions are not currently supported by the Redis Realm.

Installation

Add the Fathom-Security-Redis artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-redis</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# REDIS REALMname: "Redis Realm"type: "fathom.realm.redis.RedisRealm"# Specify the url to the Redis databaseurl: "redis://localhost:6379/8"# The password for the Redis server, if neededpassword: ""# Specify the key mappings for account and role lookupspasswordMapping: "fathom:${username}:password"nameMapping: "fathom:${username}:name"emailMapping: "fathom:${username}:email"roleMapping: "fathom:${username}:roles"permissionMapping: "fathom:${username}:permissions"
}
]

PAM Realm

The PAM Realm allows you to authenticate against the local accounts on a Linux/Unix/OSX machine.

!!! Note You may only authenticate against a PAM Realm. This realm does not support persistence of authorization data.

Installation

Add the Fathom-Security-PAM artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-pam</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# PAM REALMname: "PAM Realm"type: "fathom.realm.pam.PamRealm"serviceName: "system-auth"
}
]

Windows Realm

The Windows Realm allows you to authenticate against the local accounts on a Windows machine.

!!! Note You may only authenticate against a Windows Realm. This realm does not support persistence of authorization data.

Installation

Add the Fathom-Security-Windows artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-windows</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# WINDOWS REALMname: "Windows Realm"type: "fathom.realm.windows.WindowsRealm"defaultDomain: ""allowGuests: falseadminGroups: [ "BUILTIN\Administrators" ]
}
]

Clone this wiki locally

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
James Moger edited this page Jul 8, 2016 · 2 revisions

About

Fathom-Security provides support for multiple authentication realms and an authorization infrastructure.

The core authorization design of Apache Shiro was harvested & married to the core authentication design of Gitblit to form a similar but significantly lighterweight security infrastructure.

A complete authentication and authorization model will include declarations of:

Realms : Realms are sources of Accounts and potentially Roles and Permissions. Realms are interrogated during the authentication process.

Accounts : Accounts represent a username-password pair. They may also include additional metadata such as display name, email addresses, Roles, and Permissions.

Roles : Roles are a named grouping of specific Permissions.

Permissions : Permissions are allowed application actions.

Installation

Add the Fathom-Security artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security</artifactId>
<version>${fathom.version}</version>
</dependency>

Layout

YourApp
└── src
└── main
└── java
└── conf
└── realms.conf

Configuration

Fathom-Security is configured by the HOCON resource config file conf/realms.conf.

# Configured Realms.# Realms will be tried in the order specified until an authentication is successful.realms: []
# If you have multiple Realms and are creating aggregate Accounts you# may cache the aggregate/assembled accounts in the SecurityManager.## Configure the aggregated Account time-to-live (TTL) in minutes and the maximum# number of aggregated accounts to keep cached.# A TTL of 0 disables this cache.cacheTtl: 0cacheMax: 100

Specifying an Alternate Realms Config File

You may specify alternate realms config files in your conf/default.conf resource config file.

security.configurationFile = "classpath:conf/realms.conf"dev.security.configurationFile = "classpath:conf/realms-dev.conf"test.security.configurationFile = "classpath:conf/realms-test.conf"

Usage

Fathom-Security provides a singleton instance of a SecurityManagerservice. This service contains all loaded Realms, Accounts, Roles, and Permissions.

@InjectSecurityManagersecurityManager;
publicAccountlogin(Stringusername, Stringpassword) {
StandardCredentialscredentials = newStandardCredentials(username, password);
Accountaccount = securityManager.authenticate(credentials);
returnaccount;
}

Accounts

Account usernames are specified to be global across all realms. Fathom-Security will collect and merge account definitions across all defined realms to create an aggregate account. This is necessary because not all realms are able to provide full account metadata, roles, permissions, and tokens.

For example, the account named james is assumed to represent the same person across all defined realms so that if james authenticates against a PAM Realm, his account metadata, roles, and permissions can be collected from the jamesaccount defined in a File Realm, JDBC Realm, etc.

Permissions

Permissions are allowed application actions. Permissions can be specified as a simple action (e.g. view) or as a granular, colon-delimited action (e.g. employees:view:5). Granular permissions may be assigned with up to three components: domain:action:instance.

# Permit viewing employees 5 and 10
employees:view:5,10
# Permit viewing all employees (these are equivalent)
employees:view:*
employees:view
# Permit updating employees 5 and 10
employees:update:5,10
# Permit all actions on employee 5
employees:*:5
# Permit adding and deleting any employee (these are equivalent)
employees:add,delete:*
employees:add,delete
# Permit all actions on all employees and contractors
employees,contractors:*

Roles

Roles may be specified on an account. Roles may also be defined to have explicit permissions. The primary value of a role is that it allows you to forgo maintaining the same set of permissions on multiple accounts. Instead you can maintain a single set of permissions in the role definition and assign this role to multiple accounts.

In the example below, the adminaccount has two assigned roles. The administratorrole is explicitly defined with the *permission, while the testerrole has no definition and therefore has no explicit permissions. The frankaccount has been assigned the normalrole and is only granted the secure:viewpermission.

accounts: [
{
username: "admin"roles: ["administrator", "tester"]
permissions: ["powers:speed,strength,agility"]
}
{
username: "frank"roles: ["normal"]
}
{
username: "joe"roles: ["normal"]
disabled: true
}
]
roles: {
administrator: ["*"]
normal: ["secure:view"]
}

Tokens

Tokens may be specified on an account. Tokens are both powerful and dangerous because a token is an authentication alias for an Account. You might use a token in a request header of a RESTful API route.

!!! Note Because a token is an alias for an Account, each token must be unique across all realms.

accounts: [
{
username: "frank"roles: ["normal"]
tokens: ["cafebabe","deadbeef"]
}
]

Authorization

Account instances have many methods to enforce authorization for a particular action.

publicvoidupdate(Employeeemployee) {
Accountaccount = getAccount();
if (account.hasRole("administrator") || account.isPermitted("employee:update")) {
employeeDao.update(employee);
}
}

You can also enforce authorization with methods that throw an AuthorizationException rather than returning a boolean status.

publicvoidupdate(Employeeemployee) {
Accountaccount = getAccount();
account.checkPermission("employee:update");
employeeDao.update(employee);
}

Disabling Accounts

In the above example the joeaccount is disabled.

accounts: [
{
username: "joe"disabled: true
}
]

In this case the SecurityManager will not allow the joeaccount to authenticate.

Realms

There are many realm integrations available for Fathom.

RealmModule
Memorycom.gitblit.fathom:fathom-security
Filecom.gitblit.fathom:fathom-security
Htpasswdcom.gitblit.fathom:fathom-security-htpasswd
Keycloakcom.gitblit.fathom:fathom-security-keycloak
LDAPcom.gitblit.fathom:fathom-security-ldap
JDBCcom.gitblit.fathom:fathom-security-jdbc
Rediscom.gitblit.fathom:fathom-security-redis
PAMcom.gitblit.fathom:fathom-security-pam
Windowscom.gitblit.fathom:fathom-security-windows

Memory Realm

The Memory Realm defines Accounts & Roles within the conf/realms.conf resource file.

Accounts and Roles are loaded only once on startup.

Configuration

conf/realms.conf

realms: [
{
# MEMORY REALM# All Accounts and Roles are loaded from this definition and cached in a ConcurrentHashMap.name: "Memory Realm"type: "fathom.realm.MemoryRealm"accounts: [
{
name: "Administrator"username: "admin"password: "admin"emailAddresses: ["fathom@gitblit.com"]
roles: ["administrator"]
permissions: ["powers:speed,strength,agility"]
}
{name: "User", username: "user", password: "user", roles: ["normal"], disabled: true}
{name: "Guest", username: "guest", password: "guest"}
# assign metadata and a role to an htpasswd account
{name: "Luke Skywalker", username: "red5", roles: ["normal"]}
# assign a role to an ldap account
{username: "UserOne", roles: ["normal"]}
]
## Defined Roles are named and have an array of Permissions.#roles: {
administrator: ["*"]
normal: ["secure:view"]
}
}
]

File Realm

The File Realm defines Accounts & Roles in an external HOCON file.

This realm will hot-reload on modification to the HOCON file.

Configuration

conf/realms.conf

realms: [
{
# FILE REALM# All Accounts and Roles are loaded from this definition and cached in a ConcurrentHashMap.name: "File Realm"type: "fathom.realm.FileRealm"file: "classpath:conf/users.conf"
}
]

conf/users.conf

accounts: [
{
name: "Administrator"username: "admin"password: "admin"emailAddresses: ["fathom@gitblit.com"]
roles: ["administrator"]
permissions: ["powers:speed,strength,agility"]
}
{name: "User", username: "user", password: "user", roles: ["normal"], disabled: true}
{name: "Guest", username: "guest", password: "guest"}
# assign metadata and a role to an htpasswd account
{name: "Luke Skywalker", username: "red5", roles: ["normal"]}
# assign a role to an ldap account
{username: "UserOne", roles: ["normal"]}
]
## Defined Roles are named and have an array of Permissions.#roles: {
administrator: ["*"]
normal: ["secure:view"]
}

Htpasswd Realm

The Htpasswd Realm defines partial Accounts (username & password) in an htpasswd file.

This realm will hot-reload on modification to the htpasswd file.

!!! Note You may only authenticate against an Htpasswd Realm. This realm does not support persistence of authorization data.

Installation

Add the Fathom-Security-Htpasswd artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-htpasswd</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# HTPASSWD REALMname: "Htpasswd Realm"type: "fathom.realm.htpasswd.HtpasswdRealm"file: "classpath:conf/users.htpasswd"allowClearPasswords: false
}
]

Keycloak Realm

The Keycloak Realm allows you to authenticate and, optionally, authorize requests using your Keycloak identity management server.

Installation

Add the Fathom-Security-Keycloak artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-keycloak</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

There are two parts to configuring your Keycloak integration.

  1. You'll need a conf/keycloak.json file which your Keycloak realm will provide to you via the admin ui.
  2. You need to configure conf/realms.conf to specify add the fathom.realm.keycloak.KeycloakRealm.

conf/realms.conf

realms: [
{
# KEYCLOAK REALM# Authenticates credentials from an Keycloak server.name: "My Keycloak Realm"type: "fathom.realm.keycloak.KeycloakRealm"file: "classpath:conf/keycloak.json"
}
]

Usage

See Fathom-REST Security.


LDAP Realm

The LDAP Realm allows you to integrate authentication and authorization with your LDAP server.

!!! Note You may authenticate and authorize using LDAP-sourced data but Role definitions are not currently supported by the LDAP Realm.

Installation

Add the Fathom-Security-LDAP artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-ldap</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# LDAP REALM# Authenticates credentials from an LDAP server.# This is a CachingRealm which may optionally configure an expiring cache.name: "UnboundID LDAP"type: "fathom.realm.ldap.LdapRealm"url: "ldap://localhost:1389"username: "cn=Directory Manager"password: "password"# LDAP search syntax for looking up accounts.accountBase: "OU=Users,OU=UserControl,OU=MyOrganization,DC=MyDomain"accountPattern: "(&(objectClass=person)(sAMAccountName=${username}))"# LDAP search syntax for looking up groups.# LDAP group names are mapped to Roles.# Roles can be optionally mapped to permissions.groupBase: "OU=Groups,OU=UserControl,OU=MyOrganization,DC=MyDomain"groupMemberPattern: "(&(objectClass=group)(member=${dn}))"# Members of these LDAP Groups are given "*" administrator permissions.# Invidual accounts can be specified with the "@" prefixadminGroups: ["@UserThree", "Git_Admins", "Git Admins"]
# Mapping controls for account name and email address extraction.# These may be an attribute name or can be a complex expression.nameMapping: "displayName"emailMapping: "email"# Configure the cached Account time-to-live (TTL) in minutes and the maximum# number of accounts to keep cached.# A TTL of 0 disables this cache.cacheTtl: 0cacheMax: 100
}
]

JDBC Realm

The JDBC Realm allows you to integrate authentication and authorization with an SQL database.

Installation

Add the Fathom-Security-JDBC artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-jdbc</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# JDBC/SQL REALM# Authenticates credentials from an SQL datasource.# This is a CachingRealm which may optionally configure an expiring cache.name: "H2 Realm"type: "fathom.realm.jdbc.JdbcRealm"url: "jdbc:h2:mem:fathom"username: ""password: ""# Specify a script to run on startup of the Realm.# This script creates our tables and populates some data.startScript: "classpath:conf/realm.sql"# Specify an account query and column mappings to populate Account metadata.## This optional mapping only works for the table (or view) referenced in the# accountQuery.accountQuery: "select * from accounts where username=?"nameMapping: "name"passwordMapping: "password"# Email address column mapping if your addresses are in the same table as your accounts.# This value may be delimited by a comma or semi-colon to support multiple addresses.emailMapping: "email"# A Role column mapping if your roles are in the same table as your accounts.# This value may be delimited by a comma or semi-colon to support multiple roles.roleMapping: ""# A Permission column mapping if your permissions are in the same table as your accounts.# This value may be delimited by a semi-colon to support multiple permissions.permissionMapping: ""# Specify an account roles query.# This is useful if your roles are defined in a separate table from your accounts.## The first column of the ResultSet must be a String role name.# The String role name may be delimited by a comma or semi-colon to support multiple roles.accountRolesQuery: "select role from account_roles where username=?"# Specify an account permissions query.# This is useful if your permissions are defined in a separate table from your accounts.## The first column of the ResultSet must be a String permission value.# The String permission value may be delimited by a semi-colon to support multiple permissions.accountPermissionsQuery: "select permission from account_permissions where username=?"# Specify a defined roles query.# Defined roles specify permissions for a role name.## The first column of the ResultSet must be a String role name.# The second column of the ResultSet must be a String permission value.# The String definition value may be delimited by a semi-colon to support multiple permissions.definedRolesQuery: "select role, definition from defined_roles"# Configure the cached Account time-to-live (TTL) in minutes and the maximum# number of accounts to keep cached.# A TTL of 0 disables this cache.cacheTtl: 0cacheMax: 100# fathom-security-jdbc supports HikariCP# see http://brettwooldridge.github.io/HikariCP/hikariCP {
connectionTimeout: 5000registerMbeans: true
}
}
]

Redis Realm

The Redis Realm allows you to integrate authentication and authorization with a Redis server.

!!! Note You may authenticate and authorize using Redis-sourced data but Role definitions are not currently supported by the Redis Realm.

Installation

Add the Fathom-Security-Redis artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-redis</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# REDIS REALMname: "Redis Realm"type: "fathom.realm.redis.RedisRealm"# Specify the url to the Redis databaseurl: "redis://localhost:6379/8"# The password for the Redis server, if neededpassword: ""# Specify the key mappings for account and role lookupspasswordMapping: "fathom:${username}:password"nameMapping: "fathom:${username}:name"emailMapping: "fathom:${username}:email"roleMapping: "fathom:${username}:roles"permissionMapping: "fathom:${username}:permissions"
}
]

PAM Realm

The PAM Realm allows you to authenticate against the local accounts on a Linux/Unix/OSX machine.

!!! Note You may only authenticate against a PAM Realm. This realm does not support persistence of authorization data.

Installation

Add the Fathom-Security-PAM artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-pam</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# PAM REALMname: "PAM Realm"type: "fathom.realm.pam.PamRealm"serviceName: "system-auth"
}
]

Windows Realm

The Windows Realm allows you to authenticate against the local accounts on a Windows machine.

!!! Note You may only authenticate against a Windows Realm. This realm does not support persistence of authorization data.

Installation

Add the Fathom-Security-Windows artifact.

<dependency>
<groupId>com.gitblit.fathom</groupId>
<artifactId>fathom-security-windows</artifactId>
<version>${fathom.version}</version>
</dependency>

Configuration

conf/realms.conf

realms: [
{
# WINDOWS REALMname: "Windows Realm"type: "fathom.realm.windows.WindowsRealm"defaultDomain: ""allowGuests: falseadminGroups: [ "BUILTIN\Administrators" ]
}
]

Clone this wiki locally