When viewing a token from the CLI or UI, the type of the token
should be displayed.

https://fedorahosted.org/freeipa/ticket/4563
From b428b30e2110472d000e2c0e06bc82a3948a8906 Mon Sep 17 00:00:00 2001
From: Nathaniel McCallum <npmccal...@redhat.com>
Date: Wed, 15 Oct 2014 12:24:56 -0400
Subject: [PATCH] Display token type when viewing token

When viewing a token from the CLI or UI, the type of the token
should be displayed.

https://fedorahosted.org/freeipa/ticket/4563
---
 install/ui/src/freeipa/otptoken.js |  1 +
 ipalib/plugins/otptoken.py         | 13 ++++++++++++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/install/ui/src/freeipa/otptoken.js b/install/ui/src/freeipa/otptoken.js
index d5afd25e66c58f4a3b5ce7241b3ddd0ca4f00850..526ca22dc2a8a5d4a109ab9397383d1fb4d41a2a 100644
--- a/install/ui/src/freeipa/otptoken.js
+++ b/install/ui/src/freeipa/otptoken.js
@@ -177,6 +177,7 @@ return {
                     label: '@i18n:objects.otptoken.details',
                     fields: [
                         'ipatokenuniqueid',
+                        'type',
                         {
                             $type: 'textarea',
                             name: 'description'
diff --git a/ipalib/plugins/otptoken.py b/ipalib/plugins/otptoken.py
index 1bd85d4b952dc51ea800ed37c49b3c50aeb31492..6917cfbbb0a5597827841f22e618289771267795 100644
--- a/ipalib/plugins/otptoken.py
+++ b/ipalib/plugins/otptoken.py
@@ -108,6 +108,12 @@ def _check_interval(not_before, not_after):
         return not_before <= not_after
     return True
 
+def _set_token_type(entry_attrs):
+    klasses = [x.lower() for x in entry_attrs.get('objectclass', [])]
+    for ttype in TOKEN_TYPES.keys():
+        cls = 'ipatoken' + ttype
+        if cls.lower() in klasses:
+            entry_attrs['type'] = ttype.upper()
 
 @register()
 class otptoken(LDAPObject):
@@ -120,7 +126,7 @@ class otptoken(LDAPObject):
     object_class = ['ipatoken']
     possible_objectclasses = ['ipatokentotp', 'ipatokenhotp']
     default_attributes = [
-        'ipatokenuniqueid', 'description', 'ipatokenowner',
+        'objectclass', 'ipatokenuniqueid', 'description', 'ipatokenowner',
         'ipatokendisabled', 'ipatokennotbefore', 'ipatokennotafter',
         'ipatokenvendor', 'ipatokenmodel', 'ipatokenserial', 'managedby'
     ]
@@ -265,6 +271,7 @@ class otptoken_add(LDAPCreate):
                                   error='is before the validity start')
 
         # Set the object class and defaults for specific token types
+        options['type'] = options['type'].lower()
         entry_attrs['objectclass'] = otptoken.object_class + ['ipatoken' + options['type']]
         for ttype, tattrs in TOKEN_TYPES.items():
             if ttype != options['type']:
@@ -315,6 +322,7 @@ class otptoken_add(LDAPCreate):
 
     def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
         entry_attrs['uri'] = getattr(context, 'uri')
+        _set_token_type(entry_attrs)
         _convert_owner(self.api.Object.user, entry_attrs, options)
         return super(otptoken_add, self).post_callback(ldap, dn, entry_attrs, *keys, **options)
 
@@ -369,6 +377,7 @@ class otptoken_mod(LDAPUpdate):
         return dn
 
     def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
+        _set_token_type(entry_attrs)
         _convert_owner(self.api.Object.user, entry_attrs, options)
         return super(otptoken_mod, self).post_callback(ldap, dn, entry_attrs, *keys, **options)
 
@@ -396,6 +405,7 @@ class otptoken_find(LDAPSearch):
 
     def post_callback(self, ldap, entries, truncated, *args, **options):
         for entry in entries:
+            _set_token_type(entry)
             _convert_owner(self.api.Object.user, entry, options)
         return super(otptoken_find, self).post_callback(ldap, entries, truncated, *args, **options)
 
@@ -405,6 +415,7 @@ class otptoken_show(LDAPRetrieve):
     __doc__ = _('Display information about an OTP token.')
 
     def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
+        _set_token_type(entry_attrs)
         _convert_owner(self.api.Object.user, entry_attrs, options)
         return super(otptoken_show, self).post_callback(ldap, dn, entry_attrs, *keys, **options)
 
-- 
2.1.0

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to