001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.security.twofactor; 029 030import java.util.Objects; 031 032import org.apache.commons.lang3.StringUtils; 033import org.apache.commons.lang3.builder.HashCodeBuilder; 034import org.apache.commons.lang3.builder.ReflectionToStringBuilder; 035import org.apache.commons.lang3.builder.ToStringStyle; 036 037/** 038 * Second factor information for login. 039 */ 040public class CmsSecondFactorInfo { 041 042 /** The verification code. */ 043 private String m_code; 044 045 /** The shared secret. */ 046 private String m_secret; 047 048 /** 049 * Creates a new instance. 050 * 051 * @param code the verification code 052 */ 053 public CmsSecondFactorInfo(String code) { 054 055 m_code = StringUtils.trim(code); 056 } 057 058 /** 059 * Creates a new instance. 060 * 061 * @param secret the secret 062 * @param code the verification code 063 */ 064 public CmsSecondFactorInfo(String secret, String code) { 065 066 m_secret = StringUtils.trim(secret); 067 m_code = StringUtils.trim(code); 068 } 069 070 /** 071 * @see java.lang.Object#equals(java.lang.Object) 072 */ 073 @Override 074 public boolean equals(Object obj) { 075 076 if (!(obj instanceof CmsSecondFactorInfo)) { 077 return false; 078 } 079 CmsSecondFactorInfo other = ((CmsSecondFactorInfo)obj); 080 if (!Objects.equals(m_code, other.m_code)) { 081 return false; 082 } 083 if (!Objects.equals(m_secret, other.m_secret)) { 084 return false; 085 } 086 return true; 087 088 } 089 090 /** 091 * Gets the verification code (normally generated and entered by the user). 092 * 093 * @return the verification code 094 */ 095 public String getCode() { 096 097 return m_code; 098 } 099 100 /** 101 * Gets the secret (usually null, only used for second factor setup). 102 * 103 * @return the secret 104 */ 105 public String getSecret() { 106 107 return m_secret; 108 } 109 110 /** 111 * @see java.lang.Object#hashCode() 112 */ 113 @Override 114 public int hashCode() { 115 116 return new HashCodeBuilder().append(m_code).append(m_secret).hashCode(); 117 } 118 119 /** 120 * @see java.lang.Object#toString() 121 */ 122 @Override 123 public String toString() { 124 125 return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE); 126 127 } 128 129}