Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[main] Rewite Ldap to Azure #109

Merged
merged 55 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
3635851
Add files via upload
Kipjr Jul 8, 2023
80cfaad
Create docker-publish.yml
Kipjr Jul 8, 2023
ba7b655
Create laravel.yml
Kipjr Jul 8, 2023
b745c85
Create DOCKER.md
Kipjr Jul 8, 2023
da3ab65
Create docker-compose.yml
Kipjr Jul 8, 2023
95f0884
Update docker-publish.yml
Kipjr Jul 8, 2023
16d6f3d
Remove "new" info
Kipjr Jul 9, 2023
330a750
Rewrite docker-compose.yml
Kipjr Jul 9, 2023
f051517
Install sail
Kipjr Jul 9, 2023
6ee7445
Force HTTPS
Kipjr Jul 9, 2023
cec7747
Fix: Trusted Proxies (Upgrade 8->9)
Kipjr Jul 9, 2023
cde9759
Fix exception handler
Kipjr Jul 9, 2023
d0138fc
Upgrade laravel from 6->10
Kipjr Jul 9, 2023
f5d64bb
Fix class naming issue
Kipjr Jul 9, 2023
354e40c
remove yarn
Kipjr Jul 9, 2023
f050438
Fix badges
Kipjr Jul 9, 2023
ae00a68
Implement changes of https://github.com/laravel/laravel/compare/6.x..…
Kipjr Jul 9, 2023
fa2db91
Fix: missing middleware
Kipjr Jul 9, 2023
fa9156a
Fix: primairy id
Kipjr Jul 9, 2023
8b5b3f9
Fix: new style routing
Kipjr Jul 9, 2023
83ab12c
Fix: inconsistencies with mensaId and Id
Kipjr Jul 9, 2023
a92f596
Fix: missing mensaId / id
Kipjr Jul 9, 2023
c4f4efd
Fix mensaId / id
Kipjr Jul 9, 2023
1afe2d2
Update UserFactory.php
Kipjr Jul 10, 2023
e84d77f
I hate spaces
Kipjr Jul 10, 2023
a22c257
update composer
Kipjr Jul 10, 2023
54dea60
Update docker-publish.yml
Kipjr Jul 11, 2023
20b66e9
Update laravel.yml
Kipjr Jul 11, 2023
4d75a06
Update laravel.yml with db location
Kipjr Jul 11, 2023
531273e
Seed db
Kipjr Jul 11, 2023
197f2a0
fix env
Kipjr Jul 11, 2023
34c3cc0
Fix wrong copy and @ in EventServiceProvider.php
Kipjr Jul 11, 2023
64ea7f9
Restore and migrate Handler.php
Kipjr Jul 11, 2023
d31ce99
Fix missing bracket
Kipjr Jul 11, 2023
1c300dc
Change method of parent
Kipjr Jul 11, 2023
78e6aff
Restore parent method
Kipjr Jul 11, 2023
1b13d87
Remove parent class
Kipjr Jul 11, 2023
6b545b7
Add tests
Kipjr Jul 11, 2023
ba0b1ac
increase logging phpunit
Kipjr Jul 11, 2023
4c22a72
update .env.example with docker-vars
Kipjr Oct 29, 2023
9958cb6
Add OAuth2 support
Kipjr Oct 28, 2023
4336756
Remove AdLdap
Kipjr Oct 28, 2023
aa2dfa9
fix: mensaId instead of id
Kipjr Oct 28, 2023
1eeb4e9
Add signin page
Kipjr Oct 28, 2023
400bba6
remove ldap config
Kipjr Oct 28, 2023
9c944dd
Add MS Graph delegated User functions
Kipjr Oct 28, 2023
69727a8
Add MS Graph application daemon functions
Kipjr Oct 28, 2023
c88bc19
Rewrite LdapHelper to AzureHelper
Kipjr Oct 28, 2023
c100376
Rewrite logincontroller
Kipjr Oct 28, 2023
55913d1
Rename LdapFunction to AzureFunction
Kipjr Oct 28, 2023
90e52b3
Rename more LdapFunctions to AzureFunctions
Kipjr Oct 28, 2023
78b2808
Remove old logincontroller
Kipjr Oct 28, 2023
dec7503
update .env.example
Kipjr Oct 28, 2023
5277677
Dont forget the ;
Kipjr Oct 28, 2023
446051e
Fix query issues
Kipjr Oct 28, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@ APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost

