Commit b466cdda authored by Josh Wisenbaker's avatar Josh Wisenbaker

Created ContextAndHintHandling protocol and adopted it in SignIn.swift. This...

Created ContextAndHintHandling protocol and adopted it in SignIn.swift. This way we can simply adopt the protocol to have a set of consistent methods to handle the context and hint settings.
parent 2bbdf04d
//
// ContextAndHintHandling.swift
// NoMADLoginAD
//
// Created by Josh Wisenbaker on 12/18/17.
// Copyright © 2017 NoMAD. All rights reserved.
//
enum HintType: String {
case noMADUser
case noMADPass
case noMADFirst
case noMADLast
case noMADFull
case uid
case gid
case kerberos_principal
}
protocol ContextAndHintHandling {
var mech: MechanismRecord? {get set}
func setContext(type: String, value: String)
func setHint(type: HintType, hint: String)
func getContext(type: String)
func getHint(type: HintType)
}
extension ContextAndHintHandling {
/// Set a NoMAD Login Authorization mechanism hint.
///
/// - Parameters:
/// - type: A value from `HintType` representing the NoMad Login value to set.
/// - hint: A `String` of the hint value to set.
func setHint(type: HintType, hint: String) {
let data = NSKeyedArchiver.archivedData(withRootObject: hint)
var value = AuthorizationValue(length: data.count, data: UnsafeMutableRawPointer(mutating: (data as NSData).bytes.bindMemory(to: Void.self, capacity: data.count)))
let err = (mech?.fPlugin.pointee.fCallbacks.pointee.SetHintValue((mech?.fEngine)!, type.rawValue, &value))!
guard err == errSecSuccess else {
NSLog("NoMAD Login Set hint failed with: %@", err)
return
}
}
/// Set one of the known `AuthorizationTags` values to be used during mechanism evaluation.
///
/// - Parameters:
/// - type: A `String` constant from AuthorizationTags.h representing the value to set.
/// - value: A `String` value of the context value to set.
func setContext(type: String, value: String) {
let tempdata = value + "\0"
let data = tempdata.data(using: .utf8)
var value = AuthorizationValue(length: (data?.count)!, data: UnsafeMutableRawPointer(mutating: (data! as NSData).bytes.bindMemory(to: Void.self, capacity: (data?.count)!)))
let err = (mech?.fPlugin.pointee.fCallbacks.pointee.SetContextValue((mech?.fEngine)!, type, .extractable, &value))!
guard err == errSecSuccess else {
NSLog("NoMAD Login Set context value failed with: %@", err)
return
}
}
}
......@@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
9C6027461FE8224000B99B51 /* ContextAndHintHandling.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C6027451FE8224000B99B51 /* ContextAndHintHandling.swift */; };
9C9740191FC5DD6A00D9EAE6 /* Media.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9C9740181FC5DD6A00D9EAE6 /* Media.xcassets */; };
9C9740271FC5DEAA00D9EAE6 /* NoMAD_ADAuth.framework in Resources */ = {isa = PBXBuildFile; fileRef = 9CBDCFA61FC4CEEF00CF73F4 /* NoMAD_ADAuth.framework */; };
9CBDCFAD1FC5CDB600CF73F4 /* CreateUser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9CBDCFA81FC5CDB600CF73F4 /* CreateUser.swift */; };
......@@ -20,6 +21,7 @@
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
9C6027451FE8224000B99B51 /* ContextAndHintHandling.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextAndHintHandling.swift; sourceTree = "<group>"; };
9C709EED1FE07D91006C74D1 /* loadAD.bash */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = loadAD.bash; sourceTree = "<group>"; };
9C709EEE1FE07D91006C74D1 /* resetDB.bash */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = resetDB.bash; sourceTree = "<group>"; };
9C9740181FC5DD6A00D9EAE6 /* Media.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Media.xcassets; sourceTree = "<group>"; };
......@@ -119,6 +121,7 @@
9CBDCFA71FC5CDB500CF73F4 /* NoMADLoginAD-Bridging-Header.h */,
9CBDCFB41FC5CE2100CF73F4 /* NoMADLoginAD.h */,
9CBDCFB31FC5CE2100CF73F4 /* NoMADLoginAD.m */,
9C6027451FE8224000B99B51 /* ContextAndHintHandling.swift */,
);
path = Base;
sourceTree = "<group>";
......@@ -209,6 +212,7 @@
9CBDCFBA1FC5CE6100CF73F4 /* SignIn.swift in Sources */,
9CBDCFB01FC5CDB600CF73F4 /* CheckAD.swift in Sources */,
9CBDCFB51FC5CE2200CF73F4 /* NoMADLoginAD.m in Sources */,
9C6027461FE8224000B99B51 /* ContextAndHintHandling.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......
......@@ -13,7 +13,6 @@ import NoMAD_ADAuth
class SignIn: NSWindowController {
//MARK: - setup variables
var mech: MechanismRecord?
var session: NoMADSession?
var shortName = ""
......@@ -25,7 +24,6 @@ class SignIn: NSWindowController {
@IBOutlet weak var domain: NSPopUpButton!
@IBOutlet weak var signIn: NSButton!
@IBOutlet weak var imageView: NSImageView!
//MARK: - UI Methods
override func windowDidLoad() {
......@@ -106,37 +104,6 @@ class SignIn: NSWindowController {
setContext(type: kAuthorizationEnvironmentPassword, value: password.stringValue)
}
/// Set a NoMAD Login Authorization mechanism hint.
///
/// - Parameters:
/// - type: A value from `HintType` representing the NoMad Login value to set.
/// - hint: A `String` of the hint value to set.
func setHint(type: HintType, hint: String) {
let data = NSKeyedArchiver.archivedData(withRootObject: hint)
var value = AuthorizationValue(length: data.count, data: UnsafeMutableRawPointer(mutating: (data as NSData).bytes.bindMemory(to: Void.self, capacity: data.count)))
let err = (mech?.fPlugin.pointee.fCallbacks.pointee.SetHintValue((mech?.fEngine)!, type.rawValue, &value))!
guard err == errSecSuccess else {
NSLog("NoMAD Login Set hint failed with: %@", err)
return
}
}
/// Set one of the known `AuthorizationTags` values to be used during mechanism evaluation.
///
/// - Parameters:
/// - type: A `String` constant from AuthorizationTags.h representing the value to set.
/// - value: A `String` value of the context value to set.
func setContext(type: String, value: String) {
let tempdata = value + "\0"
let data = tempdata.data(using: .utf8)
var value = AuthorizationValue(length: (data?.count)!, data: UnsafeMutableRawPointer(mutating: (data! as NSData).bytes.bindMemory(to: Void.self, capacity: (data?.count)!)))
let err = (mech?.fPlugin.pointee.fCallbacks.pointee.SetContextValue((mech?.fEngine)!, type, .extractable, &value))!
guard err == errSecSuccess else {
NSLog("NoMAD Login Set context value failed with: %@", err)
return
}
}
/// Complete the NoLo process and either continue to the next Authorization Plugin or reset the NoLo window.
///
/// - Parameter authResult:`Authorizationresult` enum value that indicates if login should proceed.
......@@ -166,3 +133,9 @@ extension SignIn: NoMADUserSessionDelegate {
completeLogin(authResult: .allow)
}
}
//MARK: - ContextAndHintHandling Conformance
extension SignIn: ContextAndHintHandling {
func getContext(type: String) {}
func getHint(type: HintType) {}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment