Skip to content

Commit

Permalink
https://github.com/twocanoes/xcreds/issues/54
Browse files Browse the repository at this point in the history
  • Loading branch information
twocanoes committed Dec 17, 2023
1 parent f40cf39 commit 2707322
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 104 deletions.
58 changes: 41 additions & 17 deletions XCreds/MainController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,23 @@ class MainController: NSObject, NoMADUserSessionDelegate {

func NoMADUserInformation(user: NoMAD_ADAuth.ADUserRecord) {
TCSLogWithMark("AD user password expires: \(user.passwordExpire?.description ?? "unknown")")
}


var session:NoMADSession?
func run() -> Void {

TCSLogWithMark()
let defaultsPath = Bundle.main.path(forResource: "defaults", ofType: "plist")
let dateFormatter = DateFormatter()

if let defaultsPath = defaultsPath {

let defaultsDict = NSDictionary(contentsOfFile: defaultsPath)
TCSLogWithMark()
DefaultsOverride.standardOverride.register(defaults: defaultsDict as! [String : Any])
dateFormatter.locale = Locale(identifier: "en_US")
dateFormatter.dateStyle = .medium
dateFormatter.timeStyle = .short
if let passExpired = user.passwordExpire {
let dateString = dateFormatter.string(from: passExpired)
sharedMainMenu.passwordExpires="Password Expires: \(dateString)"
}
}

// make sure we have the local password, else prompt. we don't need to save it
// just make sure we prompt if not in the keychain. if the user cancels, then it will
// prompt when using OAuth.
// don't need to save it. just need to prompt and it gets saved
// in the keychain

var passwordCheckTimer:Timer?
var session:NoMADSession?
func checkPasswordExpire() {
let accountAndPassword = localAccountAndPassword()

let domainName = DefaultsOverride.standardOverride.string(forKey: PrefKeys.aDDomain.rawValue)
Expand Down Expand Up @@ -75,6 +70,35 @@ class MainController: NSObject, NoMADUserSessionDelegate {
}
}

}
func run() -> Void {

TCSLogWithMark()
let defaultsPath = Bundle.main.path(forResource: "defaults", ofType: "plist")

if let defaultsPath = defaultsPath {

let defaultsDict = NSDictionary(contentsOfFile: defaultsPath)
TCSLogWithMark()
DefaultsOverride.standardOverride.register(defaults: defaultsDict as! [String : Any])
}


// make sure we have the local password, else prompt. we don't need to save it
// just make sure we prompt if not in the keychain. if the user cancels, then it will
// prompt when using OAuth.
// don't need to save it. just need to prompt and it gets saved
// in the keychain

let domainName = Defa ultsOverride.standardOverride.string(forKey: PrefKeys.aDDomain.rawValue)

if let _ = domainName, passwordCheckTimer == nil {
checkPasswordExpire()
passwordCheckTimer = Timer.scheduledTimer(withTimeInterval: 3*60*60, repeats: true, block: { _ in
self.checkPasswordExpire()
})

}
NotificationCenter.default.addObserver(forName: Notification.Name("TCSTokensUpdated"), object: nil, queue: nil) { notification in


Expand Down
8 changes: 8 additions & 0 deletions XCreds/MainMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class MainMenu: NSObject, NSMenuDelegate {
var menuOpen = false // is the menu open?
var menuBuilt: Date? // last time menu was built
var updateStatus = "Starting Up..."
var passwordExpires = ""
var signedIn = false
var mainWindow:NSWindow!
var windowController: DesktopLoginWindowController!
Expand Down Expand Up @@ -77,6 +78,13 @@ class MainMenu: NSObject, NSMenuDelegate {
firstItemShown = true
}

if (self.passwordExpires != ""){
mainMenu.addItem(StatusUpdateMenuItem(title: self.passwordExpires))
mainMenu.addItem(NSMenuItem.separator())
firstItemShown = true

}

if let passwordChangeURLString = DefaultsOverride.standardOverride.value(forKey: PrefKeys.passwordChangeURL.rawValue) as? String, passwordChangeURLString.count>0 {
if firstItemShown == false {
mainMenu.addItem(NSMenuItem.separator())
Expand Down
12 changes: 6 additions & 6 deletions xCreds.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 6092;
CURRENT_PROJECT_VERSION = 6096;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = UXP6YEHSPW;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1339,7 +1339,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 6092;
CURRENT_PROJECT_VERSION = 6096;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = UXP6YEHSPW;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1459,7 +1459,7 @@
CODE_SIGN_ENTITLEMENTS = "XCreds Login Overlay/XCreds_Login_Overlay.entitlements";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 6092;
CURRENT_PROJECT_VERSION = 6096;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1496,7 +1496,7 @@
CODE_SIGN_ENTITLEMENTS = "XCreds Login Overlay/XCreds_Login_Overlay.entitlements";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 6092;
CURRENT_PROJECT_VERSION = 6096;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1646,7 +1646,7 @@
CODE_SIGN_ENTITLEMENTS = XCreds/xCreds.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 6092;
CURRENT_PROJECT_VERSION = 6096;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1687,7 +1687,7 @@
CODE_SIGN_ENTITLEMENTS = XCreds/xCreds.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 6092;
CURRENT_PROJECT_VERSION = 6096;
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 @@ -4,38 +4,6 @@
type = "1"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "7D5AC42C-5BE5-416F-9DA3-AAA49A5EA1CD"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "XCreds/ScheduleManager.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "37"
endingLineNumber = "37"
landmarkName = "startCredentialCheck()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "8D07860D-C3A0-436A-8FD4-D836B25B1C30"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "XCreds/MainController.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "74"
endingLineNumber = "74"
landmarkName = "run()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
Expand All @@ -46,57 +14,10 @@
filePath = "XCreds/MainController.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "187"
endingLineNumber = "187"
startingLineNumber = "211"
endingLineNumber = "211"
landmarkName = "localAccountAndPassword()"
landmarkType = "7">
<Locations>
<Location
uuid = "D0F121DF-3E75-4ECA-B411-E4F56EDAEDE7 - f41a46c23b4f68de"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "XCreds.MainController.localAccountAndPassword() -&gt; (Swift.Optional&lt;Swift.String&gt;, Swift.Optional&lt;Swift.String&gt;)"
moduleName = "XCreds"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/tperfitt/Documents/Projects/xcreds/XCreds/MainController.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "187"
endingLineNumber = "187"
offsetFromSymbolStart = "1308">
</Location>
<Location
uuid = "D0F121DF-3E75-4ECA-B411-E4F56EDAEDE7 - f41a46c23b4f68de"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "XCreds.MainController.localAccountAndPassword() -&gt; (Swift.Optional&lt;Swift.String&gt;, Swift.Optional&lt;Swift.String&gt;)"
moduleName = "XCreds"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/tperfitt/Documents/Projects/xcreds/XCreds/MainController.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "187"
endingLineNumber = "187"
offsetFromSymbolStart = "1368">
</Location>
<Location
uuid = "D0F121DF-3E75-4ECA-B411-E4F56EDAEDE7 - f41a46c23b4f68de"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "XCreds.MainController.localAccountAndPassword() -&gt; (Swift.Optional&lt;Swift.String&gt;, Swift.Optional&lt;Swift.String&gt;)"
moduleName = "XCreds"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/tperfitt/Documents/Projects/xcreds/XCreds/MainController.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "187"
endingLineNumber = "187"
offsetFromSymbolStart = "1788">
</Location>
</Locations>
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
Expand Down

0 comments on commit 2707322

Please sign in to comment.