7 Security Authentication And Authorization

NET Centric Computing · Unit 7

Security, Authentication and Authorization

Exam-focused notes for Security, Authentication and Authorization (NET Centric Computing, BIT351): what the TU syllabus asks and how it has actually been tested, with 5 solved past questions from this unit.

Security, Authentication and Authorization in short

A web application holds private data, so it must know who a user is and what that user may do. It must also resist common attacks. This chapter covers login, access control, and the main web attacks.

Security, Authentication and Authorization: notes

Authentication purposes

Authentication is the process of proving who a user is, for example with a user name and password. Authorization comes after it and decides what that user may do.

Why we add authentication to an app:

  • To identify users and keep personal data private.
  • To protect pages and actions from anonymous visitors.
  • To give each user their own data, such as orders or profile.
  • To support authorization, since roles and rights need a known user.
  • To keep an audit trail of who did what.
  • To meet rules for privacy and security.
  • To limit misuse, such as spam or fake posts.

Common methods:

  • Cookie authentication: after login the server issues a cookie. Good for browser apps.
  • JWT bearer tokens: a signed token sent in the Authorization header. Good for APIs and mobile apps.
  • External login: Google, Microsoft or Facebook through OAuth and OpenID Connect.
  • Multi factor authentication: a password plus a code from a phone.

ASP.NET Core Identity is a built in system that manages users, hashed passwords, roles and login.

builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
    .AddCookie(o => o.LoginPath = "/Account/Login");

var app = builder.Build();
app.UseAuthentication();      // who are you?
app.UseAuthorization();       // what may you do?

Authentication middleware must run before authorization middleware.

Authorization roles and policies

Authorization checks if an authenticated user may use a resource.

A role is a named group of users, such as Admin or Manager. Role based authorization allows access to anyone in the role.

[Authorize(Roles = "Admin")]
public IActionResult DeleteUser(int id) { ... }

A policy is a named rule made of one or more requirements. It is more flexible than a role. It can check claims, age, time or any custom logic.

builder.Services.AddAuthorization(o =>
{
    o.AddPolicy("AdultsOnly", p => p.RequireAssertion(ctx =>
        ctx.User.HasClaim(c => c.Type == "Age" && int.Parse(c.Value) >= 18)));
});

[Authorize(Policy = "AdultsOnly")]
public IActionResult Movies() => View();

We need roles and policies so that:

  • Rules are defined in one place and reused.
  • Different users get different rights.
  • Code stays clean, because the rule is not repeated in each action.
  • Rules can change without rewriting each controller.

What this unit covers

  • Authentication purposes
  • Authorization roles and policies
  • Claims-based authorization
  • Securing controller and action methods
  • SQL injection attacks and prevention
  • Cross-site request forgery protection
  • Vulnerability detection and prevention
  • Form validation on client side

Vulnerability detection and prevention

2081 · 5 marks

How do you detect and prevent vulnerabilities in ASP.NET core application. [5]

Note: No specific reference notes were found for this topic. The following answer is based on standard ASP.NET Core security practices as taught in security/web development courses. --- - Detection: Code review for raw SQL queries; use static analysis tools (e.g., SonarQube) - Prevention: Use Ent...

Open this answer on its own page →

Authentication purposes

2081 · 5 marks

What are the purposes of adding authentications to apps? Explain. [5]

Show solved answer

Purposes of Adding Authentication to Apps

Definition

Authentication is the process of verifying the identity of a user, device, or system before granting access to an application or its resources. It answers the fundamental question: "Who are you?"


Purposes of Adding Authentication to Apps

1. Identity Verification

Authentication ensures that only legitimate and verified users can access the application. It confirms that the person attempting to log in is who they claim to be, preventing unauthorized individuals from gaining access.

2. Security and Protection of Data

Authentication protects sensitive user data and application resources from unauthorized access. Without authentication, any person could access private information such as personal details, financial records, or confidential business data.

3. Access Control and Authorization

Authentication works as a gateway for authorization. Once a user is authenticated, the system can determine what resources or features that user is permitted to access (e.g., admin vs. regular user). This enforces role-based access control.

4. Accountability and Audit Trails

When users are authenticated, all their actions can be tracked and logged. This creates an audit trail that helps in monitoring suspicious activities, debugging issues, and ensuring accountability for any changes made within the system.

5. Prevention of Unauthorized Modifications

Authentication prevents malicious users or attackers from modifying, deleting, or corrupting application data. Only authenticated users with proper permissions can perform critical operations.

6. Building User Trust

When an application implements proper authentication (e.g., login, OTP, two-factor authentication), it builds user confidence and trust that their data is safe and the platform is secure.

7. Compliance with Security Standards

Many industries require authentication as part of legal and regulatory compliance (e.g., GDPR, HIPAA). Adding authentication helps applications meet these standards and avoid legal penalties.


Summary Table

PurposeBenefit
Identity VerificationConfirms who the user is
Data SecurityProtects sensitive information
Access ControlLimits what users can do
AccountabilityTracks user actions
Trust BuildingIncreases user confidence
ComplianceMeets legal requirements

In short, authentication is a fundamental security mechanism that protects both the application and its users from unauthorized access, data breaches, and misuse.

Open this answer on its own page →

Authorization roles and policies

2080 · 5 marks

Why do we need to define roles, policies and claims? Explain. [5]

Note: The reference notes did not contain specific content on this topic. The following answer is based on standard ASP.NET Core / web application security concepts as taught in BSc CSIT curriculum. --- In modern web applications, it is not enough to simply verify who a user is (authentication). ...

Open this answer on its own page →

SQL injection attacks and prevention

2081.1 · 5 marks

Illustrate the concept of SQL injection with an example. [5]

SQL Injection is a web security vulnerability that allows an attacker to interfere with the queries that an application makes to its database. It occurs when untrusted user input is directly embedded into an SQL query without proper validation or sanitization, allowing the attacker to manipulate ...

Open this answer on its own page →

Claims-based authorization

0 · 5 marks

Define authorities, role, claims and policies. Discuss about cross-site request forgery with a case.[5]

Note: No specific curriculum notes were found for this topic. The answer below is based on standard ASP.NET Core / web security concepts as typically taught in BSc CSIT. --- An authority is a trusted entity (server or service) that is responsible for issuing, signing, and validating security toke...

Open this answer on its own page →