Browse Source

Merge branch 'rel-4.3' of https://github.com/abpframework/abp into fix/route-reload

pull/8709/head
mehmet-erim 6 years ago
parent
commit
8c467083c5
  1. 15
      docs/en/Authorization.md
  2. 7
      modules/setting-management/src/Volo.Abp.SettingManagement.Blazor/Menus/SettingManagementMenuContributor.cs
  3. 13
      modules/setting-management/src/Volo.Abp.SettingManagement.Web/Navigation/SettingManagementMainMenuContributor.cs
  4. 1
      modules/setting-management/src/Volo.Abp.SettingManagement.Web/Pages/SettingManagement/Index.cshtml.cs
  5. 31
      npm/ng-packs/packages/core/src/lib/strategies/auth-flow.strategy.ts
  6. 4
      npm/ng-packs/packages/core/src/lib/utils/initial-utils.ts
  7. 1
      npm/ng-packs/tsconfig.json
  8. 19
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.Server/MyProjectNameBlazorModule.cs

15
docs/en/Authorization.md

@ -405,17 +405,14 @@ public class SocialSecurityNumberClaimsPrincipalContributor : IAbpClaimsPrincipa
public async Task ContributeAsync(AbpClaimsPrincipalContributorContext context)
{
var identity = context.ClaimsPrincipal.Identities.FirstOrDefault();
if (identity != null)
var userId = identity?.FindUserId();
if (userId.HasValue)
{
var currentUser = context.ServiceProvider.GetRequiredService<ICurrentUser>();
if (currentUser.Id.HasValue)
var userService = context.ServiceProvider.GetRequiredService<IUserService>(); //Your custom service
var socialSecurityNumber = await userService.GetSocialSecurityNumberAsync(userId.Value);
if (socialSecurityNumber != null)
{
var userService = context.ServiceProvider.GetRequiredService<IUserService>(); //Your custom service
var socialSecurityNumber = await userService.GetSocialSecurityNumberAsync(currentUser.Id.Value);
if (userService != null)
{
identity.AddOrReplace(new Claim("SocialSecurityNumber", userService));
}
identity.AddOrReplace(new Claim("SocialSecurityNumber", socialSecurityNumber));
}
}
}

7
modules/setting-management/src/Volo.Abp.SettingManagement.Blazor/Menus/SettingManagementMenuContributor.cs

@ -21,8 +21,7 @@ namespace Volo.Abp.SettingManagement.Blazor.Menus
{
var settingManagementPageOptions = context.ServiceProvider.GetRequiredService<IOptions<SettingManagementComponentOptions>>().Value;
var settingPageCreationContext = new SettingComponentCreationContext(context.ServiceProvider);
if (
!settingManagementPageOptions.Contributors.Any() ||
if (!settingManagementPageOptions.Contributors.Any() ||
!(await CheckAnyOfPagePermissionsGranted(settingManagementPageOptions, settingPageCreationContext))
)
{
@ -31,6 +30,10 @@ namespace Volo.Abp.SettingManagement.Blazor.Menus
var l = context.GetLocalizer<AbpSettingManagementResource>();
/* This may happen if MVC UI is being used in the same application.
* In this case, we are removing the MVC setting management UI. */
context.Menu.GetAdministration().TryRemoveMenuItem(SettingManagementMenus.GroupName);
context.Menu
.GetAdministration()
.AddItem(

13
modules/setting-management/src/Volo.Abp.SettingManagement.Web/Navigation/SettingManagementMainMenuContributor.cs

@ -19,12 +19,17 @@ namespace Volo.Abp.SettingManagement.Web.Navigation
return;
}
if (context.Menu.FindMenuItem(SettingManagementMenuNames.GroupName) != null)
{
/* This may happen if blazor server UI is being used in the same application.
* In this case, we don't add the MVC setting management UI. */
return;
}
var settingManagementPageOptions = context.ServiceProvider.GetRequiredService<IOptions<SettingManagementPageOptions>>().Value;
var settingPageCreationContext = new SettingPageCreationContext(context.ServiceProvider);
if (
!settingManagementPageOptions.Contributors.Any() ||
!(await CheckAnyOfPagePermissionsGranted(settingManagementPageOptions, settingPageCreationContext))
)
if (!settingManagementPageOptions.Contributors.Any() ||
!(await CheckAnyOfPagePermissionsGranted(settingManagementPageOptions, settingPageCreationContext)))
{
return;
}

1
modules/setting-management/src/Volo.Abp.SettingManagement.Web/Pages/SettingManagement/Index.cshtml.cs

@ -1,4 +1,3 @@
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using Microsoft.AspNetCore.Mvc;

31
npm/ng-packs/packages/core/src/lib/strategies/auth-flow.strategy.ts

@ -2,14 +2,21 @@ import { HttpHeaders } from '@angular/common/http';
import { Injector } from '@angular/core';
import { Params, Router } from '@angular/router';
import { Store } from '@ngxs/store';
import { AuthConfig, OAuthInfoEvent, OAuthService, OAuthStorage } from 'angular-oauth2-oidc';
import {
AuthConfig,
OAuthErrorEvent,
OAuthInfoEvent,
OAuthService,
OAuthStorage,
} from 'angular-oauth2-oidc';
import { from, Observable, of } from 'rxjs';
import { filter, switchMap, tap } from 'rxjs/operators';
import { RestOccurError } from '../actions/rest.actions';
import { AbpApplicationConfigurationService } from '../proxy/volo/abp/asp-net-core/mvc/application-configurations/abp-application-configuration.service';
import { SessionStateService } from '../services/session-state.service';
import { ConfigStateService } from '../services/config-state.service';
import { EnvironmentService } from '../services/environment.service';
import { SessionStateService } from '../services/session-state.service';
import { noop } from '../utils/common-utils';
export interface LoginParams {
username: string;
@ -28,6 +35,8 @@ export abstract class AuthFlowStrategy {
protected configState: ConfigStateService;
protected oAuthService: OAuthService;
protected oAuthConfig: AuthConfig;
protected appConfigService: AbpApplicationConfigurationService;
abstract checkIfInternalAuth(): boolean;
abstract navigateToLogin(queryParams?: Params): void;
abstract logout(): Observable<any>;
@ -40,7 +49,10 @@ export abstract class AuthFlowStrategy {
this.environment = injector.get(EnvironmentService);
this.configState = injector.get(ConfigStateService);
this.oAuthService = injector.get(OAuthService);
this.appConfigService = injector.get(AbpApplicationConfigurationService);
this.oAuthConfig = this.environment.getEnvironment().oAuthConfig;
this.listenToOauthErrors();
}
async init(): Promise<any> {
@ -66,6 +78,18 @@ export abstract class AuthFlowStrategy {
protected refreshToken() {
return this.oAuthService.refreshToken().catch(() => clearOAuthStorage());
}
protected listenToOauthErrors() {
this.oAuthService.events
.pipe(
filter(event => event instanceof OAuthErrorEvent),
tap(() => clearOAuthStorage()),
switchMap(() => this.appConfigService.get()),
)
.subscribe(res => {
this.configState.setState(res);
});
}
}
export class AuthCodeFlowStrategy extends AuthFlowStrategy {
@ -74,7 +98,7 @@ export class AuthCodeFlowStrategy extends AuthFlowStrategy {
async init() {
return super
.init()
.then(() => this.oAuthService.tryLogin())
.then(() => this.oAuthService.tryLogin().catch(noop))
.then(() => this.oAuthService.setupAutomaticSilentRefresh({}, 'access_token'));
}
@ -101,7 +125,6 @@ export class AuthPasswordFlowStrategy extends AuthFlowStrategy {
readonly isInternalAuth = true;
private cookieKey = 'rememberMe';
private storageKey = 'passwordFlow';
private appConfigService = this.injector.get(AbpApplicationConfigurationService);
private listenToTokenExpiration() {
this.oAuthService.events

4
npm/ng-packs/packages/core/src/lib/utils/initial-utils.ts

@ -41,9 +41,9 @@ export function getInitialData(injector: Injector) {
injector.get(SessionStateService).setTenant(currentTenant);
}),
catchError(error => {
const appInitErrorHandlers = injector.get(APP_INIT_ERROR_HANDLERS);
const appInitErrorHandlers = injector.get(APP_INIT_ERROR_HANDLERS, null);
if (appInitErrorHandlers && appInitErrorHandlers.length) {
appInitErrorHandlers.forEach(fn => fn(error));
appInitErrorHandlers.forEach(func => func(error));
}
return throwError(error);

1
npm/ng-packs/tsconfig.json

@ -7,6 +7,7 @@
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"module": "esnext",
"moduleResolution": "node",
"importHelpers": true,

19
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.Server/MyProjectNameBlazorModule.cs

@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.OpenApi.Models;
using MyCompanyName.MyProjectName.Blazor.Server.Menus;
using MyCompanyName.MyProjectName.EntityFrameworkCore;
using MyCompanyName.MyProjectName.Localization;
@ -86,6 +87,7 @@ namespace MyCompanyName.MyProjectName.Blazor.Server
ConfigureAutoMapper();
ConfigureVirtualFileSystem(hostingEnvironment);
ConfigureLocalizationServices();
ConfigureSwaggerServices(context.Services);
ConfigureAutoApiControllers();
ConfigureHttpClient(context);
ConfigureBlazorise(context);
@ -186,6 +188,18 @@ namespace MyCompanyName.MyProjectName.Blazor.Server
});
}
private void ConfigureSwaggerServices(IServiceCollection services)
{
services.AddSwaggerGen(
options =>
{
options.SwaggerDoc("v1", new OpenApiInfo { Title = "MyProjectName API", Version = "v1" });
options.DocInclusionPredicate((docName, description) => true);
options.CustomSchemaIds(type => type.FullName);
}
);
}
private static void ConfigureHttpClient(ServiceConfigurationContext context)
{
context.Services.AddTransient(sp => new HttpClient
@ -265,6 +279,11 @@ namespace MyCompanyName.MyProjectName.Blazor.Server
app.UseUnitOfWork();
app.UseIdentityServer();
app.UseAuthorization();
app.UseSwagger();
app.UseAbpSwaggerUI(options =>
{
options.SwaggerEndpoint("/swagger/v1/swagger.json", "MyProjectName API");
});
app.UseConfiguredEndpoints();
}
}

Loading…
Cancel
Save