View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0004235 | mantisbt | authentication | public | 2004-07-31 21:04 | 2017-04-30 14:48 |
Reporter | vboctor | Assigned To | vboctor | ||
Priority | normal | Severity | feature | Reproducibility | always |
Status | closed | Resolution | fixed | ||
Target Version | 2.4.0 | Fixed in Version | 2.4.0 | ||
Summary | 0004235: Support Generic Authentication through Plug-ins | ||||
Description | Define an API which can be implemented to allow Mantis to use a certain kind of authentication. | ||||
Tags | No tags attached. | ||||
Attached Files | pear_auth.patch (32,592 bytes)
--- admin/install.php Mon Feb 19 23:05:04 2007 +++ admin/install.php Wed Jul 18 00:55:32 2007 @@ -8,8 +8,8 @@ # -------------------------------------------------------- # $Id: install.php,v 1.31 2007/02/20 06:05:03 vboctor Exp $ # -------------------------------------------------------- -?> -<?php + $g_login_allowed = false; + error_reporting( E_ALL ); //@@@ put this somewhere @@ -99,9 +99,12 @@ <td class="title"> <?php switch ( $t_install_state ) { - case 6: - echo "Post Installation Checks"; - break; + case 7: + echo "Add administrator user"; + break; + case 6: + echo "Post Installation Checks"; + break; case 5: echo "Install Configuration File"; break; @@ -687,8 +690,6 @@ </td> </tr> -<!-- Checking MD5 --> -<?php print_test( 'Checking for MD5 Crypt() support', 1 === CRYPT_MD5, false, 'password security may be lower than expected' ) ?> <!-- Checking register_globals are off --> <?php print_test( 'Checking for register_globals are off for mantis', ! ini_get_bool( 'register_globals' ), false, 'change php.ini to disable register_globals setting' ) ?> @@ -773,14 +774,63 @@ } ?> </tr> -</table> <?php if ( false == $g_failed ) { $t_install_state++; } } # end install_state == 6 -if ( 7 == $t_install_state ) { +if ( 7 == $t_install_state ) { +?> +<tr> + <td bgcolor="#ffffff"> + Initializing 'administrator' user + </td> +<?php + /* + "(username, realname, email, password, date_created, last_visit, enabled, protected, access_level, login_count, lost_password_request_count, failed_login_count, cookie_string) VALUES + ('administrator', '', 'root@localhost', '63a9f0ea7bb98050796b649e85481845', " . db_now() . ", " . db_now() . ", 1, 0, 90, 3, 0, 0, '" . + md5( mt_rand( 0, mt_getrandmax() ) + mt_rand( 0, mt_getrandmax() ) ) . md5( time() ) . "')" ) ); + */ + $pearauth = auth_api_initialize_auth_object(); + + $query = "DELETE FROM mantis_user_table + WHERE username='administrator';"; + db_query( $query ); + + $t_result = user_create( + 'administrator', #user name + '', #passwprd + '', #email + 90, # access level + false, # protected + true, # enabled + ''); #real name + + if ( $t_result != false ) { + print_test_result( GOOD ); + } else { + print_test_result( BAD, true, 'could not create user through the user API' ); + } + if($t_result != false) + { + $g_failed = false; + } + else + { + $g_failed = true; + } +?> +</tr> +</table> +<?php + if ( false == $g_failed ) { + $t_install_state++; + } +} # end install_state == 7 + + +if ( 8 == $t_install_state ) { # cleanup and launch upgrade ?> <p>Install was successful.</p> --- admin/schema.php Thu Mar 15 22:13:46 2007 +++ admin/schema.php Wed Jul 18 00:57:09 2007 @@ -309,10 +309,13 @@ $upgrade[] = Array('CreateIndexSQL',Array('idx_user_username',config_get('mantis_user_table'),'username',Array('UNIQUE'))); $upgrade[] = Array('CreateIndexSQL',Array('idx_enable',config_get('mantis_user_table'),'enabled')); $upgrade[] = Array('CreateIndexSQL',Array('idx_access',config_get('mantis_user_table'),'access_level')); -$upgrade[] = Array('InsertData', Array( config_get('mantis_user_table'), +/* I had to remove this so that PEAR::Auth could hash the password */ +/* + $upgrade[] = Array('InsertData', Array( config_get('mantis_user_table'), "(username, realname, email, password, date_created, last_visit, enabled, protected, access_level, login_count, lost_password_request_count, failed_login_count, cookie_string) VALUES ('administrator', '', 'root@localhost', '63a9f0ea7bb98050796b649e85481845', " . db_now() . ", " . db_now() . ", 1, 0, 90, 3, 0, 0, '" . md5( mt_rand( 0, mt_getrandmax() ) + mt_rand( 0, mt_getrandmax() ) ) . md5( time() ) . "')" ) ); +*/ $upgrade[] = Array('AlterColumnSQL', Array( config_get( 'mantis_bug_history_table' ), "old_value C(255) NOTNULL" ) ); $upgrade[] = Array('AlterColumnSQL', Array( config_get( 'mantis_bug_history_table' ), "new_value C(255) NOTNULL" ) ); --- core/adodb/datadict/datadict-postgres.inc.php Sat Apr 22 04:35:06 2006 +++ core/adodb/datadict/datadict-postgres.inc.php Wed Jul 18 01:06:22 2007 @@ -103,7 +103,20 @@ case 'D': return 'DATE'; case 'T': return 'TIMESTAMP'; - case 'L': return 'BOOLEAN'; + case 'L': + /* + # + # postgres 8.3 expected quotes + # around the val. the easiest way + # to work was to change to a + # numeric value. I had a very + # hard time trying to figure out + # how to supply quotes arround the + # value, so I went the other way + # + return 'BOOLEAN'; + */ + return 'SMALLINT'; case 'I': return 'INTEGER'; case 'I1': return 'SMALLINT'; case 'I2': return 'INT2'; --- core/authentication_api.php Sun Apr 23 05:33:00 2006 +++ core/authentication_api.php Wed Jul 18 02:00:02 2007 @@ -8,14 +8,67 @@ # -------------------------------------------------------- # $Id: authentication_api.php,v 1.55 2006/04/23 12:32:59 vboctor Exp $ # -------------------------------------------------------- - + require_once "Auth/Auth.php"; + require_once "string_api.php"; + require_once "print_api.php"; ### Authentication API ### - - $g_script_login_cookie = null; - $g_cache_anonymous_user_cookie_string = null; - $g_cache_current_user_cookie_string = null; - $g_cache_cookie_valid = null; - + + # + # this function is called when a->start(); decides that a login is needed + # + function pearauth_login_redirector( $username, $status, $auth) { + /* keep us from looping infinatly */ + global $on_login_page; + if(isset($on_login_page)) + { + if($on_login_page == true) + { + return; + } + } + + if ( !php_version_at_least( '4.1.0' ) ) { + global $_SERVER; + } + + $p_return_page = $auth->return_page; + if(is_blank($p_return_page)){ + if (!isset($_SERVER['REQUEST_URI'])) { + $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . '?' . $_SERVER['QUERY_STRING']; + } + $p_return_page = $_SERVER['REQUEST_URI']; + } + $p_return_page = string_url( $p_return_page ); + print_header_redirect( 'login_page.php?return=' . $p_return_page ); + } + + function auth_api_initialize_auth_object() + { + global $g_login_allowed; + global $g_db_type; + global $g_db_username; + global $g_db_password; + global $g_hostname; + global $g_database_name; + + + $pearauthDriver = "DB"; + $pearAuthOptions = array( + 'dsn' => "$g_db_type://$g_db_username:$g_db_password@$g_hostname/$g_database_name", + 'table' => "mantis_user_table", + 'usernamecol' => "username", + 'passwordcol' => "password", + 'sessionName' => "mantis" + ); + + if(!isset($g_login_allowed)) $g_login_allowed=true; + $pearauth = new Auth($pearauthDriver, $pearAuthOptions, "pearauth_login_redirector",$g_login_allowed); + $pearauth->return_page =''; + return $pearauth; + } + + $pearauth = auth_api_initialize_auth_object(); + $pearauth->start(); #=================================== # Boolean queries and ensures #=================================== @@ -38,26 +91,21 @@ if ( OFF == current_user_get_field( 'enabled' ) ) { print_header_redirect( 'logout_page.php' ); } - } else { # not logged in - if ( is_blank( $p_return_page ) ) { - if (!isset($_SERVER['REQUEST_URI'])) { - $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . '?' . $_SERVER['QUERY_STRING']; - } - $p_return_page = $_SERVER['REQUEST_URI']; - } - $p_return_page = string_url( $p_return_page ); - print_header_redirect( 'login_page.php?return=' . $p_return_page ); - } + } else { + # not logged in + # old code had a redirect here. + # hmmmm.... is this legal? + $pearauth->return_page = $p_return_page; + $pearauth->start(); + } } # -------------------- # Return true if there is a currently logged in and authenticated user, # false otherwise - function auth_is_user_authenticated() { - global $g_cache_cookie_valid; - if($g_cache_cookie_valid) - return true; - return ( auth_is_cookie_valid( auth_get_current_user_cookie() ) ); + function auth_is_user_authenticated() { + global $pearauth; + return $pearauth->checkAuth(); } @@ -72,123 +120,38 @@ # true is returned. If $p_perm_login is true, the long-term # cookie is created. function auth_attempt_login( $p_username, $p_password, $p_perm_login=false ) { - $t_user_id = user_get_id_by_name( $p_username ); - - $t_login_method = config_get( 'login_method' ); - - if ( false === $t_user_id ) { - if ( BASIC_AUTH == $t_login_method ) { - # attempt to create the user if using BASIC_AUTH - $t_cookie_string = user_create( $p_username, $p_password ); - - if ( false === $t_cookie_string ) { - # it didn't work - return false; - } - - # ok, we created the user, get the row again - $t_user_id = user_get_id_by_name( $p_username ); - - if ( false === $t_user_id ) { - # uh oh, something must be really wrong - - # @@@ trigger an error here? - - return false; - } - } else { - return false; - } - } - - # check for disabled account - if ( !user_is_enabled( $t_user_id ) ) { - return false; - } - - # max. failed login attempts achieved... - if( !user_is_login_request_allowed( $t_user_id ) ) { - return false; - } - - $t_anon_account = config_get( 'anonymous_account' ); - $t_anon_allowed = config_get( 'allow_anonymous_login' ); - - # check for anonymous login - if ( !( ( ON == $t_anon_allowed ) && ( $t_anon_account == $p_username) ) ) { - # anonymous login didn't work, so check the password - - if ( !auth_does_password_match( $t_user_id, $p_password ) ) { - user_increment_failed_login_count( $t_user_id ); - return false; - } - } - - # ok, we're good to login now - - # increment login count - user_increment_login_count( $t_user_id ); - - user_reset_failed_login_count_to_zero( $t_user_id ); - user_reset_lost_password_in_progress_count_to_zero( $t_user_id ); - - # set the cookies - auth_set_cookies( $t_user_id, $p_perm_login ); - - return true; + # + # same thing. just return if we are not logged in + # + global $pearauth; + return $pearauth->checkAuth(); } # -------------------- # Allows scripts to login using a login name or ( login name + password ) - function auth_attempt_script_login( $p_username, $p_password = null ) { - global $g_script_login_cookie, $g_cache_cookie_valid, $g_cache_current_user_id, $g_cache_current_user_cookie_string; - - $t_user_id = user_get_id_by_name( $p_username ); - - $t_user = user_get_row( $t_user_id ); - - # check for disabled account - if ( OFF == $t_user['enabled'] ) { - return false; - } - - # validate password if supplied - if ( null !== $p_password ) { - if ( !auth_does_password_match( $t_user_id, $p_password ) ) { - return false; - } - } - - # ok, we're good to login now - - # With cases like RSS feeds and MantisConnect there is a login per operation, hence, there is no - # real significance of incrementing login count. - # increment login count - # user_increment_login_count( $t_user_id ); - - # set the cookies - $g_script_login_cookie = $t_user['cookie_string']; - $g_cache_current_user_cookie_string = $g_script_login_cookie; - - # cache user id for future reference - $g_cache_current_user_id = $t_user_id; - $g_cache_cookie_valid = true; - - return true; + function auth_attempt_script_login( $p_username, $p_password = null ) { + # + # we are unable to authenticate through this method anymore + # username and password are picked by the auth module from the + # get/set scripts. Anythin using this should be depreciated + # + global $pearauth; + return $pearauth->checkAuth(); } # -------------------- # Logout the current user and remove any remaining cookies from their browser # Returns true on success, false otherwise - function auth_logout() { - global $g_cache_current_user_id; - - # clear cached userid - $g_cache_current_user_id = null; - - # clear cookies, if they were set - if (auth_clear_cookies()) { - helper_clear_pref_cookies(); + function auth_logout() { + global $pearauth; + if ($pearauth->checkAuth()) + { + $pearauth->logout(); + helper_clear_pref_cookies(); + } + else + { + $pearauth->logout(); } return true; } @@ -200,71 +163,55 @@ # -------------------- # Return true if the password for the user id given matches the given # password (taking into account the global login method) - function auth_does_password_match( $p_user_id, $p_test_password ) { - $t_configured_login_method = config_get( 'login_method' ); - - if ( LDAP == $t_configured_login_method ) { - return ldap_authenticate( $p_user_id, $p_test_password ); - } - - $t_password = user_get_field( $p_user_id, 'password' ); - $t_login_methods = Array(MD5, CRYPT, PLAIN); - foreach ( $t_login_methods as $t_login_method ) { - - # pass the stored password in as the salt - if ( auth_process_plain_password( $p_test_password, $t_password, $t_login_method ) == $t_password ) { - # Check for migration to another login method and test whether the password was encrypted - # with our previously insecure implemention of the CRYPT method - if ( ( $t_login_method != $t_configured_login_method ) || - ( ( CRYPT == $t_configured_login_method ) && substr( $t_password, 0, 2 ) == substr( $p_test_password, 0, 2 ) ) ) { - user_set_password( $p_user_id, $p_test_password, true ); - } + function auth_does_password_match( $p_user_id, $p_test_password ) { + # + # this one is used all over the place :(..... + # gonna have to try to remove it from the other functions, + # I am not sure how to do this through pear::AUTH + # maybe we could trick it out? (This would be a nice thing + # to add to PEAR::Auth) + # + + $_POST["test_username"] = $p_user_id; + $_POST["test_password"] = $p_test_password; + - return true; - } - } + $tmp_pearauthDriver = $pearauthDriver; + $tmp_pearauthOptions = $pearAuthOptions; + $tmp_pearauthOptions["postUsername"] = "test_username"; + $tmp_pearauthOptions["postPassword"] = "test_password"; + $tmp_pearauthOptions["sessionName" ] = "_auth_test"; - return false; - } + + + function noaction($a,$b,$c){} + + $tempauth = new Auth($tmp_pearauthDriver,$tmp_pearauthOptions,"noaction",false); - # -------------------- - # Encrypt and return the plain password given, as appropriate for the current - # global login method. - # - # When generating a new password, no salt should be passed in. - # When encrypting a password to compare to a stored password, the stored - # password should be passed in as salt. If the auth method is CRYPT then - # crypt() will extract the appropriate portion of the stored password as its salt - function auth_process_plain_password( $p_password, $p_salt=null, $p_method=null ) { - $t_login_method = config_get( 'login_method' ); - if ( $p_method !== null ) { - $t_login_method = $p_method; - } + /* give our fake data to the function */ + $retval = $tempauth->checkAuth(); - switch ( $t_login_method ) { - case CRYPT: - # a null salt is the same as no salt, which causes a salt to be generated - # otherwise, use the salt given - $t_processed_password = crypt( $p_password, $p_salt ); - break; - case MD5: - $t_processed_password = md5( $p_password ); - break; - case BASIC_AUTH: - case PLAIN: - default: - $t_processed_password = $p_password; - break; - } + /* nix our temps. */ + unset($tempauth); + unset($_POST["test_username"]); + unset($_POST["test_password"]); + unset($_SESSION["_auth_test"]); + - # cut this off to 32 cahracters which the largest possible string in the database - return substr( $t_processed_password, 0, 32 ); + return $retval; } # -------------------- # Generate a random 12 character password # p_email is unused - function auth_generate_random_password( $p_email ) { + # used for lost passwords, when we can set the passwords though the system. + # + function auth_generate_random_password( $p_email ) { + # + # this on should stay. it is used for creation and resetting of passwords + # (on platforms that support that) + # + $t_val = mt_rand( 0, mt_getrandmax() ) + mt_rand( 0, mt_getrandmax() ); $t_val = md5( $t_val ); @@ -290,7 +237,10 @@ # -------------------- # Set login cookies for the user # If $p_perm_login is true, a long-term cookie is created - function auth_set_cookies( $p_user_id, $p_perm_login=false ) { + function auth_set_cookies( $p_user_id, $p_perm_login=false ) { + # + # used in verify.php + # $t_cookie_string = user_get_field( $p_user_id, 'cookie_string' ); $t_cookie_name = config_get( 'string_cookie' ); @@ -304,204 +254,33 @@ } } - # -------------------- - # Clear login cookies, return true if they were cleared - function auth_clear_cookies() { - global $g_script_login_cookie; - - $t_cookies_cleared = false; - - # clear cookie, if not logged in from script - if ($g_script_login_cookie == null) { - $t_cookie_name = config_get( 'string_cookie' ); - $t_cookie_path = config_get( 'cookie_path' ); - - gpc_clear_cookie( $t_cookie_name, $t_cookie_path ); - $t_cookies_cleared = true; - } else { - $g_script_login_cookie = null; - } - return $t_cookies_cleared; - } - - # -------------------- - # Generate a string to use as the identifier for the login cookie - # It is not guaranteed to be unique and should be checked - # The string returned should be 64 characters in length - function auth_generate_cookie_string() { - $t_val = mt_rand( 0, mt_getrandmax() ) + mt_rand( 0, mt_getrandmax() ); - $t_val = md5( $t_val ) . md5( time() ); - - return substr( $t_val, 0, 64 ); - } - - # -------------------- - # Generate a UNIQUE string to use as the identifier for the login cookie - # The string returned should be 64 characters in length - function auth_generate_unique_cookie_string() { - do { - $t_cookie_string = auth_generate_cookie_string(); - } while ( !auth_is_cookie_string_unique( $t_cookie_string ) ); - - return $t_cookie_string; - } - - # -------------------- - # Return true if the cookie login identifier is unique, false otherwise - function auth_is_cookie_string_unique( $p_cookie_string ) { - $t_user_table = config_get( 'mantis_user_table' ); - - $c_cookie_string = db_prepare_string( $p_cookie_string ); - - $query = "SELECT COUNT(*) - FROM $t_user_table - WHERE cookie_string='$c_cookie_string'"; - $result = db_query( $query ); - $t_count = db_result( $result ); - if ( $t_count > 0 ) { - return false; - } else { - return true; - } - } - - # -------------------- - # Return the current user login cookie string, - # note that the cookie cached by a script login superceeds the cookie provided by - # the browser. This shouldn't normally matter, except that the password verification uses - # this routine to bypass the normal authentication, and can get confused when a normal user - # logs in, then runs the verify script. the act of fetching config variables may get the wrong - # userid. - # if no user is logged in and anonymous login is enabled, returns cookie for anonymous user - # otherwise returns '' (an empty string) - function auth_get_current_user_cookie() { - global $g_script_login_cookie, $g_cache_anonymous_user_cookie_string, $g_cache_current_user_cookie_string; - - if( isset( $g_cache_current_user_cookie_string ) ) { - return $g_cache_current_user_cookie_string; - } - - # if logging in via a script, return that cookie - if ( $g_script_login_cookie !== null ) { - return $g_script_login_cookie; - } - - # fetch user cookie - $t_cookie_name = config_get( 'string_cookie' ); - $t_cookie = gpc_get_cookie( $t_cookie_name, '' ); - - # if cookie not found, and anonymous login enabled, use cookie of anonymous account. - if ( is_blank( $t_cookie ) ) { - if ( ON == config_get( 'allow_anonymous_login' ) ) { - if ( $g_cache_anonymous_user_cookie_string === null ) { - if ( function_exists( 'db_is_connected' ) && db_is_connected() ) { - # get anonymous information if database is available - $query = sprintf('SELECT id, cookie_string FROM %s WHERE username = \'%s\'', - config_get( 'mantis_user_table' ), config_get( 'anonymous_account' ) ); - $result = db_query( $query ); - - if ( 1 == db_num_rows( $result ) ) { - $row = db_fetch_array( $result ); - $t_cookie = $row['cookie_string']; - - $g_cache_anonymous_user_cookie_string = $t_cookie; - $g_cache_current_user_id = $row['id']; - } - } - } else { - $t_cookie = $g_cache_anonymous_user_cookie_string; - } - } - } - - $g_cache_current_user_cookie_string = $t_cookie; - return $t_cookie; - } - - - #=================================== - # Data Access - #=================================== - - ######################################### - # is cookie valid? - - function auth_is_cookie_valid( $p_cookie_string ) { - global $g_cache_current_user_id, $g_cache_cookie_valid; - - # fail if DB isn't accessible - if ( !db_is_connected() ) { - return false; - } - - # fail if cookie is blank - if ( '' === $p_cookie_string ) { - return false; - } - - # succeeed if user has already been authenticated - if ( null !== $g_cache_current_user_id ) { - return true; - } - - # look up cookie in the database to see if it is valid - $t_user_table = config_get( 'mantis_user_table' ); - - $c_cookie_string = db_prepare_string( $p_cookie_string ); - - $query = "SELECT id - FROM $t_user_table - WHERE cookie_string='$c_cookie_string'"; - $result = db_query( $query ); - - # return true if a matching cookie was found - $g_cache_cookie_valid = false; - if( 1 == db_num_rows( $result ) ) { - $g_cache_cookie_valid = true; - return ( true ); - } -} + function auth_set_password($p_user_id, $p_password) + { + global $pearauth; + if( true!== $pearauth->changePassword(user_get_name($p_user_id),$p_password)) + { + return false; + } + return true; + } + ######################################### # SECURITY NOTE: cache globals are initialized here to prevent them # being spoofed if register_globals is turned on # $g_cache_current_user_id = null; - function auth_get_current_user_id() { - global $g_cache_current_user_id; - - if ( null !== $g_cache_current_user_id ) { - return $g_cache_current_user_id; - } - - $t_user_table = config_get( 'mantis_user_table' ); - - $t_cookie_string = auth_get_current_user_cookie(); - - # @@@ error with an error saying they aren't logged in? - # Or redirect to the login page maybe? - - $c_cookie_string = db_prepare_string( $t_cookie_string ); - - $query = "SELECT id - FROM $t_user_table - WHERE cookie_string='$c_cookie_string'"; - $result = db_query( $query ); - - # The cookie was invalid. Clear the cookie (to allow people to log in again) - # and give them an Access Denied message. - if ( db_num_rows( $result ) < 1 ) { - auth_clear_cookies(); - access_denied(); # never returns - return false; + global $pearauth; + global $g_cache_current_user_id; + + if ( null == $g_cache_current_user_id ) { + $g_cache_current_user_id = user_get_id_by_name($pearauth->getUsername()); } - $t_user_id = (int)db_result( $result ); - $g_cache_current_user_id = $t_user_id; - - return $t_user_id; + #perhaps we should store all of this on a sucessful login into the auth obj? + return $g_cache_current_user_id; } #=================================== --- core/user_api.php Mon May 07 13:03:06 2007 +++ core/user_api.php Wed Jul 18 01:48:49 2007 @@ -342,15 +342,15 @@ # Create a user. # returns false if error, the generated cookie string if ok function user_create( $p_username, $p_password, $p_email='', $p_access_level=null, $p_protected=false, $p_enabled=true, $p_realname='' ) { + global $pearauth; + if ( null === $p_access_level ) { $p_access_level = config_get( 'default_new_account_access_level'); } - $t_password = auth_process_plain_password( $p_password ); - + $c_username = db_prepare_string( $p_username ); $c_realname = db_prepare_string( $p_realname ); - $c_password = db_prepare_string( $t_password ); $c_email = db_prepare_string( $p_email ); $c_access_level = db_prepare_int( $p_access_level ); $c_protected = db_prepare_bool( $p_protected ); @@ -362,20 +362,46 @@ user_ensure_realname_unique( $p_username, $p_realname ); email_ensure_valid( $p_email ); - $t_seed = $p_email . $p_username; + $t_seed = $p_email . $p_username; + + # + # this is for perma-login.... we could use the $pearAuth->setAuth(string $username) + # to force a login if the cookie is good. + # + + /* $t_cookie_string = auth_generate_unique_cookie_string( $t_seed ); + */ + + /* bypass perma-cookie for now*/ + $t_cookie_string = ""; + $t_user_table = config_get( 'mantis_user_table' ); - - $query = "INSERT INTO $t_user_table - ( username, email, password, date_created, last_visit, - enabled, access_level, login_count, cookie_string, realname ) - VALUES - ( '$c_username', '$c_email', '$c_password', " . db_now() . "," . db_now() . ", - $c_enabled, $c_access_level, 0, '$t_cookie_string', '$c_realname')"; - db_query( $query ); - - # Create preferences for the user - $t_user_id = db_insert_id( $t_user_table ); + + #this will add the user to the auth method. ... + # some auth methods may already have the + # users added, and we would just need to create the rest of the information. + $pearauth->addUser($p_username,$p_password); + + # update the database with the default configuration + $query = "UPDATE $t_user_table SET + email= '$c_email', date_created = " . db_now() . ", last_visit = " . db_now() . ", + enabled = $c_enabled, access_level = $c_access_level, login_count = 0 , cookie_string = '$t_cookie_string', + realname = '$c_realname' + WHERE username = '$c_username';"; + + db_query( $query ); + + # Create preferences for the user + if(db_is_pgsql()) + { + $t_user_id = user_get_id_by_name( $p_username ); + } + else + { + $t_user_id = db_insert_id( $t_user_table ); + } + user_pref_set_default( $t_user_id ); # Users are added with protected set to FALSE in order to be able to update @@ -389,8 +415,9 @@ $t_confirm_hash = auth_generate_confirm_hash( $t_user_id ); email_signup( $t_user_id, $p_password, $t_confirm_hash ); } - - return $t_cookie_string; + + if($t_cookie_string) return $t_cookie_string; + return true; } # -------------------- @@ -1069,21 +1096,11 @@ # -------------------- # Set the user's password to the given string, encoded as appropriate function user_set_password( $p_user_id, $p_password, $p_allow_protected=false ) { - $c_user_id = db_prepare_int( $p_user_id ); - if ( !$p_allow_protected ) { user_ensure_unprotected( $p_user_id ); } - - $t_password = auth_process_plain_password( $p_password ); - $t_user_table = config_get( 'mantis_user_table' ); - $query = "UPDATE $t_user_table - SET password='$t_password' - WHERE id='$c_user_id'"; - db_query( $query ); - - #db_query() errors on failure so: - return true; + + return auth_set_password($p_user_id, $p_password); } # -------------------- @@ -1136,10 +1153,9 @@ if ( ( ON == config_get( 'send_reset_password' ) ) && ( ON == config_get( 'enable_email_notification' ) ) ) { # Create random password $t_email = user_get_field( $p_user_id, 'email' ); - $t_password = auth_generate_random_password( $t_email ); - $t_password2 = auth_process_plain_password( $t_password ); - - user_set_field( $p_user_id, 'password', $t_password2 ); + $t_password = auth_generate_random_password( $t_email ); + + if(!auth_set_password($p_user_id,$t_password)) return false; # Send notification email if ( $p_send_email ) { @@ -1148,8 +1164,8 @@ } } else { # use blank password, no emailing - $t_password = auth_process_plain_password( '' ); - user_set_field( $p_user_id, 'password', $t_password ); + if(!auth_set_password($p_user_id,$t_password)) return false; + # reset the failed login count because in this mode there is no emailing user_reset_failed_login_count_to_zero( $p_user_id ); } --- login.php Sat Mar 03 07:54:16 2007 +++ login.php Wed Jul 18 01:02:57 2007 @@ -15,41 +15,17 @@ require_once( 'core.php' ); - $f_username = gpc_get_string( 'username', '' ); - $f_password = gpc_get_string( 'password', '' ); - $f_perm_login = gpc_get_bool( 'perm_login' ); - $f_return = gpc_get_string( 'return', config_get( 'default_home_page' ) ); - $f_from = gpc_get_string( 'from', '' ); + # + # not sure how to support HTTP_AUTH. I didn't see a storage continer for it + # in pear::AUTH. Maybe someone will write it? + # - if ( BASIC_AUTH == config_get( 'login_method' ) ) { - $f_username = $_SERVER['REMOTE_USER']; - $f_password = $_SERVER['PHP_AUTH_PW']; - } - - if ( HTTP_AUTH == config_get( 'login_method' ) ) { - if ( !auth_http_is_logout_pending() ) - { - if ( isset( $_SERVER['PHP_AUTH_USER'] ) ) - $f_username = $_SERVER['PHP_AUTH_USER']; - if ( isset( $_SERVER['PHP_AUTH_PW'] ) ) - $f_password = $_SERVER['PHP_AUTH_PW']; - } else { - auth_http_set_logout_pending( false ); - auth_http_prompt(); - return; - } - } - - if ( auth_attempt_login( $f_username, $f_password, $f_perm_login ) ) { + if ( $pearauth->checkAuth() ) { $t_redirect_url = 'login_cookie_test.php?return=' . urlencode( $f_return ); - } else { + } + else + { $t_redirect_url = 'login_page.php?return=' . urlencode( $f_return ) . '&error=1'; - - if ( HTTP_AUTH == config_get( 'login_method' ) ) { - auth_http_prompt(); - exit; - } } - print_header_redirect( $t_redirect_url ); ?> --- login_page.php Sun Jul 23 18:31:28 2006 +++ login_page.php Wed Jul 18 00:22:11 2007 @@ -11,6 +11,7 @@ # Login page POSTs results to login.php # Check to see if the user is already logged in + $g_login_allowed = false; require_once( 'core.php' ); @@ -23,7 +24,7 @@ $f_return = gpc_get_string( 'return', '' ); # Check for HTTP_AUTH. HTTP_AUTH is handled in login.php - +/* if ( HTTP_AUTH == config_get( 'login_method' ) ) { $t_uri = "login.php"; @@ -38,7 +39,7 @@ print_header_redirect( $t_uri ); exit; } - +*/ html_page_top1(); html_page_top2a(); @@ -183,7 +184,7 @@ ( $t_upgrade_count != ( $t_upgrades_reqd + 10 ) ) ) { # there are 10 optional data escaping fixes that may be present echo '<div class="warning" align="center">'; echo '<p><font color="red"><strong>WARNING:</strong> The database structure may be out of date. Please upgrade <a href="admin/upgrade.php">here</a> before logging in.</font></p>'; - echo '</div>'; + echo '</div>'; } } | ||||
related to | 0003043 | closed | grangeway | support for NTLM authentication |
related to | 0000287 | closed | prescience | authenticate against LDAP |
related to | 0004234 | closed | vboctor | CAS authentication |
related to | 0004010 | closed | dregad | Add NIS authentication as an alternative |
related to | 0003303 | acknowledged | Use X.509 certificate for authentication | |
related to | 0003887 | acknowledged | radius authentcation support [patch] | |
related to | 0003847 | closed | grangeway | CMS Integration (Namrly - Xoops) |
related to | 0007478 | closed | dregad | MS Active Directory Authentication |
related to | 0007432 | closed | vboctor | LDAP integration with Active Directory |
related to | 0006771 | closed | vboctor | LDAP - Allow auth not to require dedicated LDAP account |
related to | 0008012 | closed | dregad | Consider supporting Linux-PAM for authentication |
parent of | 0003068 | closed | grangeway | render_full_name in core/print.php |
has duplicate | 0003394 | closed | grangeway | rely on external source for authentication |
has duplicate | 0007989 | closed | jreese | Multiple or Composite authentication mode for mantisbt |
has duplicate | 0006718 | closed | jreese | Multiple authentification |
has duplicate | 0007791 | closed | atrol | Allow custom login method |
related to | 0004292 | closed | thraxisp | Sign-up sends a password for LDAP |
related to | 0008402 | closed | atrol | Single Sign on for CMS such as Drupal, Joomla, Mambo etc |
related to | 0011219 | acknowledged | Provide OAuth inter-application authentication "tokens" mechanism | |
related to | 0012627 | new | Plugin to enable login based upon Active Directory | |
related to | 0007371 | new | Single signon for PHP-Fusion | |
related to | 0019919 | closed | dregad | New Authentication Method HTTP_AUTH_LDAP |
related to | 0022740 | closed | vboctor | Allowed memory size of 268435456 bytes exhausted |
related to | 0022744 | closed | vboctor | Signup is not working on mantisbt.org/bugs |
We may want to look at the PEAR Authentication module for this. It covers all of the current authentication methods we use and is supposed to be extensible. I wrote a NIS method for it very quickly. |
|
I agree that we should probably support PEAR authentication rather than inventing our own API. I remember I looked at it before and I liked it. It basically provides one interface that can be used to access more than one authentication technique, the nice thing is that they can be mixed, rather than having to use just one technique. So probably we can add Mantis authentication as one of the techniques. Note that the above is from memory so it may not be very accurate. |
|
I did have a look at the PEAR Auth package. It does seem much interresting. But there are two points to check.
|
|
Perhaps that encapsulating class should also take in the account the possibility that PEAR's Authentication module is not installed/available and fall back to our own authentication in that case? Depends on how likely it is that the Authentication module is not installed (and how difficult it is to install). |
|
The attached files implement PEAR_Auth using the DB container (hardcoded). I needed to patch the postgres ADO in order to get the app to work. I suppose that should be posted under a separate issue. Auth_Container_ArrayAuth_Container_DBAuth_Container_DBLiteAuth_Container_FileAuth_Container_IMAPAuth_Container_KADM5Auth_Container_LDAPAuth_Container_MDBAuth_Container_MDB2Auth_Container_MultipleAuth_Container_PEARAuth_Container_POP3Auth_Container_RADIUSAuth_Container_SAPAuth_Container_SMBPasswdAuth_Container_SOAPAuth_Container_SOAP5Auth_Container_vpopmail |
|
Could someone create a wiki page to let me start specifying a requirement list for this issue. |
|
NT, Wiki page created! Go for it. |
|
NT, I had a quick look at the requirements, and I believe it might be useful to have a "Scenarios" or "High Level Requirements" section after the "Introduction" and before we get into the detailed requirements. Following is some sample content that I had in mind:
|
|
Hello vboctor, NT, I took the liberty of placing some comments en ideas in the document of NT In reference to the requirements of vboctor: regards, Niels |
|
What is the status of this? I would really love to use mantis but we already have an intranet user system and I don have to have to have another login for people to be able to submit bugs. |
|
I am also interested in this feature as well. Could anyone who was previously working on this or who has done anything with this, provide what they know as far a status update? Or did it pretty much stop at a list of requirements? |
|
Hi, |
|
Have there been any plan when this is going to be implemented? 1.2.x or 1.3.x ? |
|
Hi, please consider using http://simplesamlphp.org/ for this - it will be the best solution for putting all the best php apps together! |
|
+1 in regards to http://simplesamlphp.org SimpleSAMLphp is far from trivial to configure but, once configured, it can remove from other webapps a lot of logic related to authentication and user provisioning. For more information about user provisioning, look for module "selfregister" (a module for simplesamlphp). |
|
Hi, i did code modification and simpleSAMLphp work with mantibt 1.3.0 how ever it will be more nicely implement if mantisbt have auth-plugin environment |
|
@dpenezic: Could you please provide more information? Thanks a lot :) |
|
@rgomes1997: You may found patch, part of configuration, and simplesamlphp_api.php file on fallow link http://developer.aaiedu.hr/download/ssphp_auth_addon_v.0.1.tar.gz |
|
Any progress on this feature? PEAR Auth based patch looks quite complete and simple. Even the configuration for PEAR Auth is quite simple. So as a default use multiple with variable number of Auth containers defined in config. http://pear.php.net/manual/en/package.authentication.auth.storage.multiple.php |
|
It seems the patch URL provided by @dpenezic is not available any more. So I have attached a copy of the original patch. |
|
I've got the patch from @dpenezic working on Mantis v2.1.0. Is it interesting to the team, and should I create a PR to merge into the core code? |
|
@epenet I had a (very) quick look at your code (https://github.com/epenet/mantisbt/pull/1) As far as I can tell it does not really address the current issue, i.e. implementing authentication via plugins (in the MantisBT sense of the term) - it just adds a new standard authentication method (SAML) which, in a perfect world in which we had auth plugin events, should be developed as a plugin. Anyway, that being said, pull requests are always welcome; here's some comments on your code :
|
|
If there's a chance it might make it into the core functionnality, then I'm happy to make the necessary code changes. However, if it will never be brought into the core, and parked until authentication plugins are implemented then it's hard to be motivated. |
|
Sample Authentication Plugin |
|
What would be the future of LDAP authentication? Will it be moved to AuthPlugin or remain in the core? |
|
MantisBT: master 8e466bb3 2017-03-25 17:10 Details Diff |
Support authentication plugins Provide plugins with the ability to control authentication related flags and provide their own login flows. Fixes 0004235 |
Affected Issues 0004235 |
|
mod - account_page.php | Diff File | ||
mod - admin/check/check_anonymous_inc.php | Diff File | ||
mod - api/rest/restcore/AuthMiddleware.php | Diff File | ||
mod - api_token_create.php | Diff File | ||
mod - api_tokens_page.php | Diff File | ||
mod - core/access_api.php | Diff File | ||
mod - core/antispam_api.php | Diff File | ||
mod - core/api_token_api.php | Diff File | ||
mod - core/authentication_api.php | Diff File | ||
mod - core/custom_function_api.php | Diff File | ||
mod - core/events_inc.php | Diff File | ||
mod - core/gpc_api.php | Diff File | ||
mod - core/html_api.php | Diff File | ||
mod - core/layout_api.php | Diff File | ||
mod - core/print_api.php | Diff File | ||
mod - core/user_api.php | Diff File | ||
mod - css/status_config.php | Diff File | ||
mod - index.php | Diff File | ||
mod - issues_rss.php | Diff File | ||
mod - login.php | Diff File | ||
mod - login_cookie_test.php | Diff File | ||
mod - login_page.php | Diff File | ||
mod - logout_page.php | Diff File | ||
mod - lost_pwd.php | Diff File | ||
mod - lost_pwd_page.php | Diff File | ||
mod - manage_user_edit_page.php | Diff File | ||
mod - manage_user_reset.php | Diff File | ||
mod - news_rss.php | Diff File | ||
mod - signup.php | Diff File | ||
mod - signup_page.php | Diff File | ||
mod - verify.php | Diff File | ||
MantisBT: master 65438e05 2017-03-25 17:15 Details Diff |
Document EVENT_AUTH_FLAGS event |
Affected Issues 0004235 |
|
mod - docbook/Developers_Guide/en-US/Events_Reference.xml | Diff File | ||
MantisBT: master 7fa0c354 2017-03-25 19:15 Details Diff |
Fix redirect after login Fixes 0004235 |
Affected Issues 0004235 |
|
mod - core/authentication_api.php | Diff File | ||
MantisBT: master 0cb7683d 2017-03-25 19:30 Details Diff |
Add ‘signup_access_level’ auth flag Fixes 0004235 |
Affected Issues 0004235 |
|
mod - core/antispam_api.php | Diff File | ||
mod - core/authentication_api.php | Diff File | ||
mod - core/user_api.php | Diff File | ||
MantisBT: master 615be21c 2017-03-25 20:03 Details Diff |
Use auth flags for reauthentication Fixes 0004235 |
Affected Issues 0004235 |
|
mod - core/access_api.php | Diff File | ||
mod - core/authentication_api.php | Diff File | ||
MantisBT: master ddc9cec7 2017-03-25 20:18 Details Diff |
Reference ‘SampleAuth’ plugin from docs Fixes 0004235 |
Affected Issues 0004235 |
|
mod - docbook/Developers_Guide/en-US/Events_Reference.xml | Diff File | ||
MantisBT: master 0ec31e9b 2017-03-26 15:34 Details Diff |
Use classes for AuthFlags and AuthPlugin - Use classes. - Use chain event rather than first to allow for multiple auth plugins as long as they don’t conflict. |
Affected Issues 0004235 |
|
mod - core/authentication_api.php | Diff File | ||
add - core/classes/AuthFlags.class.php | Diff File | ||
add - core/classes/AuthPlugin.class.php | Diff File | ||
mod - core/events_inc.php | Diff File | ||
MantisBT: master c76333ac 2017-04-08 10:29 Details Diff |
Keep anonymous access as core feature only Remove control for anonymous access for auth flags. |
Affected Issues 0004235 |
|
mod - core/authentication_api.php | Diff File | ||
mod - core/classes/AuthFlags.class.php | Diff File | ||
MantisBT: master 6fed9b77 2017-04-08 10:52 Details Diff |
Keep signup settings in core only |
Affected Issues 0004235 |
|
mod - core/authentication_api.php | Diff File | ||
mod - core/classes/AuthFlags.class.php | Diff File | ||
MantisBT: master 9734b159 2017-04-08 11:05 Details Diff |
Add a password login page Start with an exact copy of login_page.php so that changes are reviewable. |
Affected Issues 0004235 |
|
add - login_password_page.php | Diff File | ||
MantisBT: master 5f26bfb6 2017-04-08 11:18 Details Diff |
Improve `auth_prepare_username` to use in login |
Affected Issues 0004235 |
|
mod - core/authentication_api.php | Diff File | ||
MantisBT: master 674363f2 2017-04-08 11:37 Details Diff |
Use paginated sign-in First page - User name - Signup - Anonymous access Second page - Password - Forgot Password - Secure Session - Remember me For plugins, the second page can be replaced with their own. |
Affected Issues 0004235 |
|
mod - login_page.php | Diff File | ||
mod - login_password_page.php | Diff File | ||
MantisBT: master 1d1c9ade 2017-04-08 11:46 Details Diff |
Default username on lost password page |
Affected Issues 0004235 |
|
mod - login_password_page.php | Diff File | ||
mod - lost_pwd_page.php | Diff File | ||
MantisBT: master 02472101 2017-04-08 12:09 Details Diff |
Re-authentication flow to trigger credential page The re-authentication flow now triggers the credentials page since it doesn’t need to ask for username. |
Affected Issues 0004235 |
|
mod - core/authentication_api.php | Diff File | ||
mod - core/helper_api.php | Diff File | ||
mod - login_password_page.php | Diff File | ||
MantisBT: master d1f46e1f 2017-04-08 12:44 Details Diff |
Remove API tokens threshold from Auth Flags API tokens can always be created unless user is protected. Protected user can use already created tokens. |
Affected Issues 0004235 |
|
mod - api_token_create.php | Diff File | ||
mod - api_tokens_page.php | Diff File | ||
mod - core/api_token_api.php | Diff File | ||
mod - core/authentication_api.php | Diff File | ||
mod - core/classes/AuthFlags.class.php | Diff File | ||
mod - core/html_api.php | Diff File | ||
MantisBT: master 1dc4535a 2017-04-08 12:54 Details Diff |
Remove AuthPlugin abstract class |
Affected Issues 0004235 |
|
rm - core/classes/AuthPlugin.class.php | Diff | ||
MantisBT: master 21af4d24 2017-04-08 13:35 Details Diff |
Remove left over api field from AuthFlags |
Affected Issues 0004235 |
|
mod - core/classes/AuthFlags.class.php | Diff File | ||
MantisBT: master 7ac97abc 2017-04-08 14:13 Details Diff |
Change ‘can set password’ from threshold to bool Since it now applies to a specific user or a default, use bool instead of threshold. |
Affected Issues 0004235 |
|
mod - core/authentication_api.php | Diff File | ||
mod - core/classes/AuthFlags.class.php | Diff File | ||
MantisBT: master cfeab360 2017-04-08 14:15 Details Diff |
Remove redundant method for pwd managed elsewhere |
Affected Issues 0004235 |
|
mod - account_page.php | Diff File | ||
mod - core/authentication_api.php | Diff File | ||
mod - verify.php | Diff File | ||
MantisBT: master ed305696 2017-04-08 14:25 Details Diff |
Add ‘Enter password for %username’ on pwd page |
Affected Issues 0004235 |
|
mod - lang/strings_english.txt | Diff File | ||
mod - login_password_page.php | Diff File | ||
MantisBT: master 90a6b734 2017-04-08 14:34 Details Diff |
Make ‘can_use_standard_login’ as bool No need for threshold since auth flags are per user. Also no need for a separate can set password, since if standard login is enabled, we check the native auth provider and decide that. |
Affected Issues 0004235 |
|
mod - core/authentication_api.php | Diff File | ||
mod - core/classes/AuthFlags.class.php | Diff File | ||
MantisBT: master 90c02d69 2017-04-08 14:47 Details Diff |
Add credentials page to auth flags and use consts |
Affected Issues 0004235 |
|
mod - config_defaults_inc.php | Diff File | ||
mod - core/authentication_api.php | Diff File | ||
mod - core/classes/AuthFlags.class.php | Diff File | ||
mod - core/constant_inc.php | Diff File | ||
mod - css/status_config.php | Diff File | ||
mod - login_page.php | Diff File | ||
mod - login_password_page.php | Diff File | ||
mod - lost_pwd_page.php | Diff File | ||
mod - signup.php | Diff File | ||
mod - signup_page.php | Diff File | ||
MantisBT: master f937d876 2017-04-08 15:09 Details Diff |
phpdoc for AuthFlags |
Affected Issues 0004235 |
|
mod - core/classes/AuthFlags.class.php | Diff File | ||
MantisBT: master 6810b10e 2017-04-08 15:37 Details Diff |
Fixes for per user authentication method |
Affected Issues 0004235 |
|
mod - core/authentication_api.php | Diff File | ||
mod - core/classes/AuthFlags.class.php | Diff File | ||
mod - login_password_page.php | Diff File | ||
MantisBT: master 1850aaef 2017-04-08 20:02 Details Diff |
Some minor tweaks |
Affected Issues 0004235 |
|
mod - css/status_config.php | Diff File | ||
mod - login_page.php | Diff File | ||
mod - login_password_page.php | Diff File | ||
MantisBT: master 2d5ab946 2017-04-15 22:05 Details Diff |
Code review fixes for Auth Plugins |
Affected Issues 0004235 |
|
mod - core/authentication_api.php | Diff File | ||
mod - core/classes/AuthFlags.class.php | Diff File | ||
MantisBT: master f723ff52 2017-04-16 06:14 Details Diff |
Fix call of undefined function api_token_can_create from html_api.php account_prefs_page.php was broken because of the call Issue 0004235 |
Affected Issues 0004235 |
|
mod - core/html_api.php | Diff File |