Custom User Validation

Catalyst Authentication allows you to authorize and validate your end-users using a custom Basic I/O function on the event of a sign-up to your Catalyst application. You can write your own logic and process the credentials that the user provides through this function, and grant access to your application.

A sample code for a Custom User Validation function is given below.

Ensure the following packages are imported:

    
copy
import com.catalyst.Context;
import com.catalyst.basic.BasicIO;
import com.catalyst.basic.ZCFunction;
import com.zc.api.APIConstants.ZCSignupValidationStatus;
import com.zc.common.ZCProject;
import com.zc.component.auth.ZCSignupResponseUserDetails;
import com.zc.component.auth.ZCSignupUserValidationRequest;
import com.zc.component.auth.ZCSignupUserValidationResponse;
import com.zc.component.users.ZCSignupUserService;

The validation logic can be set based on your preference. In this example, we have depicted the logic with @notallowedemail. If the user tries to sign up using a disallowed email addressed, the user will not be allowed to sign up.

    
copy
public class MainClass implements ZCFunction {
private static final Logger LOGGER = Logger.getLogger(MainClass.class.getName());
@Override
public void runner(Context context, BasicIO basicIO) throws Exception
{
try
{
ZCProject.initProject();
ZCSignupUserValidationRequest requestDetails = ZCSignupUserService.getSignupValidationRequest(basicIO);
if(requestDetails != null) {
/* Validation logic starts */
LOGGER.info("Inside null check");
ZCSignupUserValidationResponse validationResponse = ZCSignupUserValidationResponse.getInstance();
if(requestDetails.getUserDetails().getEmailId().contains("@notallowedmail"))
{
validationResponse.setStatus(ZCSignupValidationStatus.FAILURE); // The user has failed authentication
}
else
{
validationResponse.setStatus(ZCSignupValidationStatus.SUCCESS); // The actions that occur in the event of a successful authentication can be customized
ZCSignupResponseUserDetails respUserDetails = ZCSignupResponseUserDetails.getInstance();
respUserDetails.setFirstName("Patricial");
respUserDetails.setLastName("Boyle");
respUserDetails.setRoleIdentifier("App User");
respUserDetails.setOrgId("1241113");
validationResponse.setUserDetails(respUserDetails);
}
basicIO.write(validationResponse);
/* Validation logic ends */
}
}
catch(Exception e)
{
basicIO.write(e);
LOGGER.log(Level.SEVERE,"Exception in MainClass",e);
basicIO.setStatus(500);
}
}
}

To test this function, you can pass the details of the user in the following .JSON format:

    
copy
{
"request_type": "add_user",
"request_details":
{
"user_details":
{
"email_id": "emmy@zylker.com",
"first_name": "Emma",
"last_name": "Thompson",
"org_id": "65**************",
"role_details":
{
"role_name": "Moderator",
"role_id": "10*****"
}
},
"auth_type": "web"
}
}

Last Updated 2023-09-03 01:06:41 +0530 +0530

RELATED LINKS

Authentication

ON THIS PAGE
ACCESS THIS PAGE