-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
73 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Injectable, NestMiddleware } from '@nestjs/common'; | ||
import { Request } from 'express'; | ||
import ipRangeCheck from 'ip-range-check'; | ||
import { AppConfigService } from 'src/config/app-config.service'; | ||
import { AuthnStrategy, Role } from './constants'; | ||
import { UserProfile } from './dto/user-profile.dto'; | ||
@Injectable() | ||
export class SiteminderAuthnStrategyMiddleware implements NestMiddleware { | ||
constructor(private readonly appConfigService: AppConfigService) {} | ||
|
||
use(req: Request & { user: UserProfile }, res: any, next: () => void) { | ||
if (req.user) return next(); | ||
const currUser = | ||
req.get('SM_UNIVERSALID') || | ||
req.get('sm_user') || | ||
req.get('smgov_userdisplayname'); | ||
if (!currUser) { | ||
return next(); | ||
} | ||
const siteMinderReverseProxyIps = this.appConfigService.get( | ||
'siteMinderReverseProxyIps', | ||
); | ||
if (!siteMinderReverseProxyIps || siteMinderReverseProxyIps.length <= 0) { | ||
return next(); | ||
} | ||
// rely on express 'trust proxy' settings to obtain real ip | ||
const realIp = req.ip; | ||
const isFromSM = siteMinderReverseProxyIps.some(function (e: string) { | ||
return ipRangeCheck(realIp, e); | ||
}); | ||
if (isFromSM) { | ||
req.user = { | ||
securityId: currUser, | ||
authnStrategy: AuthnStrategy.SiteMinder, | ||
role: Role.AuthenticatedUser, | ||
}; | ||
} | ||
return next(); | ||
} | ||
} |