Skip to content

Commit

Permalink
added remounting and refresh kerb ticket after network change
Browse files Browse the repository at this point in the history
  • Loading branch information
twocanoes committed Feb 23, 2024
1 parent 88c96df commit 8db9ec6
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 25 deletions.
2 changes: 1 addition & 1 deletion XCreds/KeychainUtil.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class KeychainUtil {

return (account,password as? String ?? "")
} else {
TCSLogErrorWithMark("Password not found in keychain")
TCSLogErrorWithMark("\(serviceName) not found in keychain")
throw KeychainError.noStoredPassword
}
}
Expand Down
28 changes: 24 additions & 4 deletions XCreds/MainController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,18 @@ class MainController: NSObject, UpdateCredentialsFeedbackProtocol {
}
func setup() {


NSWorkspace.shared.notificationCenter.addObserver(forName: NSWorkspace.didUnmountNotification, object: nil, queue: nil) { notification in
self.scheduleManager.checkKerberosTicket()
self.checkAndMountShares()

}

NotificationCenter.default.addObserver(forName: .connectivityStatus, object: nil, queue: nil) { notification in
self.checkAndMountShares()
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now()+10) {
self.scheduleManager.checkKerberosTicket()
self.checkAndMountShares()
}
}
self.checkAndMountShares()
TCSLogWithMark()
Expand Down Expand Up @@ -320,7 +330,7 @@ class MainController: NSObject, UpdateCredentialsFeedbackProtocol {
}

//delay startup to give network time to settle.
Timer.scheduledTimer(withTimeInterval: 1, repeats: false) { timer in
Timer.scheduledTimer(withTimeInterval: 15, repeats: false) { timer in
self.scheduleManager.startCredentialCheck()
}

Expand All @@ -341,13 +351,23 @@ class MainController: NSObject, UpdateCredentialsFeedbackProtocol {

credentialStatus="Valid kerberos tickets"
}
func kerberosTicketCheckFailed() {
func kerberosTicketCheckFailed(_ error: NoMADSessionError) {

TCSLogWithMark()
hasKerberosTicket=false
(NSApp.delegate as? AppDelegate)?.updateStatusMenuIcon(showDot:false)

credentialStatus="Kerberos Tickets Failed"
showSignInWindow(forceLoginWindowType: .usernamePassword)
switch error{

case .OffDomain:
TCSLogWithMark("Off domain so not prompting")


default:
showSignInWindow(forceLoginWindowType: .usernamePassword)

}
}
func adUserUpdated(_ adUser: ADUserRecord) {

Expand Down
2 changes: 1 addition & 1 deletion XCreds/PreferencesWindow.xib
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<windowStyleMask key="styleMask" titled="YES" closable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="560" y="551" width="494" height="173"/>
<rect key="screenRect" x="0.0" y="0.0" width="1496" height="910"/>
<rect key="screenRect" x="0.0" y="0.0" width="3440" height="1415"/>
<view key="contentView" wantsLayer="YES" id="ZbF-tC-vpZ">
<rect key="frame" x="0.0" y="0.0" width="494" height="173"/>
<autoresizingMask key="autoresizingMask"/>
Expand Down
25 changes: 14 additions & 11 deletions XCreds/ScheduleManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,7 @@ class ScheduleManager:TokenManagerFeedbackDelegate, NoMADUserSessionDelegate {

}
}

func checkToken() {
TCSLogWithMark("checking token")
if nextCheckTime>Date() {
TCSLogWithMark("Token will be checked at \(nextCheckTime)")

NotificationCenter.default.post(name: NSNotification.Name("CheckTokenStatus"), object: self, userInfo:["NextCheckTime":nextCheckTime])
return
}
setNextCheckTime()
func checkKerberosTicket(){
let domainName = DefaultsOverride.standardOverride.string(forKey: PrefKeys.aDDomain.rawValue)


Expand All @@ -142,6 +133,18 @@ class ScheduleManager:TokenManagerFeedbackDelegate, NoMADUserSessionDelegate {
TCSLogWithMark("not checking for kerberos ticket")
}

}
func checkToken() {
TCSLogWithMark("checking token")
if nextCheckTime>Date() {
TCSLogWithMark("Token will be checked at \(nextCheckTime)")

NotificationCenter.default.post(name: NSNotification.Name("CheckTokenStatus"), object: self, userInfo:["NextCheckTime":nextCheckTime])
return
}
setNextCheckTime()
checkKerberosTicket()

TCSLogWithMark("checking for oidc tokens if we have a refresh token and oidc is configured.")
tokenManager.feedbackDelegate=self

Expand Down Expand Up @@ -169,7 +172,7 @@ class ScheduleManager:TokenManagerFeedbackDelegate, NoMADUserSessionDelegate {

func NoMADAuthenticationFailed(error: NoMADSessionError, description: String) {
TCSLogErrorWithMark("NoMADAuthenticationFailed:\(description)")
feedbackDelegate?.kerberosTicketCheckFailed()
feedbackDelegate?.kerberosTicketCheckFailed(error)
}

func NoMADUserInformation(user: ADUserRecord) {
Expand Down
4 changes: 2 additions & 2 deletions XCredsLoginPlugIn/LoginWindow/SignInWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protocol UpdateCredentialsFeedbackProtocol {
func credentialsUpdated(_ credentials:Creds)
func credentialsCheckFailed()
func kerberosTicketUpdated()
func kerberosTicketCheckFailed()
func kerberosTicketCheckFailed(_ error:NoMADSessionError)
func adUserUpdated(_ adUser:ADUserRecord)

}
Expand Down Expand Up @@ -737,7 +737,7 @@ protocol UpdateCredentialsFeedbackProtocol {
extension SignInViewController: NoMADUserSessionDelegate {

func NoMADAuthenticationFailed(error: NoMADSessionError, description: String) {
updateCredentialsFeedbackDelegate?.kerberosTicketCheckFailed()
updateCredentialsFeedbackDelegate?.kerberosTicketCheckFailed(error)

TCSLogWithMark("NoMADAuthenticationFailed: \(description)")
// alertTextField.isHidden=false
Expand Down
12 changes: 6 additions & 6 deletions xCreds.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1440,7 +1440,7 @@
buildSettings = {
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 6346;
CURRENT_PROJECT_VERSION = 6356;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = UXP6YEHSPW;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1477,7 +1477,7 @@
buildSettings = {
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 6346;
CURRENT_PROJECT_VERSION = 6356;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = UXP6YEHSPW;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1598,7 +1598,7 @@
CODE_SIGN_ENTITLEMENTS = "XCreds Login Overlay/XCreds_Login_Overlay.entitlements";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 6346;
CURRENT_PROJECT_VERSION = 6356;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1635,7 +1635,7 @@
CODE_SIGN_ENTITLEMENTS = "XCreds Login Overlay/XCreds_Login_Overlay.entitlements";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 6346;
CURRENT_PROJECT_VERSION = 6356;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1785,7 +1785,7 @@
CODE_SIGN_ENTITLEMENTS = XCreds/xCreds.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 6346;
CURRENT_PROJECT_VERSION = 6356;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1827,7 +1827,7 @@
CODE_SIGN_ENTITLEMENTS = XCreds/xCreds.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 6346;
CURRENT_PROJECT_VERSION = 6356;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,22 @@
uuid = "94C20054-8AB3-42DB-93A7-A3026166D6FC"
type = "1"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "A4CD8689-7FCA-431A-A3A0-2C05F786EF35"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "ShareMounter.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "382"
endingLineNumber = "382"
landmarkName = "mountShares()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>

0 comments on commit 8db9ec6

Please sign in to comment.