UserIdentityProvider.vala 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using Inversion;
  2. namespace Spry.Authentication {
  3. /**
  4. * UserIdentityProvider implements the IdentityProvider interface from the
  5. * Authorisation system, bridging Authentication.User to Authorisation.Identity.
  6. *
  7. * This allows the Authorisation system to retrieve Identity objects using
  8. * the UserService for storage operations.
  9. *
  10. * Usage:
  11. * Register this as the IdentityProvider implementation in your IoC container:
  12. * container.register<Authorisation.IdentityProvider, UserIdentityProvider>();
  13. *
  14. * Or use directly:
  15. * var provider = new UserIdentityProvider();
  16. * var identity = yield provider.get_identity_by_id("user-123");
  17. */
  18. public class UserIdentityProvider : GLib.Object, Authorisation.IdentityProvider {
  19. private UserService _user_service = inject<UserService>();
  20. /**
  21. * Creates a new UserIdentityProvider.
  22. * Dependencies are injected via inject<>() pattern.
  23. */
  24. public UserIdentityProvider() {
  25. // Dependencies injected via field initializers
  26. }
  27. /**
  28. * Retrieves an Identity by its unique ID.
  29. *
  30. * This method looks up a User by ID and returns it as an Identity.
  31. * Since User implements Identity, no conversion is needed.
  32. *
  33. * @param id The user's unique identifier
  34. * @return The User as Identity, or null if not found
  35. * @throws Error on retrieval failure
  36. */
  37. public async Authorisation.Identity? get_identity_by_id(string id) throws Error {
  38. var user = yield _user_service.get_user_async(id);
  39. return user; // User implements Identity
  40. }
  41. /**
  42. * Retrieves an Identity by its username.
  43. *
  44. * This method looks up a User by username and returns it as an Identity.
  45. * Since User implements Identity, no conversion is needed.
  46. *
  47. * @param username The username to look up
  48. * @return The User as Identity, or null if not found
  49. * @throws Error on retrieval failure
  50. */
  51. public async Authorisation.Identity? get_identity_by_username(string username) throws Error {
  52. var user = yield _user_service.get_user_by_username_async(username);
  53. return user; // User implements Identity
  54. }
  55. }
  56. }