APP_OFFLINE=0
APP_PORT=8180
APP_SERVICE=mensa.php
WWWUSER=1000
WWWGROUP=1000
FORWARD_DB_PORT=3307

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
DB_ROOT_PASSWORD=verysecret

BROADCAST_DRIVER=log
CACHE_DRIVER=file
Expand Down Expand Up @@ -55,14 +63,22 @@ MENSA_ACCOUNTURL_BAR001=
MENSA_ACCOUNTURL_BAR002=
MENSA_ACCOUNT_WHITELIST_IPS=127.0.0.1

MENSA_LDAP_USER_BASEDN=
MENSA_LDAP_ALLOWED_GROUP=
MENSA_LDAP_ADMIN_GROUP=
LOG_CHANNEL=daily
LOG_DEPRECATIONS_CHANNEL=daily
LOG_LEVEL=warning

AZURE_EXTENSION_APP_ID= # Tenant Schema Extension App
AZURE_TENANT_ID=
AZURE_CLIENT_ID=
AZURE_SERVICEPRINCIPAL_ID=
AZURE_CLIENT_SECRET=
AZURE_ROLE_ADMIN_VALUE=
AZURE_ROLE_USER_VALUE=
AZURE_REDIRECT_URI=

ADLDAP_ACCOUNT_PREFIX=
ADLDAP_ADMIN_USERNAME=
ADLDAP_ADMIN_PASSWORD=
ADLDAP_CONTROLLERS=
ADLDAP_PORT=
ADLDAP_BASEDN=
ADLDAP_BASEDN=
81 changes: 81 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Docker

on:
push:
# Publish `main` as Docker `latest` image.
tags: [ 'v*.*.*' ]
workflow_dispatch:


env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}

jobs:
# Run tests.
# See also https://docs.docker.com/docker-hub/builds/automated-testing/
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Copy .env
run: |
if [[ ! -f '.env' ]];then
cp '.env.example' '.env'
fi
- name: Install Dependencies
run: composer require laravel/sail -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist

- name: Run tests
run: |
if [ -f docker-compose.test.yml ]; then
docker-compose --file docker-compose.test.yml build
docker-compose --file docker-compose.test.yml run sut
else
docker-compose build
fi
# Push image to GitHub Packages.
# See also https://docs.docker.com/docker-hub/builds/
push:
# Ensure test job passes before pushing image.
needs: test

runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v2

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
36 changes: 36 additions & 0 deletions .github/workflows/laravel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Laravel

on:
push:
branches: [ development ]
pull_request:
branches: [ main ]
workflow_dispatch:

jobs:
laravel-tests:

runs-on: ubuntu-latest
env:
DB_CONNECTION: sqlite
DB_DATABASE: database.sqlite
steps:
- uses: actions/checkout@v2
- name: Copy .env
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
- name: Install Dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
- name: Generate key
run: php artisan key:generate
- name: Directory Permissions
run: chmod -R 777 storage bootstrap/cache
- name: Create Database
run: |
mkdir -p database
touch database/database.sqlite
- name: Fill database
run: |
php artisan migrate:fresh
php artisan db:seed
- name: Execute tests (Unit and Feature tests) via PHPUnit
run: vendor/bin/phpunit
65 changes: 65 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
*Main*

[![Docker (Branch: Main)](https://github.com/VSLCatena/mensa/actions/workflows/docker-publish.yml/badge.svg?branch=main-docker)](https://github.com/VSLCatena/mensa/actions/workflows/docker-publish.yml)
[![Laravel (Branch: main)](https://github.com/VSLCatena/mensa/actions/workflows/laravel.yml/badge.svg?branch=main-docker)](https://github.com/VSLCatena/mensa/actions/workflows/laravel.yml)

*Development*

[![Docker (Branch: development)](https://github.com/VSLCatena/mensa/actions/workflows/docker-publish.yml/badge.svg?branch=development)](https://github.com/VSLCatena/mensa/actions/workflows/docker-publish.yml)
[![Laravel (Branch: development)](https://github.com/VSLCatena/mensa/actions/workflows/laravel.yml/badge.svg?branch=development)](https://github.com/VSLCatena/mensa/actions/workflows/laravel.yml)


# mensa
Mensa is an enrollment system for dinner that we use at our student association.
You can create dinners and assign them to cooks, who can change the dinner by adding a menu and changing some extra
info.

The back-end works through a PHP server, the front-end is html/javascript which talks to back-end through AJAX calls.
This means that with very little adjustments you could split front-end from back-end.


## Setup

### .env file
All configuration of the app itself should be doable through the .env file.
If you don't have a .env file available, you can duplicate the .env.example file to create a new .env file.

### Authorization
For authorization we use Active Directory. For this you'll need to make sure PHP-LDAP works

### Building the app
For production I recommend to look at, and following the
[Laravel deployment page](https://laravel.com/docs/8.x/deployment).
Here you can see the laravel requirements and some optimizations you can do for Laravel such as caching options.

#### Here are just the bare minimals for development purposes:
To set up composer (Package manager for PHP):
`composer install`

To set up npm (Package manager for Javascript):
`npm install`
`npm run dev`

To run migrations:
`php artisan migrate`

To fill in mock data in the database:
`php artisan db:seed`



## Running the app for development
For running the PHP server:
`php artisan serve`
This will keep a server running, and changes are reflected immediately.

For compiling the front-end source:
`npm run watch`
This will keep npm running, a new build will automatically start on every file changes,
so changes are reflected on page refresh.

These two commands have made my life a lot better :)


## Docker
Info about how to get it working in docker can be found [Here](docs/DOCKER.md)
6 changes: 4 additions & 2 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ class Kernel extends ConsoleKernel
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
protected function schedule(Schedule $schedule): void
{
// $schedule->command('inspire')->hourly();

// Remove all expired sign ins that past the 15 minutes
$schedule->command('users:deleteunconfirmed')
->everyFiveMinutes();
Expand All @@ -40,7 +42,7 @@ protected function schedule(Schedule $schedule)
*
* @return void
*/
protected function commands()
protected function commands(): void
{
$this->load(__DIR__.'/Commands');

Expand Down
78 changes: 24 additions & 54 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,75 +2,45 @@

namespace App\Exceptions;

use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Http\Request;
use Throwable;

use Illuminate\Http\Request;
class Handler extends ExceptionHandler
{
/**
* A list of the exception types that are not reported.
* The list of the inputs that are never flashed to the session on validation exceptions.
*
* @var array
*/
protected $dontReport = [
//
];

/**
* A list of the inputs that are never flashed for validation exceptions.
*
* @var array
* @var array<int, string>
*/
protected $dontFlash = [
'current_password',
'password',
'password_confirmation',
];

/**
* Report or log an exception.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @param \Exception $exception
* @return void
* Register the exception handling callbacks for the application.
*/
public function report(Exception $exception)
public function register(): void
{
parent::report($exception);
}

/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $exception
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $exception)
{
if($this->isHttpException($exception))
{
switch ($exception->getStatusCode())
{
// not found
case 404:
return redirect(route('home'));
break;

// internal error
case '500':
return redirect(route('home'));
break;

default:
return $this->renderHttpException($exception);
break;
$this->renderable(function (Throwable $exception, Request $request) {
if($this->isHttpException($exception))
{
switch ($exception->getStatusCode())
{
case 404:
return redirect(route('home'));
break;
case '500':
return redirect(route('home'));
break;

default:
return $this->renderHttpException($exception);
break;
}
}
}
else
{
return parent::render($request, $exception);
}
});
}
}
Loading
Loading