1
0
mirror of https://github.com/mailcow/mailcow-dockerized.git synced 2025-02-03 13:22:17 +02:00

[Web] fix bug on mailbox login

This commit is contained in:
FreddleSpl0it 2023-05-16 14:50:36 +02:00 committed by DerLinkman
parent 7cf6a9d808
commit 4dc3222f03
No known key found for this signature in database
GPG Key ID: F109FD97469550A2
3 changed files with 11 additions and 20 deletions

View File

@ -333,26 +333,16 @@ function keycloak_mbox_login_rest($user, $pass, $iam_settings, $is_internal = fa
return 'user'; return 'user';
} }
// try to create mbox on successfull login // check if matching attribute exist
$mbox_template = null; $mapper_key = array_search($user_template, $iam_settings['mappers']);
// check if matching attribute mapping exists if ($mapper_key === false) return false;
foreach ($iam_settings['mappers'] as $index => $mapper){
if (in_array($mapper, $iam_settings['mappers'])) {
$mbox_template = $iam_settings['templates'][$index];
break;
}
}
if (!$mbox_template){
// no matching template found
return false;
}
// create mailbox // create mailbox
$create_res = mailbox('add', 'mailbox_from_template', array( $create_res = mailbox('add', 'mailbox_from_template', array(
'domain' => explode('@', $user)[1], 'domain' => explode('@', $user)[1],
'local_part' => explode('@', $user)[0], 'local_part' => explode('@', $user)[0],
'authsource' => 'keycloak', 'authsource' => 'keycloak',
'template' => $mbox_template 'template' => $iam_settings['mappers'][$mapper_key]
)); ));
if (!$create_res) return false; if (!$create_res) return false;

View File

@ -2316,7 +2316,7 @@ function identity_provider($_action, $_data = null, $_extra = null) {
); );
return true; return true;
} }
// get mapped template, if not set return false // get mapped template, if not set return false
// also return false if no mappers were defined // also return false if no mappers were defined
$provider = identity_provider('get'); $provider = identity_provider('get');
@ -2330,9 +2330,10 @@ function identity_provider($_action, $_data = null, $_extra = null) {
); );
return false; return false;
} }
// check if matching attribute exist // check if matching attribute exist
if (array_search($user_template, $provider['mappers']) === false) { $mapper_key = array_search($user_template, $provider['mappers']);
if ($mapper_key === false) {
clear_session(); clear_session();
$_SESSION['return'][] = array( $_SESSION['return'][] = array(
'type' => 'danger', 'type' => 'danger',
@ -2341,13 +2342,13 @@ function identity_provider($_action, $_data = null, $_extra = null) {
); );
return false; return false;
} }
// create mailbox // create mailbox
$create_res = mailbox('add', 'mailbox_from_template', array( $create_res = mailbox('add', 'mailbox_from_template', array(
'domain' => explode('@', $info['email'])[1], 'domain' => explode('@', $info['email'])[1],
'local_part' => explode('@', $info['email'])[0], 'local_part' => explode('@', $info['email'])[0],
'authsource' => identity_provider('get')['authsource'], 'authsource' => identity_provider('get')['authsource'],
'template' => $user_template 'template' => $provider['templates'][$mapper_key]
)); ));
if (!$create_res){ if (!$create_res){
clear_session(); clear_session();

View File

@ -1361,7 +1361,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
break; break;
} }
} }
return mailbox('add', 'mailbox', $mailbox_attributes, array('iam_create_login' => true)); return mailbox('add', 'mailbox', $mailbox_attributes, array('iam_create_login' => true));
break; break;
case 'resource': case 'resource':