2.0.5 • Published 1 year ago

exc-security-v2 v2.0.5

Weekly downloads
29
License
-
Repository
-
Last release
1 year ago

Module Exc-Security-V2

Content
  • ExcSecurityModule
Services
  • ExcSecurityService
Enumerations
  • ExcSecurityEvent
Interfaces
  • IExcCurrentUser
  • IExcCredentials
Classes
  • ExcCredentials
  • ExcStateSecurityProcessor (implements CanActivate of angular router)

Dependencies

  • exc-core-v2
  • exc-rest-v2
  • @angular/router

Install

To install ExcRestModule into your project use

npm i exc-security-v2

ExcSecurityService

Dependencies

  • Register environment into ExcCoreModule.Config() with ExcCoreModule.RegisterConfig('Environment',environment)
  • Add appID, secMode and mainToken into sec section in environment.ts
export const environment = {
  production: false,
  sec: {
    secMode: 'DEFAULT', /* DEFAULT | CODE */
    appID: 17, /* GlobalAccess AppIndex */
    mainToken: 'APPUSE', /* Maintoken to use the application */
  },
  rest: {
    ServiceUrl: 'Base URL of Service with trailing /',
    LoginUrl: 'Base URL of Security Service with trailing /',
    Endpoints: {
      PasswordSettings: 'PasswordSettings'
    }
  }
};

Setup

To use ExcSecurityService you have to do preparations in your project. You have to add Router in your module constructor and register it to ExcCoreModule

  1. app.module.ts
//...
import {environment} from '../environments/environment';
import {ExcCoreModule} from 'exc-core-v2';
import {ExcRestModule, ExcRestService, ExcRestMode, ExcTranslateService} from 'exc-rest-v2';
import {ExcSecurityModule, ExcStateSecurityProcessor} from 'exc-security-v2';
import {AppComponent} from './app.component';

@NgModule({
  declarations: [AppComponent],
  imports: [
    BrowserModule,
    AppRoutingModule,
    ExcCoreModule,
    ExcRestModule,
    ExcSecurityModule
    //...
  ],
  providers: [ExcStateSecurityProcessor],
  bootstrap: [AppComponent]
})
export class AppModule {
  constructor(private excRest: ExcRestService, private excTranslate: ExcTranslateService, private router: Router) {
    ExcCoreModule.RegisterConfig('Environment', environment);
    ExcCoreModule.RegisterService('Router', router); /* Add this line */
    excRest.Mode = ExcRestMode.GROOT;
    excTranslate.activate();
  }
}
  1. app.component.ts
//...
import {ExcCoreModule} from 'exc-core-v2';
import {ExcRestService} from 'exc-rest-v2';
import {ExcSecurityService} from 'exc-security-v2';

//...
export class AppComponent implements OnInit {
//...
  constructor(private excRestService: ExcRestService, public excSecurityService: ExcSecurityService) {
  /* If you want to trigger calls after successful authentication you can subscribe any event */
    excSecurityService.OnReady.subscribe(()=>{
        /* Do anything */
    })
  }
}
  1. app-routing.module.ts
//...
import {ExcSecurityService} from 'exc-security-v2';

const routes: Routes = [
  {
    path: '', redirectTo: '/testroute1', pathMatch: 'full',
    data: {hidden: true}
  },
  {
    path: 'testroute1',
    component: Testroute1Component,
    canActivate: [ExcStateSecurityProcessor],
    data: {class: 'fas fa-home', friendlyName: 'TestRoute1', security: '*'} /*  Use * to allow without security context. Use $$REDIR$$ for manual redirection states */
  },
  {
    path: 'testroute2',
    component: Testroute2Component,
    canActivate: [ExcStateSecurityProcessor],
    data: {class: 'fas fa-brain', friendlyName: 'TestRoute2', security: 'APPUSE'} /* Use Tokens for security check. Multiple tokens are comma separated. Tokens are OR linked */
  }
];
//...

Definitions

Events

NameEmitted paramsDescription
OnReady-Triggered after initial successful authentication
OnLoggedOut-Triggered after logout
OnRefreshincludeToken?: booleanTriggers reload of authentication information. ExcSecurityService has subscribed this Eventhandler To emit this event use excRestService.OnRefresh.emit(includeToken?: boolean)
OnTokenRefreshed-Triggered after reloading of authentication information.
OnIsPwdChangeForced-Triggered after reloading of authentication information if password change is forced.

Properties

NameTypeDescription
LoggedInbooleanGet flag if user is logged in or not.
IsInitializingbooleanGet flag if ExcSecurityService is already initializing
CredentialsExcCredentialsGet credential instance for login mask
UserLoginstringGet user login of logged in user
UserNamestringGet name of logged in user

Methods

Login(credentials?)
Parameters
NameTypeDescription
credentialsIExcCredentials | ExcCredentials(optional) Credentials for login. If parameter is missing it uses Credentials instance of service instead.
Returns

void

Examples
const excSecurity = ExcCoreModule.Services().ExcSecurityService;
let credentials: IExcCredentials = {uid: 'username',pwd: 'password'}

excSecurity.Login(credentials);
Logout()
Parameters
NameTypeDescription
Returns

void

Examples
const excSecurity = ExcCoreModule.Services().ExcSecurityService;
excSecurity.Logout();
changePassword(pwdOld, pwdNew, pwdNewRepeat)
Parameters
NameTypeDescription
pwdOldstringOld password
pwdNewstringNew password
pwdNewRepeatstringRepeated new password
Returns

Observable<any>

Examples
const excSecurity = ExcCoreModule.Services().ExcSecurityService;
excSecurity.changePassword('old','new','newRepeat').subscribe((success: boolean)=>{
    /* OnTokenRefreshed is triggered automatically on success */
    /* ExcCoreModule.showSuccess is triggered automatically on success */ 
    /* ExcCoreModule.showError is triggered automatically on non-success */ 
    /* ------------------------- */
    /* Do custom implementation here if needed.  */
});
isStateAvailable(routeName, router?)

This method is used by ExcStateSecurityProcessor

Parameters
NameTypeDescription
routeNamestringname of route path
router?any undefined(optional) angular router. If missing, it uses ExcCoreModule.Services().Router instead.
Returns

boolean

Examples
const excSecurity = ExcCoreModule.Services().ExcSecurityService;

excSecurity.isStateAvailable('testroute1');
excSecurity.isStateAvailable('testroute1', router);
isFeatured(featureToken)
Parameters
NameTypeDescription
featureTokenstringSecurity token to check against token list of security instance
Returns

boolean

Examples
const excSecurity = ExcCoreModule.Services().ExcSecurityService;

excSecurity.isFeatured('APPUSE');
2.0.5

1 year ago

2.0.3

2 years ago

2.0.4

2 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago