Skip to content

Commit

Permalink
feat: Default auth gate selection
Browse files Browse the repository at this point in the history
  • Loading branch information
dogukanoksuz committed Jul 5, 2024
1 parent 9b4168e commit f5d9484
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 21 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ QUEUE_DRIVER=redis
# Changes login screen brand name
BRAND_NAME="HAVELSAN © 2023"

# AUTH DEFAULT GATE
# Default gate for Liman authentication
DEFAULT_AUTH_GATE=liman

# EXTENSION TIMEOUT
# Extension request timeout parameter, Liman render engine using it
EXTENSION_TIMEOUT=30
Expand Down
39 changes: 20 additions & 19 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ public function register()
//
});

$this->renderable(function (AuthenticationException $e) {
return response()->json([
'message' => 'Giriş yapmanız gereklidir.'
], Response::HTTP_UNAUTHORIZED)
->withoutCookie('token')
->withoutCookie('currentUser');
});

// Use validator response hack
$this->renderable(function (JsonResponseException $e) {
return response()->json($e->getData(), $e->getCode() ? $e->getCode() : Response::HTTP_OK);
Expand All @@ -81,31 +89,12 @@ public function register()
}
});

$this->renderable(function (QueryException $e) {
return response()->json([
'message' => 'Veritabanı hatası mevcut. Sistem veritabanı bağlantısını kontrol ediniz.',
], Response::HTTP_INTERNAL_SERVER_ERROR);
});

$this->renderable(function (ThrottleRequestsException $e) {
return response()->json([
'message' => 'Çok fazla istek gönderdiniz. Lütfen biraz bekleyin.',
], Response::HTTP_TOO_MANY_REQUESTS);
});

$this->renderable(function (HttpException $e) {
return response()->json([
'message' => $e->getMessage()
], Response::HTTP_INTERNAL_SERVER_ERROR);
});

$this->renderable(function (AuthenticationException $e) {
return response()->json([
'message' => 'Giriş yapmanız gereklidir.'
], Response::HTTP_UNAUTHORIZED)
->withoutCookie('token')
->withoutCookie('currentUser');
});

if (config('app.debug')) {
$this->renderable(function (Throwable $e) {
Expand All @@ -126,6 +115,18 @@ public function register()
], Response::HTTP_INTERNAL_SERVER_ERROR);
});
}

$this->renderable(function (QueryException $e) {
return response()->json([
'message' => 'Veritabanı hatası mevcut. Sistem veritabanı bağlantısını kontrol ediniz.',
], Response::HTTP_INTERNAL_SERVER_ERROR);
});

$this->renderable(function (HttpException $e) {
return response()->json([
'message' => $e->getMessage()
], Response::HTTP_INTERNAL_SERVER_ERROR);
});

$this->renderable(function (Throwable $e) {
if ($e->getMessage() === 'Unauthenticated.') {
Expand Down
11 changes: 10 additions & 1 deletion app/Http/Controllers/API/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public function __construct()
'setupTwoFactorAuthentication',
'sendPasswordResetLink',
'resetPassword',
'loginBranding'
'loginBranding',
'authGate',
]
]
);
Expand Down Expand Up @@ -70,6 +71,14 @@ public function loginBranding()
]);
}

/**
* Get default auth gate
*/
public function authGate()
{
return response()->json(env('DEFAULT_AUTH_GATE', 'liman'));
}

/**
* Get a JWT via given credentials.
*
Expand Down
7 changes: 6 additions & 1 deletion app/Http/Controllers/API/Settings/TweaksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function getConfiguration()
'NEW_LOG_LEVEL' => env('NEW_LOG_LEVEL'),
'LDAP_IGNORE_CERT' => (bool) env('LDAP_IGNORE_CERT', 'false'),
'LOGIN_IMAGE' => SystemSettings::where('key', 'LOGIN_IMAGE')->first()?->data ?? '',
'DEFAULT_AUTH_GATE' => env('DEFAULT_AUTH_GATE', 'liman'),
]);
}

Expand All @@ -45,6 +46,7 @@ public function saveConfiguration(Request $request)
'APP_URL' => 'required|url',
'EXTENSION_TIMEOUT' => 'required|integer|min:1|max:300',
'NEW_LOG_LEVEL' => 'required|string',
'DEFAULT_AUTH_GATE' => 'required|string|in:liman,keycloak,ldap',
], [], [
"EXTENSION_TIMEOUT" => "Eklenti zaman aşımı"
]);
Expand All @@ -58,9 +60,10 @@ public function saveConfiguration(Request $request)
'EXTENSION_DEVELOPER_MODE' => (bool) $request->EXTENSION_DEVELOPER_MODE,
'NEW_LOG_LEVEL' => $request->NEW_LOG_LEVEL,
'LDAP_IGNORE_CERT' => (bool) $request->LDAP_IGNORE_CERT,
'DEFAULT_AUTH_GATE' => $request->DEFAULT_AUTH_GATE,
]);

if ($request->has('LOGIN_IMAGE') && $request->LOGIN_IMAGE != '')
if ($request->has('LOGIN_IMAGE') && $request->LOGIN_IMAGE != '') {
// Control if LOGIN_IMAGE is bigger than 1mb
if (strlen($request->LOGIN_IMAGE) > 1048576) {
return response()->json([
Expand All @@ -71,6 +74,7 @@ public function saveConfiguration(Request $request)
['key' => 'LOGIN_IMAGE'],
['data' => $request->get('LOGIN_IMAGE')]
);
}

AuditLog::write(
'tweak',
Expand All @@ -84,6 +88,7 @@ public function saveConfiguration(Request $request)
'EXTENSION_DEVELOPER_MODE' => (bool) $request->EXTENSION_DEVELOPER_MODE,
'NEW_LOG_LEVEL' => $request->NEW_LOG_LEVEL,
'LDAP_IGNORE_CERT' => (bool) $request->LDAP_IGNORE_CERT,
'DEFAULT_AUTH_GATE' => $request->DEFAULT_AUTH_GATE,
],
"TWEAK_EDIT"
);
Expand Down
1 change: 1 addition & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
], function () {
Route::get('/types', [AuthController::class, 'activeAuthTypes']);
Route::get('/branding', [AuthController::class, 'loginBranding']);
Route::get('/gate', [AuthController::class, 'authGate']);
Route::post('/login', [AuthController::class, 'login'])
->middleware('throttle:login');
Route::post('/setup_mfa', [AuthController::class, 'setupTwoFactorAuthentication']);
Expand Down

0 comments on commit f5d9484

Please sign in to comment.