adding option to configure unAuthenticated user role

This commit is contained in:
Patrik J. Braun 2018-12-04 22:08:13 +01:00
parent 037c366e80
commit 77a815fe53
6 changed files with 22 additions and 8 deletions

View File

@ -1,7 +1,9 @@
# User rights # User rights
* Limited Guest - list dir | id | Role | rights |
* Guest - +search |----|---------------|-------------|
* User - +share | 1 | Limited Guest | list dir |
* Admin - +settings | 2 | Guest | +search |
* Developer - +see errors | 3 | User | +share |
| 4 | Admin | +settings |
| 5 | Developer | +see errors |

View File

@ -12,7 +12,7 @@ export class AuthenticationMWs {
public static async tryAuthenticate(req: Request, res: Response, next: NextFunction) { public static async tryAuthenticate(req: Request, res: Response, next: NextFunction) {
if (Config.Client.authenticationRequired === false) { if (Config.Client.authenticationRequired === false) {
req.session.user = <UserDTO>{name: 'Admin', role: UserRoles.Admin}; req.session.user = <UserDTO>{name: UserRoles[Config.Client.unAuthenticatedUserRole], role: Config.Client.unAuthenticatedUserRole};
return next(); return next();
} }
try { try {
@ -31,7 +31,7 @@ export class AuthenticationMWs {
public static async authenticate(req: Request, res: Response, next: NextFunction) { public static async authenticate(req: Request, res: Response, next: NextFunction) {
if (Config.Client.authenticationRequired === false) { if (Config.Client.authenticationRequired === false) {
req.session.user = <UserDTO>{name: 'Admin', role: UserRoles.Admin}; req.session.user = <UserDTO>{name: UserRoles[Config.Client.unAuthenticatedUserRole], role: Config.Client.unAuthenticatedUserRole};
return next(); return next();
} }
try { try {

View File

@ -2,6 +2,9 @@ import {PublicConfigClass} from '../public/ConfigClass';
import {DatabaseType, IPrivateConfig, ReIndexingSensitivity, ServerConfig, ThumbnailProcessingLib} from './IPrivateConfig'; import {DatabaseType, IPrivateConfig, ReIndexingSensitivity, ServerConfig, ThumbnailProcessingLib} from './IPrivateConfig';
import * as path from 'path'; import * as path from 'path';
import {ConfigLoader} from 'typeconfig'; import {ConfigLoader} from 'typeconfig';
import {UserService} from '../../../frontend/app/model/network/user.service';
import {Utils} from '../../Utils';
import {UserRoles} from '../../entities/UserDTO';
/** /**
* This configuration will be only at backend * This configuration will be only at backend
@ -59,6 +62,10 @@ export class PrivateConfigClass extends PublicConfigClass implements IPrivateCon
path.join(__dirname, './../../../config.json'), path.join(__dirname, './../../../config.json'),
[['PORT', 'Server-port']]); [['PORT', 'Server-port']]);
if (Utils.enumToArray(UserRoles).map(r => r.key).indexOf(this.Client.unAuthenticatedUserRole) === -1) {
throw new Error('Unknown user role for Client.unAuthenticatedUserRole, found: ' + this.Client.unAuthenticatedUserRole);
}
} }
public save() { public save() {

View File

@ -1,4 +1,5 @@
import {SortingMethods} from '../../entities/SortingMethods'; import {SortingMethods} from '../../entities/SortingMethods';
import {UserRoles} from '../../entities/UserDTO';
export module ClientConfig { export module ClientConfig {
export interface SearchConfig { export interface SearchConfig {
@ -63,6 +64,7 @@ export module ClientConfig {
RandomPhoto: RandomPhotoConfig; RandomPhoto: RandomPhotoConfig;
Other: OtherConfig; Other: OtherConfig;
authenticationRequired: boolean; authenticationRequired: boolean;
unAuthenticatedUserRole: UserRoles;
languages: string[]; languages: string[];
Video: VideoConfig; Video: VideoConfig;
MetaFile: MetaFileConfig; MetaFile: MetaFileConfig;
@ -118,6 +120,7 @@ export class PublicConfigClass {
} }
}, },
authenticationRequired: true, authenticationRequired: true,
unAuthenticatedUserRole: UserRoles.Admin,
publicUrl: '', publicUrl: '',
urlBase: '', urlBase: '',
languages: [] languages: []

View File

@ -30,7 +30,7 @@ export class AuthenticationService {
this.getSessionUser(); this.getSessionUser();
} else { } else {
if (Config.Client.authenticationRequired === false) { if (Config.Client.authenticationRequired === false) {
this.user.next(<UserDTO>{name: '', role: UserRoles.Admin}); this.user.next(<UserDTO>{name: UserRoles[Config.Client.unAuthenticatedUserRole], role: Config.Client.unAuthenticatedUserRole});
} }
} }

View File

@ -3,6 +3,7 @@ import {BehaviorSubject} from 'rxjs';
import {DatabaseType, IPrivateConfig, ReIndexingSensitivity, ThumbnailProcessingLib} from '../../../common/config/private/IPrivateConfig'; import {DatabaseType, IPrivateConfig, ReIndexingSensitivity, ThumbnailProcessingLib} from '../../../common/config/private/IPrivateConfig';
import {NetworkService} from '../model/network/network.service'; import {NetworkService} from '../model/network/network.service';
import {SortingMethods} from '../../../common/entities/SortingMethods'; import {SortingMethods} from '../../../common/entities/SortingMethods';
import {UserRoles} from '../../../common/entities/UserDTO';
@Injectable() @Injectable()
export class SettingsService { export class SettingsService {
@ -55,6 +56,7 @@ export class SettingsService {
publicUrl: '', publicUrl: '',
applicationTitle: '', applicationTitle: '',
authenticationRequired: true, authenticationRequired: true,
unAuthenticatedUserRole: UserRoles.Admin,
languages: [] languages: []
}, },
Server: { Server: {