Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift macOS授权插件机制在两者同时位于AuthorizationDB中时不会被破坏_Swift_Macos_Security_Plugins_Authorization - Fatal编程技术网

Swift macOS授权插件机制在两者同时位于AuthorizationDB中时不会被破坏

Swift macOS授权插件机制在两者同时位于AuthorizationDB中时不会被破坏,swift,macos,security,plugins,authorization,Swift,Macos,Security,Plugins,Authorization,我在LoginUIAuthPlugin(MacOS授权插件)中包含了两种机制。授权机制运行得很好,但第二个机制在第一个机制被销毁之前被调用,然后第一个机制被自己调用。它们都会被无限地调用。 当它们中的任何一个单独使用时,它们运行良好,破坏良好。但是,问题是当它们同时在AuthorizationDB中时。 Swift中的类实例会自动销毁,就像只调用一种机制时销毁一样。那么,我怎样才能解决这个问题呢?我可以手动调用destroy函数吗?还是 我的授权数据库: . . <key>mecha

我在LoginUIAuthPlugin(MacOS授权插件)中包含了两种机制。授权机制运行得很好,但第二个机制在第一个机制被销毁之前被调用,然后第一个机制被自己调用。它们都会被无限地调用。 当它们中的任何一个单独使用时,它们运行良好,破坏良好。但是,问题是当它们同时在AuthorizationDB中时。 Swift中的类实例会自动销毁,就像只调用一种机制时销毁一样。那么,我怎样才能解决这个问题呢?我可以手动调用destroy函数吗?还是

我的授权数据库:

.
.
<key>mechanisms</key>
<array>
<string>builtin:policy-banner</string>
<string>LoginUIAuthPlugin:login</string>
<string>builtin:login-begin</string>
<string>LoginUIAuthPlugin:createUser,privileged</string>
<string>builtin:reset-password,privileged</string>
<string>loginwindow:FDESupport,privileged</string>
.
.
#第二种机制从这里开始:

2020-10-16 10:55:51.566353+0500 0x24af       mechanism -1 will invoke
2020-10-16 10:55:51.566462+0500 0x24af       LoginUICreateUserMechanism: invoke
2020-10-16 10:55:51.581631+0500 0x24af       mechanism -1 will set result 0
2020-10-16 10:55:51.582208+0500 0x24af       mechanism -1 did set result 0
2020-10-16 10:55:51.582247+0500 0x24af       mechanism -1 will did deactivate
2020-10-16 10:55:51.582272+0500 0x24af       mechanism -1 did did deactivate
#第一个机制再次调用:

2020-10-16 10:55:51.582314+0500 0x24af       mechanism -1 did invoke
2020-10-16 10:55:53.869029+0500 0x240c       mechanism -1 will invoke
2020-10-16 10:55:53.869406+0500 0x240c       LoginUIAuthMechanism: invoke
2020-10-16 10:55:53.869520+0500 0x240c       will display view
2020-10-16 10:55:53.874812+0500 0x240c       will enable
2020-10-16 10:55:53.893029+0500 0x240c       will return view for Username
2020-10-16 10:55:53.908530+0500 0x240c       mechanism -1 did invoke
所有这些都会无限重复(

机制由以下代码创建:

extension AuthPlugin: AuthPluginEntry {
.
.
.
return AuthPlugin.start(
            log: OSLog(subsystem: "com.example.apple-samplecode.LoginUIAuthPlugin", category: "plugin"),
            mechanismForID: {
                mechID, context in
                guard mechID.rawValue == "login" || mechID.rawValue == "createUserMech" else { throw AuthPlugin.noSuchMechanismError }
                switch mechID.rawValue {
                case "login":
                    return LoginUIAuthMechanism(context: context)
                case "createUserMech":
                    return LoginUICreateUserMechanism(context: context);
                default:
                    throw AuthPlugin.noSuchMechanismError;
                }
            },
.
.
.

处理第二种机制的类:

class LoginUICreateUserMechanism:AuthPlugin.Mechanism {
    var context: AuthPlugin.Context
    
    func invoke() throws {
        try! self.context.setResult(.allow)
        try! self.context.didDeactivate()
    }
    
    func deactivate() throws {
        globalLogger("LoginUICreateUserMechanism: deactivate")
    }
    
    func destroy() {
        globalLogger("LoginUICreateUserMechanism: destroy")
    }
    
    init(context: AuthPlugin.Context) {
        globalLogger("LoginUICreateUserMechanism: init")
        self.context = context
    }
    
    deinit {
        globalLogger("LoginUICreateUserMechanism: deinit")
    }
class LoginUICreateUserMechanism:AuthPlugin.Mechanism {
    var context: AuthPlugin.Context
    
    func invoke() throws {
        try! self.context.setResult(.allow)
        try! self.context.didDeactivate()
    }
    
    func deactivate() throws {
        globalLogger("LoginUICreateUserMechanism: deactivate")
    }
    
    func destroy() {
        globalLogger("LoginUICreateUserMechanism: destroy")
    }
    
    init(context: AuthPlugin.Context) {
        globalLogger("LoginUICreateUserMechanism: init")
        self.context = context
    }
    
    deinit {
        globalLogger("LoginUICreateUserMechanism: deinit")
    }