Introduction

The purpose of this task is to remove all tokens from the token repository of a specific product and manufacturer, that have been assigned to a specific user (optionally, token deletion can be further restricted to inactive tokens).

The task will either use previously supplied default task parameters, or will be manually supplied by the system administrator after the task is run from the management console.

The task can be found by navigating to "Administration | Tasks", then scrolling down to the task "Delete all tokens of user by product";

Task Parameters

The task parameters are used by the task script to determine which tokens are to be deleted and are edited by left clicking on the context menu of the task and selecting "Parameters";

A new window titled "Task Parameters" will now open that lists the parameters making them available for editing, and the default parameters for this task are as follows;






Specify the domain that assigned users of the tokens must be members of if the tokens are to be deleted by the task.




If specified, this property will restrict token deletion to tokens that are assigned to the user with the selected user login name.





Specifies the Product Code of the tokens to be deleted.





Specifies if only inactive tokens are to be deleted when the task is run.




The parameters may then be editing by selecting one of the parameters, then clicking on the button.

Editing and Scheduling the Task

Viewing and Editing Tasks

The task can be edited by left clicking on the context menu of the task and selecting "Edit";

A new window will now open titled "Task - Edit";







Enter the name to be assigned to the task within the management console.





Enter a description of what the task will do.





The version number of the task.





This field is used to specify when the task is scheduled to execute;

(see "Scheduling the Task Execution Time and Frequency [MC-TKTD]" in the Related Articles section below).





This field will determine if the task schedule is enabled (if enabled the task will execute at the scheduled time).





Specifies how many times the task should be repeated after the task is executed.






                import com.deepnet.das.util.*
                import com.deepnet.das.user.*
                import com.deepnet.das.token.*
                import com.deepnet.das.exception.ProductNotFoundException
                import com.deepnet.das.domain.Domain
                import com.deepnet.das.exception.DomainNotFoundException
                import com.deepnet.das.exception.UserNotFoundException
                import com.deepnet.das.identitysource.*
                import com.deepnet.das.util.QueryHelper
                import com.deepnet.das.licence.LicenceManager

                if (Util.isNull(removeInactiveTokensOnly)) {
                    removeInactiveTokensOnly = true;
                }
                if (!Util.isNullOrEmpty(product)) {
                    Product prod = Product.findById(product as long)
                    if(!prod)
                        throw new ProductNotFoundException()
                    deleteAllTokensOfUserByProduct(domainName, userName, removeInactiveTokensOnly, prod)
                } else {
                    deleteAllTokensOfUserByProduct(domainName, userName, removeInactiveTokensOnly)
                }

                def deleteAllTokensOfUserByProduct(String domainName, String loginName, boolean onlyRemoveInactiveTokens, def prod = null) {
                    Domain domain = Domain.findByName(domainName)
                    if (!domain) {
                        throw new DomainNotFoundException(domainName)
                    }
                    User user = User.findImportedUser(QueryHelper.mapToJsonQuery(['loginName': loginName, 'domain.name': domainName]), false)
                    if (!user)
                        throw new UserNotFoundException();
                    if (!user.isAttached()) {
                        return;
                    }
                    int deleteCount = 0;
                    int totalToken = 0;
                    int totalUser = 1;

                    def tas = user.tokenAssignments.findAll{true};
                    if (tas) {
                        if (prod != null) {
                            tas = tas.findAll {it.token.product.id == prod.id}
                        }
                        totalToken += tas.size();
                        if (onlyRemoveInactiveTokens) {
                            tas = tas.findAll {it.status == AssignmentStatus.INACTIVE.toString()}
                        }
                        tas.each { ta ->
                            user.unassignToken(ta.token);
                            deleteCount++;
                        }
                        onProgress(totalToken, " token handled:  " + totalToken + "/" + totalUser + "users");
                    }
                    def msg =  " deleted:  " + deleteCount + " tokens from " + totalUser + " users and " + totalToken + " tokens"
                    LicenceManager.triggerStatistics()
                    setEndMessage(msg)
                }





Scheduling the Task

Select the "Enable Schedule" checkbox to ensure the task schedule is activated, then use the pencil icon ("")  to specify the time and frequency settings for automated task execution.

Manual Task Execution

The task can be run manually from the management console by left click on the context menu of the task, then selecting "Run";

A new window headed "Execute Task" will now open allowing you to edit the task parameters prior to running the task;







Provide a brief description that will be used to describe the purpose of the task in the audit log.





Specify the domain that assigned users of the tokens must be members of if the tokens are to be deleted by the task.




If specified, this property will restrict token deletion to tokens that are assigned to the user with the selected user login name.




If specified, this property will restrict token deletion to tokens that have the specified Product Code.




If selected on tokens that are inactive and meet the other criteria will be deleted.