193 lines
5.7 KiB
C#
193 lines
5.7 KiB
C#
using System.Linq;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Logging;
|
|
using xCommons.Attributes;
|
|
using xCommons.Configurations;
|
|
using xCommons.Providers;
|
|
using xIdentityHelper;
|
|
using xIdentityService.Controllers;
|
|
using xIdentityService.Interfaces;
|
|
|
|
namespace xAiApi.Controllers
|
|
{
|
|
/// <summary>
|
|
/// Test all Authentication Policies ...
|
|
/// </summary>
|
|
[RequireXPowered(false)]
|
|
public class TestIdentity : XIBaseController
|
|
{
|
|
public TestIdentity(
|
|
ILogger<TestIdentity> logger,
|
|
XAppConfiguration appConfiguration,
|
|
IXIdentityProvider identityProvider,
|
|
XValidationProvider validationProvider
|
|
) : base(
|
|
logger,
|
|
appConfiguration,
|
|
identityProvider,
|
|
validationProvider
|
|
)
|
|
{ }
|
|
|
|
//
|
|
#region Test Actions ...
|
|
/// <summary>
|
|
/// API Read Scope
|
|
/// </summary>
|
|
/// <returns>string message</returns>
|
|
[HttpGet("PassReadAccess")]
|
|
[Authorize(Policy = XPolicies.ReadAccess)]
|
|
public ActionResult<string> PassReadAccess()
|
|
{
|
|
return Ok("Read Access Passed ...");
|
|
}
|
|
|
|
/// <summary>
|
|
/// API Write Scope
|
|
/// </summary>
|
|
/// <returns>string message</returns>
|
|
[HttpGet("PassWriteAccess")]
|
|
[Authorize(Policy = XPolicies.WriteAccess)]
|
|
public ActionResult<string> PassWriteAccess()
|
|
{
|
|
return Ok("Write Access Passed ...");
|
|
}
|
|
|
|
/// <summary>
|
|
/// API Admin Scope
|
|
/// </summary>
|
|
/// <returns>string message</returns>
|
|
[HttpGet("PassAdminAccess")]
|
|
[Authorize(Policy = XPolicies.AdminAccess)]
|
|
public ActionResult<string> PassAdminAccess()
|
|
{
|
|
return Ok("Admin Access Passed ...");
|
|
}
|
|
|
|
/// <summary>
|
|
/// API Manage Scop
|
|
/// </summary>
|
|
/// <returns>string message</returns>
|
|
[HttpGet("PassManageAccess")]
|
|
[Authorize(Policy = XPolicies.ManageAccess)]
|
|
public ActionResult<string> PassManageAccess()
|
|
{
|
|
return Ok("Manage Access Passed ...");
|
|
}
|
|
|
|
/// <summary>
|
|
/// a simple Action which returns a List of Authenticated User Claims
|
|
/// </summary>
|
|
/// <returns>string message which represent current user's claims</returns>
|
|
[HttpGet("HiClaims")]
|
|
[Authorize(Policy = XPolicies.User)]
|
|
public ActionResult<string> HiClaims()
|
|
{
|
|
//
|
|
var result = new
|
|
{
|
|
name = User.Identity.Name,
|
|
claims = User.Claims.Select(c => new
|
|
{
|
|
c.Type,
|
|
c.Value
|
|
})
|
|
};
|
|
|
|
//
|
|
return Ok(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// a simple Hello User for Checking Authentication and Policy
|
|
/// </summary>
|
|
/// <returns>string message which contains authenticated user name</returns>
|
|
[HttpGet("HiUser")]
|
|
[Authorize(Policy = XPolicies.User)]
|
|
public ActionResult<string> HiUser()
|
|
{
|
|
//
|
|
var result = $"Hi User: {User.Identity.Name} ...";
|
|
|
|
//
|
|
return Ok(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// a simple Hello User for Checking Authentication and Policy
|
|
/// </summary>
|
|
/// <returns>string message which contains authenticated user name</returns>
|
|
[HttpGet("HiEnabledUser")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public ActionResult<string> HiEnabledUser()
|
|
{
|
|
//
|
|
var result = $"Hi User: {User.Identity.Name} is Enabled ...";
|
|
|
|
//
|
|
return Ok(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// a simple Hello User for Checking Authentication and Policy
|
|
/// </summary>
|
|
/// <returns>string message which contains authenticated user name</returns>
|
|
[HttpGet("HiAgent")]
|
|
[Authorize(Policy = XPolicies.Agent)]
|
|
public ActionResult<string> HiAgent()
|
|
{
|
|
//
|
|
var result = $"Hi Agent: {User.Identity.Name} ...";
|
|
|
|
//
|
|
return Ok(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// a simple Hello User for Checking Authentication and Policy
|
|
/// </summary>
|
|
/// <returns>string message which contains authenticated user name</returns>
|
|
[HttpGet("HiEnabledAgent")]
|
|
[Authorize(Policy = XPolicies.EnabledAgent)]
|
|
public ActionResult<string> HiEnabledAgent()
|
|
{
|
|
//
|
|
var result = $"Hi Agent: {User.Identity.Name} is Enabled ...";
|
|
|
|
//
|
|
return Ok(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// a simple Hello User for Checking Authentication and Policy
|
|
/// </summary>
|
|
/// <returns>string message which contains authenticated user name</returns>
|
|
[HttpGet("HiAdmin")]
|
|
[Authorize(Policy = XPolicies.Admin)]
|
|
public ActionResult<string> HiAdmin()
|
|
{
|
|
//
|
|
var result = $"Hi Admin: {User.Identity.Name} ...";
|
|
|
|
//
|
|
return Ok(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// a simple Hello User for Checking Authentication and Policy
|
|
/// </summary>
|
|
/// <returns>string message which contains authenticated user name</returns>
|
|
[HttpGet("HiEnabledAdmin")]
|
|
[Authorize(Policy = XPolicies.EnabledAdmin)]
|
|
public ActionResult<string> HiEnabledAdmin()
|
|
{
|
|
//
|
|
var result = $"Hi Admin: {User.Identity.Name} is Enabled ...";
|
|
|
|
//
|
|
return Ok(result);
|
|
}
|
|
#endregion
|
|
}
|
|
} |