X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=src%2Fmoonshot-server.vala;h=74288f78e5f71d7af06ae6e99385873c01436e06;hb=5b68b364f2c62fa43111b5a53c7040d34205ba20;hp=681d0dd211aac63b107fa124cfa989b2cbc8c42a;hpb=e34a05b2fc62596d4aeb455d88539eecb8d6a10f;p=moonshot-ui.git diff --git a/src/moonshot-server.vala b/src/moonshot-server.vala index 681d0dd..74288f7 100644 --- a/src/moonshot-server.vala +++ b/src/moonshot-server.vala @@ -1,13 +1,54 @@ +/* + * Copyright (c) 2011-2014, JANET(UK) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of JANET(UK) nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. +*/ #if IPC_DBUS [DBus (name = "org.janet.Moonshot")] public class MoonshotServer : Object { - private IdentityManagerView main_window; + private IdentityManagerApp parent_app; + + public MoonshotServer (IdentityManagerApp app) + { + this.parent_app = app; + } - public MoonshotServer (Gtk.Window window) + public bool show_ui() { - this.main_window = (IdentityManagerView) window; + if (parent_app.view == null) { + return false; + } + parent_app.show(); + parent_app.explicitly_launched = true; + return true; } public async bool get_identity (string nai, @@ -20,7 +61,7 @@ public class MoonshotServer : Object { out string subject_name_constraint, out string subject_alt_name_constraint) { - var request = new IdentityRequest (main_window, + var request = new IdentityRequest (parent_app, nai, password, service); @@ -37,9 +78,12 @@ public class MoonshotServer : Object { var id_card = request.id_card; - if (id_card != null) { + if ((id_card != null) && (id_card.display_name != IdCard.NO_IDENTITY)) { nai_out = id_card.nai; - password_out = id_card.password; + if ((request.password!=null) && (request.password != "")) + password_out = request.password; + else + password_out = id_card.password; server_certificate_hash = id_card.trust_anchor.server_cert; ca_certificate = id_card.trust_anchor.ca_cert; @@ -72,7 +116,7 @@ public class MoonshotServer : Object { out string subject_name_constraint, out string subject_alt_name_constraint) { - var request = new IdentityRequest.default (main_window); + var request = new IdentityRequest.default (parent_app); request.set_callback ((IdentityRequest) => get_default_identity.callback()); request.execute (); yield; @@ -115,21 +159,24 @@ public class MoonshotServer : Object { public bool install_id_card (string display_name, string user_name, - string password, - string realm, - string[] rules_patterns, - string[] rules_always_confirm, - string[] services, - string ca_cert, - string subject, - string subject_alt, - string server_cert) + string ?password, + string ?realm, + string[] ?rules_patterns, + string[] ?rules_always_confirm, + string[] ?services, + string ?ca_cert, + string ?subject, + string ?subject_alt, + string ?server_cert, + int force_flat_file_store) { IdCard idcard = new IdCard (); idcard.display_name = display_name; idcard.username = user_name; idcard.password = password; + if ((password != null) && (password != "")) + idcard.store_password = true; idcard.issuer = realm; idcard.services = services; idcard.trust_anchor.ca_cert = ca_cert; @@ -139,25 +186,28 @@ public class MoonshotServer : Object { if (rules_patterns.length == rules_always_confirm.length) { - idcard.rules = new Rule[rules_patterns.length]; + /* workaround Centos vala array property bug: use temp array */ + Rule[] rules = new Rule[rules_patterns.length]; - for (int i=0; i { mutex.lock (); - success = main_window.add_identity (idcard); + success = parent_app.add_identity (idcard, force_flat_file_store); cond.signal (); mutex.unlock (); return false;