If you want to add two-factor SMS authentication to your application you should do the following steps:
- Clone this repository and execute command
gradlew build
- Copy
sms-authentication.jar
from repo_clone_folder/build/lib folder to Tomcat CATALINA_HOME/lib folder or add task to your build script wich makes this operation - Configure your
<Context>
tag in CATALINA_HOME/conf/server.xml as follows:<Realm xmlns="" className="io.codesolver.auth.SMSRealm" dataSourceName="xyz" localDataSource="true" roleNameCol="GROUP_NAME" userCredCol="USR_PASSWD" userNameCol="USR_NAME" userRoleTable="MTD_GROUPS" userTable="MTD_USERS" codeTable="MTD_CODE"> ... </Realm> <Valve xmlns="" className="io.codesolver.SMSAuthenticator"/>
- Add table wich will contain generated codes. Table name should be the same as in the above example. See attribute
codeTable
of tag<Realm>
. Table structure should be:Fieldsid:numeric - Primary Key user:string - Foreign Key to user table code:string dateFrom:timestamp dateTo:timestamp
dateFrom
anddateTo
are used to define time period in wich code is valid. - Add to your application a function wich will generate code, save code to database and send code via SMS
- Ensure that this function can be called without authentication
- Latest step. Update your login page as folowing:
- Add field with name
j_code
- Add button
Get code
- Link this button with function wich has been created in step 5
- Add field with name
Congradulations! Now you have two-factor authentication with SMS in your application.