I came accross a question posted in the SDN forum asking if it was possible to restrict the viewing of iviews and pages during certain time of the day. I thought it was possible and through this blog I present what I find is a possible solution.
My solution is as follows.I create the iviews and put them into pages. The pages are attached to a role. The users are assigned or unassigned from the role based on how I wish to control the access. The assigning and unassigning of the users from the roles can be made dynamic using the IRole, IRoleFactory API’s.
For the sake of simplicity, I have created an iview which is assigned to the role “usr”. The user “sampleuser” is assigned to the role. By using the system time, I will assign or unassign the user from the role, inturn controlling the access to the page assigned to the role.
I will give the code samples here. Organise the following in the form of a Dyn Page. Export the project as a par file and create an iview out of the par file. Place the iview in the desktop inner page of the portal. You will have a page restrictor that will restrict the uasage of the pages between certain time period.
The following are the variables and conventions used
irole: Variable indicating Name of the role taken
iuser: Variable indicating User taken
roleiterator: Variable indicating Role Iterator. java.util.iterator
irolefactory: Variable indicating iRoleFactory
inTime: Boolean variable which is used to check if the current system time is within the restriction time
FlagLock: Integer variable indicating if the restriction is enforced or not. A value of 1 indicates no restriction and a value of 0 indicates a restriction.
The folowing imports are to be organised
The following methods are the methods for adding and removing a user into a role
public void addRole() – Method to add a user into a role
public void removeRole() – Method to remove a user from a role
The following method is the checking method which checks if the time is between a certain limit and returns a boolean. The checking method here is very simple. It can be modelled as complex as you might want. The section controller is added in the doProcessBeforeOutput section.