HabrJuly 22, 2026🇷🇺Translated from Russian

Spring Security Tutorial Details Refresh Token Implementation to Complement JWT Authentication

A comprehensive tutorial on Spring Security demonstrates how to extend JWT authentication with refresh tokens to balance security and usability. The guide begins by explaining the limitations of short-lived access tokens, which typically expire within 15 minutes to one hour, and introduces refresh tokens that can last from one week to one month.

The article details the creation of a RefreshToken entity annotated with JPA mappings, including fields for the token string, associated user, expiration instant, and revocation flag. It also provides the corresponding RefreshTokenRepository interface with methods to find tokens and delete all tokens for a given user.

In the service layer, RefreshTokenService implements token creation by removing existing tokens for the user, generating a new UUID-based token, setting an expiration based on a configurable property, and persisting it. The verify method checks for existence, expiration, and revocation status, throwing a custom RefreshTokenException when necessary, while the revoke method marks tokens as revoked.

Security considerations are thoroughly covered, highlighting benefits such as reduced exposure time for access tokens, automatic session renewal, centralized session control, and minimized password transmission. Risks discussed include potential database compromise mitigated by hashing with SHA-256 or HMAC-SHA256, increased database load due to statefulness, implementation complexity involving token rotation, and client-side storage vulnerabilities addressed by using HttpOnly cookies instead of localStorage.

The tutorial updates DTOs to include AuthResponse and RefreshRequest, modifies AuthService to integrate refresh token creation during registration and login, and enhances AuthController with endpoints for refresh and logout. A helper method sets secure, HTTP-only cookies with appropriate path and max-age settings.

Finally, adjustments to SecurityConfig are shown to permit public access to authentication endpoints and profile retrieval while restricting administrative routes, ensuring a complete implementation of refresh token mechanics alongside JWT handling.

Related articles

HabrOther

Amazon Confirms Irrecoverable Data Loss in UAE and Bahrain Data Centers After Drone Attacks

Amazon Web Services has officially confirmed that data stored in specific availability zones within its Middle East regions was permanently destroyed following physical attacks on data centers in the UAE and Bahrain. The incidents began on March 1 and continued through April and July, damaging infrastructure tied to AI development projects. In the UAE region mec1, only zone mec1-az2 was completely destroyed with no external backups, while mec1-az3 suffered severe damage and mec1-az1 remained operational but overloaded. All three zones in the Bahrain region me-south-1 were rendered inoperable. AWS had spent six months attempting recovery before issuing the final statement on September 15, 2026, and has advised customers to migrate workloads to unaffected regions. The event highlights growing risks to data from physical-world attacks beyond traditional network threats.

HabrOther

Bots Overload OT Commerce Store on OT Box, Spike Paid OTAPI Calls Mistaken for DDoS Attack

An online store running OT Commerce experienced CPU loads reaching 98-100% and a 6-7x increase in paid OTAPI calls over three days due to automated bot traffic rather than a traditional DDoS. The site owner had already deployed a paid anti-bot module on the VPS, yet behavioral bots continued to bypass protections and force expensive calls to the external OTAPI platform for product data from Taobao, Tmall, 1688 and other marketplaces. Traffic analysis after switching to the CRONARMOR WAF revealed that 41.9% of page requests were automated, with 99.3% of early-stage automation blocked before reaching the origin server. Only 0.5% were behavioral bots visible in analytics, while legitimate search crawlers accounted for 27,190 requests that were explicitly allowed. The WAF approach stopped requests at the reverse proxy layer, preventing PHP execution, database queries and OTAPI billing events on the origin. Post-deployment CPU dropped to single digits for most of the day, eliminating both performance issues and the anomalous rise in paid API usage.

SecuritylabOther

Teenage Smartphone Addiction: Causes, Consequences, and Treatment Approaches

Smartphone use has become an integral part of adolescent life, but problematic usage patterns rather than device ownership itself are the focus of concern. Medical experts avoid the term smartphone addiction and instead address issues like disrupted self-control, social media overuse, and gaming disorder that interfere with sleep, studies, relationships, and mental health. Data from Pew Research indicates nearly 50% of U.S. teens aged 13-17 are online almost constantly, while CDC findings link four or more hours of daily screen time to elevated anxiety and depression symptoms. Family digital habits strongly influence teen behavior, and rigid bans often fail without addressing underlying issues such as boredom, anxiety, or social isolation. Parents are advised to track specific disruptions over a week and consider professional help when signs of depression, bullying, or self-harm appear alongside device overuse.

HabrOther

VK WorkSpace Federation Enables Secure Multi-Organization On-Premise Messaging Without Infrastructure Merge

VK Tech has released federation capabilities for its VK WorkSpace corporate messenger that connect independent On-Premise installations while preserving each organization's full control over data, administration, and security policies. The feature, first piloted in November 2025 and expanded in the July 2026 26.2 release, supports multi-party chats across more than two separate environments. Federation relies on mutual trust establishment and per-user access grants rather than full directory replication or proxy access to a single host instance. Each participating organization maintains local copies of messages, files, and chat metadata, allowing continued access even if a partner installation becomes unavailable. The architecture deliberately avoids both centralized hosting and open protocols such as Matrix to keep changes to the existing messenger core minimal. Administrators retain independent levers to create or revoke trusts and to limit which employees may communicate externally.