From 42d5ddc559bf22792b170bdacaf19996350783e1 Mon Sep 17 00:00:00 2001 From: Rob Crittenden Date: Fri, 11 Jan 2008 11:44:23 -0500 Subject: [PATCH] Service principal deletion --- ipa-python/ipaclient.py | 3 ++ ipa-python/rpcclient.py | 12 +++++ .../ipagui/subcontrollers/principal.py | 45 ++++++++++++++++ .../ipagui/templates/principallist.kid | 6 ++- .../ipagui/templates/principalshow.kid | 53 +++++++++++++++++++ ipa-server/xmlrpc-server/funcs.py | 20 +++++++ ipa-server/xmlrpc-server/ipaxmlrpc.py | 1 + 7 files changed, 138 insertions(+), 2 deletions(-) create mode 100644 ipa-server/ipa-gui/ipagui/templates/principalshow.kid diff --git a/ipa-python/ipaclient.py b/ipa-python/ipaclient.py index c5377f3af..c05abd510 100644 --- a/ipa-python/ipaclient.py +++ b/ipa-python/ipaclient.py @@ -386,6 +386,9 @@ class IPAClient: def add_service_principal(self, princ_name): return self.transport.add_service_principal(princ_name) + def delete_service_principal(self, principal_dn): + return self.transport.delete_service_principal(principal_dn) + def find_service_principal(self, criteria, sattrs=None, searchlimit=0, timelimit=-1): """Return a list: counter followed by a Entity object for each host that matches the criteria. If the results are truncated, counter will diff --git a/ipa-python/rpcclient.py b/ipa-python/rpcclient.py index 32249fd3c..4d6b3a701 100644 --- a/ipa-python/rpcclient.py +++ b/ipa-python/rpcclient.py @@ -699,6 +699,18 @@ class RPCClient: return ipautil.unwrap_binary_data(result) + def delete_service_principal(self, principal_dn): + server = self.setup_server() + + try: + result = server.delete_service_principal(principal_dn) + except xmlrpclib.Fault, fault: + raise ipaerror.gen_exception(fault.faultCode, fault.faultString) + except socket.error, (value, msg): + raise xmlrpclib.Fault(value, msg) + + return ipautil.unwrap_binary_data(result) + def find_service_principal (self, criteria, sattrs=None, searchlimit=0, timelimit=-1): """Return a list: counter followed by a Entity object for each host that matches the criteria. If the results are truncated, counter will diff --git a/ipa-server/ipa-gui/ipagui/subcontrollers/principal.py b/ipa-server/ipa-gui/ipagui/subcontrollers/principal.py index 27c4f9d63..47deb8879 100644 --- a/ipa-server/ipa-gui/ipagui/subcontrollers/principal.py +++ b/ipa-server/ipa-gui/ipagui/subcontrollers/principal.py @@ -125,6 +125,51 @@ class PrincipalController(IPAController): return dict(principals=principals, hostname=hostname, fields=ipagui.forms.principal.PrincipalFields()) + @expose("ipagui.templates.principalshow") + @identity.require(identity.not_anonymous()) + def show(self, **kw): + """Display a single service principal""" + + try: + princ = kw['principal'] + princ_dn = kw['principal_dn'] + except KeyError, e: + turbogears.flash("Principal show failed. Unable to find key %s" % e) + raise turbogears.redirect("/principal/list") + + principal = {} + + try: + # The principal info is passed in. Not going to both to re-query this. + (service,host) = princ.split('/') + h = host.split('@') + principal['service'] = service + principal['hostname'] = h[0] + principal['principal_dn'] = princ_dn + + return dict(principal=principal) + except: + turbogears.flash("Principal show failed %s" % princ) + raise turbogears.redirect("/") + + @expose() + @identity.require(identity.in_group("admins")) + def delete(self, principal): + """Delete a service principal""" + self.restrict_post() + client = self.get_ipaclient() + + print "Deleting %s" % principal + + try: + client.delete_service_principal(principal) + + turbogears.flash("Service principal deleted") + raise turbogears.redirect('/principal/list') + except (SyntaxError, ipaerror.IPAError), e: + turbogears.flash("Service principal deletion failed: " + str(e) + "
" + e.detail[0]['desc']) + raise turbogears.redirect('/principal/list') + @validate(form=principal_new_form) @identity.require(identity.not_anonymous()) def principalcreatevalidate(self, tg_errors=None, **kw): diff --git a/ipa-server/ipa-gui/ipagui/templates/principallist.kid b/ipa-server/ipa-gui/ipagui/templates/principallist.kid index ae8bdda46..8da9c15e3 100644 --- a/ipa-server/ipa-gui/ipagui/templates/principallist.kid +++ b/ipa-server/ipa-gui/ipagui/templates/principallist.kid @@ -33,10 +33,12 @@ - ${principal.hostname} + ${principal.hostname} - ${principal.service} + ${principal.service} diff --git a/ipa-server/ipa-gui/ipagui/templates/principalshow.kid b/ipa-server/ipa-gui/ipagui/templates/principalshow.kid new file mode 100644 index 000000000..c93622d3f --- /dev/null +++ b/ipa-server/ipa-gui/ipagui/templates/principalshow.kid @@ -0,0 +1,53 @@ + + + + +View Service Principal + + + + + + + +
+ + + + + +

View Service Principal

+ +

Principal

+ + + + + + + + + +
+ : + ${principal.get("hostname")}
+ : + ${principal.get("service")}
+
+ +
+ + + diff --git a/ipa-server/xmlrpc-server/funcs.py b/ipa-server/xmlrpc-server/funcs.py index a4ebfcded..d0600b51a 100644 --- a/ipa-server/xmlrpc-server/funcs.py +++ b/ipa-server/xmlrpc-server/funcs.py @@ -1724,6 +1724,26 @@ class IPAServer: self.releaseConnection(conn) return res + def delete_service_principal (self, principal, opts=None): + """Delete a service principal. + + principal is the full DN of the entry to delete. + + This should be called with much care. + """ + if not principal: + raise ipaerror.gen_exception(ipaerror.INPUT_INVALID_PARAMETER) + entry = self.get_entry_by_dn(principal, ['dn', 'objectclass'], opts) + if entry is None: + raise ipaerror.gen_exception(ipaerror.LDAP_NOT_FOUND) + + conn = self.getConnection(opts) + try: + res = conn.deleteEntry(entry['dn']) + finally: + self.releaseConnection(conn) + return res + def find_service_principal(self, criteria, sattrs, searchlimit=-1, timelimit=-1, opts=None): """Returns a list: counter followed by the results. diff --git a/ipa-server/xmlrpc-server/ipaxmlrpc.py b/ipa-server/xmlrpc-server/ipaxmlrpc.py index abf6aed7e..3f3e38b8e 100644 --- a/ipa-server/xmlrpc-server/ipaxmlrpc.py +++ b/ipa-server/xmlrpc-server/ipaxmlrpc.py @@ -365,6 +365,7 @@ def handler(req, profiling=False): h.register_function(f.get_password_policy) h.register_function(f.update_password_policy) h.register_function(f.add_service_principal) + h.register_function(f.delete_service_principal) h.register_function(f.find_service_principal) h.register_function(f.get_radius_client_by_ip_addr) h.register_function(f.add_radius_client)