Not able to get current auditor id using keycloak in spring boot

i am using java 21, spring security 6 and keycloak version 22.0.4. Here i am trying to use audit aware to enable timestamps and records who created and updated. But the problem is i am getting currunt auditor id as null.

"Message": "Disability created successfully",
    "HttpStatus": "OK",
    "Data": {

type here


        "id": "388465a1-f06b-4d28-acbb-9110f8905ce3",
        "effectiveFrom": null,
        "deletedAt": null,
        "createdDate": "2024-05-14T16:49:17.655439",
        "createdBy": null,
        "lastModifiedDate": "2024-05-14T16:49:17.655439",
        "lastModifiedBy": null,
        "branchId": "395d5596-af9f-4acf-bcc5-89471098a24f",
        "name": "uyu problem",
        "notes": "Additional notes about the disability"
    }

response from the create request in postman

i am expecting loged in user id in this created by

i am using getCurrunt auditor method

 @Override
    public Optional<UUID> get Current Auditor() {
        Authentication authentication =
                SecurityContextHolder
                        .getContext()
                        .getAuthentication();

        if (authentication == null ||
                !authentication.isAuthenticated() ||
                authentication instanceof AnonymousAuthenticationToken) {
            System.out.println("Authentication is null or not authenticated");
            return Optional.empty();
        }

        Object principal = authentication.getPrincipal();

        if (principal instanceof User userPrincipal) {
            System.out.println("Auditing for user: " + userPrincipal.getUsername());
            return Optional.ofNullable(userPrincipal.getId());
        } else {
            System.out.println("Principal is not a User entity: " + principal);
            return Optional.empty();
        }

i have tried some ways to figure it out but can not able to get the desired results

i have addded a bean in the security config file

`@Bean
    public AuditorAware<UUID> auditorAware() {
        return new ApplicationAuditAware();
    }

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "UUID")
    @Column(name = "id", updatable = false, nullable = false)
    private UUID id;

    /** Date and time when the record was effective from. */
    @Column(name = "effective_from")
    private Date effectiveFrom;

    /** Deleted At timestamp when the record was deleted. Otherwise null */
    @Column(
            name = "deleted_at",
            insertable = false
    )
    private LocalDateTime deletedAt;

    /**
     * The timestamp when the entity was created.
     */
    @CreatedDate
    @Column(
            name = "created_date",
            nullable = false,
            updatable = false
    )
    private LocalDateTime createdDate;

    /**
     * The timestamp when the entity was last updated.
     */
    @LastModifiedDate
    @Column(
            name = "last_modified_date",
            insertable = false
    )
    private LocalDateTime lastModifiedDate;

    /**
     * The user who created the entity.
     */
    @CreatedBy
    @Column(
            name = "created_by",
           // nullable = false,
            updatable = false
    )
    private UUID createdBy;

    /**
     * The user who last updated the entity.
     */
    @LastModifiedBy
    @Column(
            name = "last_modified_by",
            insertable = false
    )
    private UUID lastModifiedBy;

}`

i am still getting the same output which is not desired output

New contributor

Priyanshu Thakur is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật