Skip to content

Commit 1e4791a

Browse files
committed
feat: enhance authentication process with agent state validation
- Added a check for the agent's current state during authentication, ensuring that only active agents can proceed with login attempts. - Implemented auditing for failed authentication attempts due to inactive agents, improving tracking and security measures.
1 parent d99636b commit 1e4791a

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

apps/api/src/core/auth/auth.service.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { ApiSession } from '~/_common/data/api-session';
1919
import { AuditsService } from '~/core/audits/audits.service';
2020
import { Types } from 'mongoose';
2121
import ipRangeCheck from 'ip-range-check';
22+
import { AgentState } from '~/core/agents/_enum/agent-state.enum';
2223

2324
@Injectable()
2425
export class AuthService extends AbstractService implements OnModuleInit {
@@ -88,6 +89,17 @@ export class AuthService extends AbstractService implements OnModuleInit {
8889
return null;
8990
}
9091

92+
if (user?.state?.current !== AgentState.ACTIVE) {
93+
await this.auditAuthenticationAttempt({
94+
username,
95+
ip,
96+
result: 'failed',
97+
reason: 'agent_not_active',
98+
agentId: user?._id,
99+
});
100+
return null;
101+
}
102+
91103
if (!this.isClientIpAllowed(user?.security?.allowedNetworks, ip)) {
92104
await this.auditAuthenticationAttempt({
93105
username,

0 commit comments

Comments
 (0)