|
10 | 10 | use ProcessMaker\Events\Logout; |
11 | 11 | use ProcessMaker\Http\Controllers\Controller; |
12 | 12 | use ProcessMaker\Managers\LoginManager; |
| 13 | +use ProcessMaker\Models\Setting; |
13 | 14 | use ProcessMaker\Models\User; |
14 | 15 | use ProcessMaker\Traits\HasControllerAddons; |
15 | 16 |
|
@@ -55,17 +56,90 @@ public function showLoginForm() |
55 | 56 | { |
56 | 57 | $manager = App::make(LoginManager::class); |
57 | 58 | $addons = $manager->list(); |
| 59 | + // Review if we need to redirect the default SSO |
| 60 | + if (config('app.enable_default_sso')) { |
| 61 | + $arrayAddons = $addons->toArray(); |
| 62 | + $driver = $this->getDefaultSSO($arrayAddons); |
| 63 | + // If a default SSO was defined we will to redirect |
| 64 | + if (!empty($driver)) { |
| 65 | + return redirect()->route('sso.redirect', ['driver' => $driver]); |
| 66 | + } |
| 67 | + } |
58 | 68 | $block = $manager->getBlock(); |
59 | 69 | // clear cookie to avoid an issue when logout SLO and then try to login with simple PM login form |
60 | 70 | \Cookie::queue(\Cookie::forget(config('session.cookie'))); |
61 | 71 | // cookie required here because SSO redirect resets the session |
62 | | - $cookie = cookie('processmaker_intended', redirect()->intended()->getTargetUrl(), 10, null, null, true, true, false, 'none'); |
| 72 | + $cookie = cookie( |
| 73 | + 'processmaker_intended', |
| 74 | + redirect()->intended()->getTargetUrl(), |
| 75 | + 10, |
| 76 | + null, |
| 77 | + null, |
| 78 | + true, |
| 79 | + true, |
| 80 | + false, |
| 81 | + 'none' |
| 82 | + ); |
63 | 83 | $response = response(view('auth.login', compact('addons', 'block'))); |
64 | 84 | $response->withCookie($cookie); |
65 | 85 |
|
66 | 86 | return $response; |
67 | 87 | } |
68 | 88 |
|
| 89 | + protected function getDefaultSSO(array $addons): string |
| 90 | + { |
| 91 | + $addonsData = !empty($addons) ? head($addons)->data : []; |
| 92 | + $defaultSSO = ''; |
| 93 | + if (class_exists(\ProcessMaker\Package\Auth\Database\Seeds\AuthDefaultSeeder::class)) { |
| 94 | + $defaultSSO = Setting::byKey( |
| 95 | + \ProcessMaker\Package\Auth\Database\Seeds\AuthDefaultSeeder::SSO_DEFAULT_LOGIN |
| 96 | + ); |
| 97 | + } |
| 98 | + if (!empty($defaultSSO) && !empty($addonsData)) { |
| 99 | + // Get the config selected |
| 100 | + $position = $this->getColumnAttribute($defaultSSO, 'config', 'config'); |
| 101 | + // Get the ui defined |
| 102 | + $elements = $this->getColumnAttribute($defaultSSO, 'ui', 'elements'); |
| 103 | + $options = $this->getColumnAttribute($defaultSSO, 'ui', 'options'); |
| 104 | + // Get the sso drivers configured |
| 105 | + $drivers = !empty($addonsData['drivers']) ? $addonsData['drivers'] : []; |
| 106 | + if ( |
| 107 | + is_int($position) |
| 108 | + && $options[$position] !== AuthDefaultSeeder::PM_LOGIN |
| 109 | + && !empty($elements) |
| 110 | + && !empty($drivers) |
| 111 | + ) { |
| 112 | + // Get the specific element defined with the default SSO |
| 113 | + $element = !empty($elements[$position]->name) ? strtolower($elements[$position]->name) : ''; |
| 114 | + if (!empty($element) && array_key_exists($element, $drivers)) { |
| 115 | + return $element; |
| 116 | + } |
| 117 | + } |
| 118 | + } |
| 119 | + |
| 120 | + return ''; |
| 121 | + } |
| 122 | + |
| 123 | + protected function getColumnAttribute(object $setting, string $attribute, string $key = '') |
| 124 | + { |
| 125 | + $config = $setting->getAttribute($attribute); |
| 126 | + switch ($key) { |
| 127 | + case 'config': |
| 128 | + $result = !is_null($config) ? (int) $config : null; |
| 129 | + break; |
| 130 | + case 'elements': |
| 131 | + $result = !empty($config->elements) ? $config->elements : []; |
| 132 | + break; |
| 133 | + case 'options': |
| 134 | + $result = !empty($config->options) ? $config->options : []; |
| 135 | + break; |
| 136 | + default: |
| 137 | + $result = null; |
| 138 | + } |
| 139 | + |
| 140 | + return $result; |
| 141 | + } |
| 142 | + |
69 | 143 | public function loginWithIntendedCheck(Request $request) |
70 | 144 | { |
71 | 145 | $intended = Cookie::get('processmaker_intended'); |
@@ -96,6 +170,13 @@ public function loginWithIntendedCheck(Request $request) |
96 | 170 | } |
97 | 171 | } |
98 | 172 |
|
| 173 | + if (class_exists(\ProcessMaker\Package\Auth\Auth\LDAPLogin::class)) { |
| 174 | + $redirect = \ProcessMaker\Package\Auth\Auth\LDAPLogin::auth($user, $request->input('password')); |
| 175 | + if ($redirect !== false) { |
| 176 | + return $redirect; |
| 177 | + } |
| 178 | + } |
| 179 | + |
99 | 180 | return $this->login($request); |
100 | 181 | } |
101 | 182 |
|
|
0 commit comments