Skip to content

Commit

Permalink
added username / password view to prompt in userspace
Browse files Browse the repository at this point in the history
  • Loading branch information
twocanoes committed Dec 28, 2023
1 parent 3f14dc2 commit a56020e
Show file tree
Hide file tree
Showing 12 changed files with 111 additions and 31 deletions.
6 changes: 5 additions & 1 deletion Shared/Tokens.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ struct Creds {
self.jsonDict=jsonDict

}
func hasTokens() -> Bool {

return (self.accessToken != nil) && (self.idToken != nil) && (self.refreshToken != nil)
}



}


Expand Down
6 changes: 3 additions & 3 deletions XCreds/DesktopLoginWindowController.xib
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<window title="XCreds Cloud Refresh" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" animationBehavior="default" id="KxT-zM-Vnn" customClass="LoginWindow" customModule="XCreds" customModuleProvider="target">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<window title="XCreds Password Update" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" animationBehavior="default" id="KxT-zM-Vnn" customClass="LoginWindow" customModule="XCreds" customModuleProvider="target">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="453" y="250" width="628" height="613"/>
<rect key="screenRect" x="0.0" y="0.0" width="1496" height="910"/>
Expand All @@ -37,7 +37,7 @@
<constraint firstAttribute="height" constant="50" id="JzN-tR-KJo"/>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="628" id="zPs-Yp-tRg"/>
</constraints>
<textFieldCell key="cell" alignment="center" title="Your local password needs to be synced with your cloud password. Please authenticate now." drawsBackground="YES" id="DzZ-yz-JFo">
<textFieldCell key="cell" alignment="center" title="Your local account password needs to be changed to match your online password. Please authenticate now." drawsBackground="YES" id="DzZ-yz-JFo">
<font key="font" metaFont="system" size="21"/>
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<color key="backgroundColor" white="0.0062473695290000001" alpha="0.57066289449999996" colorSpace="custom" customColorSpace="calibratedWhite"/>
Expand Down
1 change: 0 additions & 1 deletion XCreds/MainController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ class MainController: NSObject, NoMADUserSessionDelegate {
}
NotificationCenter.default.addObserver(forName: Notification.Name("TCSTokensUpdated"), object: nil, queue: nil) { notification in


DispatchQueue.main.async {
sharedMainMenu.windowController.window?.close()

Expand Down
5 changes: 4 additions & 1 deletion XCreds/MainMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ class MainMenu: NSObject, NSMenuDelegate {
var webViewController: WebViewController?
var prefsWindow: PreferencesWindowController?
var aboutWindowController: AboutWindowController?
var signInMenuItem:SignInMenuItem
override init() {
mainMenu = NSMenu()
signInMenuItem = SignInMenuItem()

super.init()
buildMenu()
windowController = DesktopLoginWindowController(windowNibName: "DesktopLoginWindowController")
Expand Down Expand Up @@ -96,7 +99,7 @@ class MainMenu: NSObject, NSMenuDelegate {

}

mainMenu.addItem(SignInMenuItem())
mainMenu.addItem(signInMenuItem)
mainMenu.addItem(CheckTokenMenuItem())
// mainMenu.addItem(PrefsMenuItem())
TCSLogWithMark()
Expand Down
54 changes: 37 additions & 17 deletions XCreds/MenuItems.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class ChangePasswordMenuItem: NSMenuItem {
}
class SignInMenuItem: NSMenuItem {

var signInViewController:SignInViewController?
override var title: String {
get {
if sharedMainMenu.signedIn==true {
Expand All @@ -88,34 +89,53 @@ class SignInMenuItem: NSMenuItem {
}

init() {
super.init(title: "", action: #selector(doAction), keyEquivalent: "")
super.init(title: "", action: #selector(showSigninWindow), keyEquivalent: "")
self.target = self
}

required init(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

@objc func doAction() {
@objc func showSigninWindow() {

ScheduleManager.shared.setNextCheckTime()
if DefaultsOverride.standardOverride.value(forKey: PrefKeys.discoveryURL.rawValue) != nil && DefaultsOverride.standardOverride.value(forKey: PrefKeys.clientID.rawValue) != nil {
// if (sharedMainMenu.webViewController==nil){
// windowController = DesktopLoginWindowController(windowNibName: "DesktopLoginWindowController")
//
//// sharedMainMenu.windowController=NSWindowController(windowNibName: "WebView")
//// sharedMainMenu.webViewController = sharedMainMenu.windowController
//
//
// }
//
print(sharedMainMenu.windowController.window)
let view = sharedMainMenu.windowController.webViewController.view
// sharedMainMenu.windowController.window!.contentView?.addSubview(view)
// sharedMainMenu.windowController.showWindow(self)
if DefaultsOverride.standardOverride.value(forKey: PrefKeys.shouldVerifyPasswordWithRopg.rawValue) != nil {

if let window = sharedMainMenu.windowController.window{
let bundle = Bundle.findBundleWithName(name: "XCreds")
if let bundle = bundle{
TCSLogWithMark("Creating signInViewController")
signInViewController = SignInViewController(nibName: "LocalUsersViewController", bundle:bundle)

guard let signInViewController = signInViewController else {
return
}

if let contentView = window.contentView {

signInViewController.view.wantsLayer=true
window.contentView?.addSubview(signInViewController.view)
var x = NSMidX(contentView.frame)
var y = NSMidY(contentView.frame)

x = x - signInViewController.view.frame.size.width/2
y = y - signInViewController.view.frame.size.height/2
let lowerLeftCorner = NSPoint(x: x, y: y)
signInViewController.localOnlyCheckBox.isHidden = true
signInViewController.localOnlyView.isHidden = true

signInViewController.view.setFrameOrigin(lowerLeftCorner)
}

window.makeKeyAndOrderFront(self)

}
}
}
else if DefaultsOverride.standardOverride.value(forKey: PrefKeys.discoveryURL.rawValue) != nil && DefaultsOverride.standardOverride.value(forKey: PrefKeys.clientID.rawValue) != nil {

sharedMainMenu.windowController.window!.makeKeyAndOrderFront(self)
// mainMenu.webView?.window!.forceToFrontAndFocus(nil)
sharedMainMenu.windowController.webViewController?.loadPage()
}
else {
Expand Down
2 changes: 1 addition & 1 deletion XCreds/ScheduleManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ScheduleManager:TokenManagerFeedbackDelegate {
}
DispatchQueue.main.async {

SignInMenuItem().doAction()
sharedMainMenu.signInMenuItem.showSigninWindow()
}

}
Expand Down
10 changes: 8 additions & 2 deletions XCreds/TokenManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,15 @@ extension TokenManager {
TCSLogWithMark("======== tokenResponse =========")

RunLoop.main.perform {

let xcredCreds = Creds(password: nil, tokens: tokens)
self.feedbackDelegate?.credentialsUpdated(xcredCreds)

if xcredCreds.hasTokens(){
self.feedbackDelegate?.credentialsUpdated(xcredCreds)
}
else {
self.feedbackDelegate?.tokenError("error gettings tokens")
}

}
}
}
Expand Down
8 changes: 8 additions & 0 deletions XCredsLoginPlugIn/LoginWindow/SignInWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ let checkADLog = OSLog(subsystem: "menu.nomad.login.ad", category: "CheckADMech"

@objc class SignInViewController: NSViewController, DSQueryable, TokenManagerFeedbackDelegate {

override var nibName: NSNib.Name{

return "LocalUsersViewController"
}

func tokenError(_ err:String){
TCSLogWithMark("Token error: \(err)")
authFail()
Expand All @@ -27,6 +32,9 @@ let checkADLog = OSLog(subsystem: "menu.nomad.login.ad", category: "CheckADMech"
TCSLogWithMark("error setting up hints")
authFail()
}
var credWithPass = credentials
credWithPass.password = self.passString
NotificationCenter.default.post(name: Notification.Name("TCSTokensUpdated"), object: self, userInfo:["credentials":credWithPass])

}

Expand Down
8 changes: 8 additions & 0 deletions xCreds.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
760418D72A1332660051411B /* DSQueryable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 760418D62A1332660051411B /* DSQueryable.swift */; };
760418D92A1332770051411B /* SystemInfoHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 760418D82A1332770051411B /* SystemInfoHelper.swift */; };
760418E02A133A370051411B /* DSQueryable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 760418D62A1332660051411B /* DSQueryable.swift */; };
761121B62B3D24FE005F7D02 /* SignInWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 760418CF2A1332210051411B /* SignInWindowController.swift */; };
761121B72B3D26EE005F7D02 /* SystemInfoHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 760418D82A1332770051411B /* SystemInfoHelper.swift */; };
761121B82B3D26F5005F7D02 /* LocalCheckAndMigrate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 760418DA2A13328C0051411B /* LocalCheckAndMigrate.swift */; };
761121B92B3D26FB005F7D02 /* DS+AD.swift in Sources */ = {isa = PBXBuildFile; fileRef = 760418D42A1332520051411B /* DS+AD.swift */; };
7611CEC0288B75140063A644 /* XCredsCreateUser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7611CEBF288B75140063A644 /* XCredsCreateUser.swift */; };
7611CEC2288B96760063A644 /* XCredsEnableFDE.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7611CEC1288B96760063A644 /* XCredsEnableFDE.swift */; };
7613FDF7289E114F00340CCD /* loadpage.html in Resources */ = {isa = PBXBuildFile; fileRef = 7613FDF6289E114F00340CCD /* loadpage.html */; };
Expand Down Expand Up @@ -1275,6 +1279,7 @@
089B22F22AFAED810006B6BC /* NetworkMonitor.swift in Sources */,
76EECD0228752C1F00483C66 /* LoginWindow.swift in Sources */,
76673CD529D3D5F500452848 /* LicenseChecker.swift in Sources */,
761121B82B3D26F5005F7D02 /* LocalCheckAndMigrate.swift in Sources */,
76E74DD22B39034B004C6429 /* SelectLocalAccountWindowController.swift in Sources */,
767116A7284AABC500CCD6FF /* NotifyManager.swift in Sources */,
76EE06B827FD1EB7009E0F3A /* PreferencesWindowController.swift in Sources */,
Expand All @@ -1296,13 +1301,16 @@
76D175772B23C62A00E64A62 /* UpdatePasswordWindowController.swift in Sources */,
7683973129A854EC003D9B9F /* NSImage+String.swift in Sources */,
76FDC5DA2B235A4F0035D61E /* StatusMenuWindowController.swift in Sources */,
761121B92B3D26FB005F7D02 /* DS+AD.swift in Sources */,
76CB9077287FBEEA00C70D0C /* Helper+URLDecode.swift in Sources */,
764D8129284BCAB100B3EE54 /* Window+Shake.swift in Sources */,
764D8126284BC1C300B3EE54 /* VerifyLocalPasswordWindowController.swift in Sources */,
76EE069E27FD1D00009E0F3A /* AppDelegate.swift in Sources */,
76D7ADFB284EB15100332EBC /* TCSUnifiedLogger.m in Sources */,
7657DEBC2B35055F003A23DB /* Logger.swift in Sources */,
7657DEB62B3504A6003A23DB /* UserRecord.swift in Sources */,
761121B62B3D24FE005F7D02 /* SignInWindowController.swift in Sources */,
761121B72B3D26EE005F7D02 /* SystemInfoHelper.swift in Sources */,
7657DEAF2B3503BF003A23DB /* SessionManager.swift in Sources */,
7681FEC52A4C8B9000F91CD1 /* AboutWindowController.swift in Sources */,
768633D92AFC4908004065E5 /* WifiManager.swift in Sources */,
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,50 @@
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "C93A3850-C5C7-48F5-BB4B-B7E1EA7DD48B"
uuid = "87152D0B-6359-4CFA-9647-434B8AA90995"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "XCredsLoginPlugIn/LoginWindow/SignInWindowController.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "30"
endingLineNumber = "30"
landmarkName = "credentialsUpdated(_:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "CAA91FDB-FC1F-4D14-BA87-A01D32198DC3"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "XCreds/MainController.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "109"
endingLineNumber = "109"
startingLineNumber = "124"
endingLineNumber = "124"
landmarkName = "run()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "57367307-40A1-447E-949E-F8208163F442"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "XCreds/PasswordUtils.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "211"
endingLineNumber = "211"
landmarkName = "changeLocalUserAndKeychainPassword(_:newPassword:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<key>auth_mech_fixup.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>8</integer>
<integer>7</integer>
</dict>
<key>authrights.xcscheme_^#shared#^_</key>
<dict>
Expand All @@ -42,7 +42,7 @@
<key>test.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>7</integer>
<integer>8</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
Expand Down

0 comments on commit a56020e

Please sign in to comment.