# HG changeset patch # User Johannes Bornhold # Date 2016-05-27 18:21:13 # Node ID 0ca726bbaf8ab600841327bc0221ddcecf9ed745 # Parent ed2af6dcf8c98bc66474f2e48fd7badabc53ca87 authn: Add whitespace stripping to authentication plugin settings. diff --git a/rhodecode/authentication/plugins/auth_container.py b/rhodecode/authentication/plugins/auth_container.py --- a/rhodecode/authentication/plugins/auth_container.py +++ b/rhodecode/authentication/plugins/auth_container.py @@ -26,6 +26,7 @@ from sqlalchemy.ext.hybrid import hybrid from rhodecode.authentication.base import RhodeCodeExternalAuthPlugin from rhodecode.authentication.schema import AuthnPluginSettingsSchemaBase from rhodecode.authentication.routes import AuthnPluginResourceBase +from rhodecode.lib.colander_utils import strip_whitespace from rhodecode.lib.utils2 import str2bool, safe_unicode from rhodecode.model.db import User from rhodecode.translation import _ @@ -52,12 +53,14 @@ class ContainerSettingsSchema(AuthnPlugi colander.String(), default='REMOTE_USER', description=_('Header to extract the user from'), + preparer=strip_whitespace, title=_('Header'), widget='string') fallback_header = colander.SchemaNode( colander.String(), default='HTTP_X_FORWARDED_USER', description=_('Header to extract the user from when main one fails'), + preparer=strip_whitespace, title=_('Fallback header'), widget='string') clean_username = colander.SchemaNode( diff --git a/rhodecode/authentication/plugins/auth_crowd.py b/rhodecode/authentication/plugins/auth_crowd.py --- a/rhodecode/authentication/plugins/auth_crowd.py +++ b/rhodecode/authentication/plugins/auth_crowd.py @@ -34,6 +34,7 @@ from sqlalchemy.ext.hybrid import hybrid from rhodecode.authentication.base import RhodeCodeExternalAuthPlugin from rhodecode.authentication.schema import AuthnPluginSettingsSchemaBase from rhodecode.authentication.routes import AuthnPluginResourceBase +from rhodecode.lib.colander_utils import strip_whitespace from rhodecode.lib.ext_json import json, formatted_json from rhodecode.model.db import User @@ -58,12 +59,14 @@ class CrowdSettingsSchema(AuthnPluginSet colander.String(), default='127.0.0.1', description=_('The FQDN or IP of the Atlassian CROWD Server'), + preparer=strip_whitespace, title=_('Host'), widget='string') port = colander.SchemaNode( colander.Int(), default=8095, description=_('The Port in use by the Atlassian CROWD Server'), + preparer=strip_whitespace, title=_('Port'), validator=colander.Range(min=0, max=65536), widget='int') @@ -71,12 +74,14 @@ class CrowdSettingsSchema(AuthnPluginSet colander.String(), default='', description=_('The Application Name to authenticate to CROWD'), + preparer=strip_whitespace, title=_('Application Name'), widget='string') app_password = colander.SchemaNode( colander.String(), default='', description=_('The password to authenticate to CROWD'), + preparer=strip_whitespace, title=_('Application Password'), widget='password') admin_groups = colander.SchemaNode( @@ -85,6 +90,7 @@ class CrowdSettingsSchema(AuthnPluginSet description=_('A comma separated list of group names that identify ' 'users as RhodeCode Administrators'), missing='', + preparer=strip_whitespace, title=_('Admin Groups'), widget='string') diff --git a/rhodecode/authentication/plugins/auth_jasig_cas.py b/rhodecode/authentication/plugins/auth_jasig_cas.py --- a/rhodecode/authentication/plugins/auth_jasig_cas.py +++ b/rhodecode/authentication/plugins/auth_jasig_cas.py @@ -36,6 +36,7 @@ from sqlalchemy.ext.hybrid import hybrid from rhodecode.authentication.base import RhodeCodeExternalAuthPlugin from rhodecode.authentication.schema import AuthnPluginSettingsSchemaBase from rhodecode.authentication.routes import AuthnPluginResourceBase +from rhodecode.lib.colander_utils import strip_whitespace from rhodecode.lib.utils2 import safe_unicode from rhodecode.model.db import User @@ -60,6 +61,7 @@ class JasigCasSettingsSchema(AuthnPlugin colander.String(), default='https://domain.com/cas/v1/tickets', description=_('The url of the Jasig CAS REST service'), + preparer=strip_whitespace, title=_('URL'), widget='string') diff --git a/rhodecode/authentication/plugins/auth_ldap.py b/rhodecode/authentication/plugins/auth_ldap.py --- a/rhodecode/authentication/plugins/auth_ldap.py +++ b/rhodecode/authentication/plugins/auth_ldap.py @@ -33,6 +33,7 @@ from sqlalchemy.ext.hybrid import hybrid from rhodecode.authentication.base import RhodeCodeExternalAuthPlugin from rhodecode.authentication.schema import AuthnPluginSettingsSchemaBase from rhodecode.authentication.routes import AuthnPluginResourceBase +from rhodecode.lib.colander_utils import strip_whitespace from rhodecode.lib.exceptions import ( LdapConnectionError, LdapUsernameError, LdapPasswordError, LdapImportError ) @@ -71,12 +72,14 @@ class LdapSettingsSchema(AuthnPluginSett colander.String(), default='', description=_('Host of the LDAP Server'), + preparer=strip_whitespace, title=_('LDAP Host'), widget='string') port = colander.SchemaNode( colander.Int(), default=389, description=_('Port that the LDAP server is listening on'), + preparer=strip_whitespace, title=_('Port'), validator=colander.Range(min=0, max=65536), widget='int') @@ -85,6 +88,7 @@ class LdapSettingsSchema(AuthnPluginSett default='', description=_('User to connect to LDAP'), missing='', + preparer=strip_whitespace, title=_('Account'), widget='string') dn_pass = colander.SchemaNode( @@ -92,6 +96,7 @@ class LdapSettingsSchema(AuthnPluginSett default='', description=_('Password to connect to LDAP'), missing='', + preparer=strip_whitespace, title=_('Password'), widget='password') tls_kind = colander.SchemaNode( @@ -113,6 +118,7 @@ class LdapSettingsSchema(AuthnPluginSett default='', description=_('Base DN to search (e.g., dc=mydomain,dc=com)'), missing='', + preparer=strip_whitespace, title=_('Base DN'), widget='string') filter = colander.SchemaNode( @@ -120,6 +126,7 @@ class LdapSettingsSchema(AuthnPluginSett default='', description=_('Filter to narrow results (e.g., ou=Users, etc)'), missing='', + preparer=strip_whitespace, title=_('LDAP Search Filter'), widget='string') search_scope = colander.SchemaNode( @@ -133,14 +140,16 @@ class LdapSettingsSchema(AuthnPluginSett colander.String(), default='', description=_('LDAP Attribute to map to user name'), + missing_msg=_('The LDAP Login attribute of the CN must be specified'), + preparer=strip_whitespace, title=_('Login Attribute'), - missing_msg=_('The LDAP Login attribute of the CN must be specified'), widget='string') attr_firstname = colander.SchemaNode( colander.String(), default='', description=_('LDAP Attribute to map to first name'), missing='', + preparer=strip_whitespace, title=_('First Name Attribute'), widget='string') attr_lastname = colander.SchemaNode( @@ -148,6 +157,7 @@ class LdapSettingsSchema(AuthnPluginSett default='', description=_('LDAP Attribute to map to last name'), missing='', + preparer=strip_whitespace, title=_('Last Name Attribute'), widget='string') attr_email = colander.SchemaNode( @@ -155,6 +165,7 @@ class LdapSettingsSchema(AuthnPluginSett default='', description=_('LDAP Attribute to map to email address'), missing='', + preparer=strip_whitespace, title=_('Email Attribute'), widget='string') diff --git a/rhodecode/authentication/plugins/auth_pam.py b/rhodecode/authentication/plugins/auth_pam.py --- a/rhodecode/authentication/plugins/auth_pam.py +++ b/rhodecode/authentication/plugins/auth_pam.py @@ -35,6 +35,7 @@ from sqlalchemy.ext.hybrid import hybrid from rhodecode.authentication.base import RhodeCodeExternalAuthPlugin from rhodecode.authentication.schema import AuthnPluginSettingsSchemaBase from rhodecode.authentication.routes import AuthnPluginResourceBase +from rhodecode.lib.colander_utils import strip_whitespace log = logging.getLogger(__name__) @@ -57,6 +58,7 @@ class PamSettingsSchema(AuthnPluginSetti colander.String(), default='login', description=_('PAM service name to use for authentication.'), + preparer=strip_whitespace, title=_('PAM service name'), widget='string') gecos = colander.SchemaNode( @@ -64,6 +66,7 @@ class PamSettingsSchema(AuthnPluginSetti default='(?P.+),\s*(?P\w+)', description=_('Regular expression for extracting user name/email etc. ' 'from Unix userinfo.'), + preparer=strip_whitespace, title=_('Gecos Regex'), widget='string')