You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.1 KiB
45 lines
1.1 KiB
4 years ago
|
import debug from 'debug';
|
||
4 years ago
|
import { IAuthentication } from '../../types/Authentication';
|
||
|
import {
|
||
4 years ago
|
IPacket,
|
||
4 years ago
|
IPacketHandler,
|
||
|
IPacketHandlerResult,
|
||
|
PacketResponseCode
|
||
|
} from '../../types/PacketHandler';
|
||
|
|
||
4 years ago
|
const log = debug('radius:user-pwd');
|
||
|
|
||
|
export class UserPasswordPacketHandler implements IPacketHandler {
|
||
4 years ago
|
constructor(private authentication: IAuthentication) {}
|
||
|
|
||
4 years ago
|
async handlePacket(packet: IPacket): Promise<IPacketHandlerResult> {
|
||
|
const username = packet.attributes['User-Name'];
|
||
|
const password = packet.attributes['User-Password'];
|
||
4 years ago
|
|
||
|
if (!username || !password) {
|
||
|
// params missing, this handler cannot continue...
|
||
|
return {};
|
||
|
}
|
||
|
|
||
4 years ago
|
log('username', username, username.toString());
|
||
|
log('token', password, password.toString());
|
||
|
|
||
4 years ago
|
const authenticated = await this.authentication.authenticate(
|
||
|
username.toString(),
|
||
|
password.toString()
|
||
|
);
|
||
|
if (authenticated) {
|
||
|
// success
|
||
|
return {
|
||
4 years ago
|
code: PacketResponseCode.AccessAccept,
|
||
|
attributes: [['User-Name', username]]
|
||
4 years ago
|
};
|
||
|
}
|
||
|
|
||
|
// Failed
|
||
|
return {
|
||
|
code: PacketResponseCode.AccessReject
|
||
|
};
|
||
|
}
|
||
|
}
|