exc-security-v2

ExcSecurityModule

Usage no npm install needed!

<script type="module">
  import excSecurityV2 from 'https://cdn.skypack.dev/exc-security-v2';
</script>

README

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

Name Emitted params Description
OnReady - Triggered after initial successful authentication
OnLoggedOut - Triggered after logout
OnRefresh includeToken?: boolean Triggers 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

Name Type Description
LoggedIn boolean Get flag if user is logged in or not.
IsInitializing boolean Get flag if ExcSecurityService is already initializing
Credentials ExcCredentials Get credential instance for login mask
UserLogin string Get user login of logged in user
UserName string Get name of logged in user

Methods

Login(credentials?)
Parameters
Name Type Description
credentials IExcCredentials | 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
Name Type Description
Returns

void

Examples
const excSecurity = ExcCoreModule.Services().ExcSecurityService;
excSecurity.Logout();
changePassword(pwdOld, pwdNew, pwdNewRepeat)
Parameters
Name Type Description
pwdOld string Old password
pwdNew string New password
pwdNewRepeat string Repeated 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
Name Type Description
routeName string name 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
Name Type Description
featureToken string Security token to check against token list of security instance
Returns

boolean

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

excSecurity.isFeatured('APPUSE');