extensions/net.sf.basedb.otp/trunk/src/net/sf/basedb/otp/OtpQRCodeTabFactory.java

Code
Comments
Other
Rev Date Author Line
4923 10 Aug 18 nicklas 1 /**
4923 10 Aug 18 nicklas 2   $Id: IncludeContentTabFactory.java 6875 2015-04-20 09:08:18Z nicklas $
4923 10 Aug 18 nicklas 3
4923 10 Aug 18 nicklas 4   Copyright (C) 2010 Nicklas Nordborg
4923 10 Aug 18 nicklas 5
4923 10 Aug 18 nicklas 6   This file is part of BASE - BioArray Software Environment.
4923 10 Aug 18 nicklas 7   Available at http://base.thep.lu.se/
4923 10 Aug 18 nicklas 8
4923 10 Aug 18 nicklas 9   BASE is free software; you can redistribute it and/or
4923 10 Aug 18 nicklas 10   modify it under the terms of the GNU General Public License
4923 10 Aug 18 nicklas 11   as published by the Free Software Foundation; either version 3
4923 10 Aug 18 nicklas 12   of the License, or (at your option) any later version.
4923 10 Aug 18 nicklas 13
4923 10 Aug 18 nicklas 14   BASE is distributed in the hope that it will be useful,
4923 10 Aug 18 nicklas 15   but WITHOUT ANY WARRANTY; without even the implied warranty of
4923 10 Aug 18 nicklas 16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4923 10 Aug 18 nicklas 17   GNU General Public License for more details.
4923 10 Aug 18 nicklas 18
4923 10 Aug 18 nicklas 19   You should have received a copy of the GNU General Public License
4923 10 Aug 18 nicklas 20   along with BASE. If not, see <http://www.gnu.org/licenses/>.
4923 10 Aug 18 nicklas 21 */
4923 10 Aug 18 nicklas 22 package net.sf.basedb.otp;
4923 10 Aug 18 nicklas 23
4923 10 Aug 18 nicklas 24 import net.sf.basedb.clients.web.extensions.tabcontrol.IncludeContentTabFactory;
4923 10 Aug 18 nicklas 25 import net.sf.basedb.clients.web.extensions.tabcontrol.TabAction;
4923 10 Aug 18 nicklas 26 import net.sf.basedb.core.User;
4923 10 Aug 18 nicklas 27 import net.sf.basedb.util.extensions.InvokationContext;
4923 10 Aug 18 nicklas 28
4923 10 Aug 18 nicklas 29 /**
4923 10 Aug 18 nicklas 30   Adds a tab to the user information dialog if the user has
4923 10 Aug 18 nicklas 31   OTP configured. We inherit all functionality from the BASE implementation
4923 10 Aug 18 nicklas 32   and onl checks if the user has configured OTP or not.
4923 10 Aug 18 nicklas 33 */
4923 10 Aug 18 nicklas 34 public class OtpQRCodeTabFactory 
4923 10 Aug 18 nicklas 35   extends IncludeContentTabFactory
4923 10 Aug 18 nicklas 36 {
4923 10 Aug 18 nicklas 37
4923 10 Aug 18 nicklas 38   /**
4923 10 Aug 18 nicklas 39     Create a new factory instance.
4923 10 Aug 18 nicklas 40   */
4923 10 Aug 18 nicklas 41   public OtpQRCodeTabFactory()
4923 10 Aug 18 nicklas 42   {}
4923 10 Aug 18 nicklas 43
4923 10 Aug 18 nicklas 44   @Override
4923 10 Aug 18 nicklas 45   public boolean prepareContext(InvokationContext<? super TabAction> context) 
4923 10 Aug 18 nicklas 46   {
4923 10 Aug 18 nicklas 47     Object currentItem = context.getClientContext().getCurrentItem();
4923 10 Aug 18 nicklas 48     if (!(currentItem instanceof User)) return false;
4923 10 Aug 18 nicklas 49
4923 10 Aug 18 nicklas 50     User currentUser = (User)currentItem;
4923 10 Aug 18 nicklas 51     String otpKeyEncrypted = (String)currentUser.getExtended("otpSecretKey");
4923 10 Aug 18 nicklas 52     if (otpKeyEncrypted == null) return false;
4923 10 Aug 18 nicklas 53     
4923 10 Aug 18 nicklas 54     return super.prepareContext(context);
4923 10 Aug 18 nicklas 55   }  
4923 10 Aug 18 nicklas 56
4923 10 Aug 18 nicklas 57 }