Security

Metalama lets you add cross-cutting security concerns like authorization, auditing, and encryption to your applications without writing boilerplate code.

Authorization

Aspects can enforce role-based or permission-based access control without permission checks written by hand. They add the checks to methods, properties, fields and parameters, and a run-time policy decides whether the current user has the required permission on the object being accessed. Business objects inherit default permissions, and the configuration is hierarchical, so a namespace or a project can set the rules for everything below it.

See the commented example: Enforcing authorization with aspects. It is a proof of concept, with an abstract authorization layer and a role-based model that you can replace with groups, access-control lists or attribute-based rules.

Audit

With Metalama, you can implement auditing by creating an aspect that logs method calls, parameter values, and execution results. This aspect can be applied to critical methods to ensure that all actions are recorded for compliance and debugging purposes.

To audit the calls to sensitive APIs that you don’t own, such as File.Delete or a payment SDK, use interceptors: one registration covers every call in the project, including the calls written later. See the commented example: Auditing calls to sensitive APIs.

Transparent encryption

Metalama can help implement transparent encryption by weaving aspects that encrypt and decrypt data at specific points in your code: for example, encrypting a field before it is persisted and decrypting it on read. The encryption logic stays out of your business code.