use of org.wso2.iot.integration.ui.pages.login.LoginPage in project identity-outbound-auth-sms-otp by wso2-extensions.
the class SMSOTPAuthenticator method proceedWithOTP.
/**
* Proceed with One Time Password.
*
* @param response the HttpServletResponse
* @param context the AuthenticationContext
* @param errorPage the errorPage
* @param mobileNumber the mobile number
* @param queryParams the queryParams
* @param username the Username
* @throws AuthenticationFailedException
*/
private void proceedWithOTP(HttpServletResponse response, AuthenticationContext context, String errorPage, String mobileNumber, String queryParams, String username) throws AuthenticationFailedException {
String screenValue;
Map<String, String> authenticatorProperties = context.getAuthenticatorProperties();
boolean isEnableResendCode = SMSOTPUtils.isEnableResendCode(context, getName());
String loginPage = getLoginPage(context);
String tenantDomain = MultitenantUtils.getTenantDomain(username);
String tenantAwareUsername = MultitenantUtils.getTenantAwareUsername(username);
UserRealm userRealm = SMSOTPUtils.getUserRealm(tenantDomain);
try {
// One time password is generated and stored in the context.
OneTimePassword token = new OneTimePassword();
String secret = OneTimePassword.getRandomNumber(SMSOTPConstants.SECRET_KEY_LENGTH);
String otpToken = token.generateToken(secret, String.valueOf(SMSOTPConstants.NUMBER_BASE), SMSOTPConstants.NUMBER_DIGIT);
context.setProperty(SMSOTPConstants.OTP_TOKEN, otpToken);
if (log.isDebugEnabled()) {
log.debug("Generated OTP successfully and set to the context.");
}
// Get the values of the sms provider related api parameters.
String smsUrl = authenticatorProperties.get(SMSOTPConstants.SMS_URL);
String httpMethod = authenticatorProperties.get(SMSOTPConstants.HTTP_METHOD);
String headerString = authenticatorProperties.get(SMSOTPConstants.HEADERS);
String payload = authenticatorProperties.get(SMSOTPConstants.PAYLOAD);
String httpResponse = authenticatorProperties.get(SMSOTPConstants.HTTP_RESPONSE);
if (!sendRESTCall(context, smsUrl, httpMethod, headerString, payload, httpResponse, mobileNumber, otpToken)) {
String retryParam;
context.setProperty(SMSOTPConstants.STATUS_CODE, SMSOTPConstants.UNABLE_SEND_CODE);
if (context.getProperty(SMSOTPConstants.ERROR_CODE) != null) {
retryParam = SMSOTPConstants.UNABLE_SEND_CODE_PARAM + context.getProperty(SMSOTPConstants.ERROR_CODE).toString();
} else {
retryParam = SMSOTPConstants.UNABLE_SEND_CODE_PARAM + SMSOTPConstants.UNABLE_SEND_CODE_VALUE;
}
String redirectUrl = getURL(errorPage, queryParams);
response.sendRedirect(redirectUrl + SMSOTPConstants.RESEND_CODE + isEnableResendCode + retryParam);
} else {
String url = getURL(loginPage, queryParams);
boolean isUserExists = FederatedAuthenticatorUtil.isUserExistInUserStore(username);
if (isUserExists) {
screenValue = getScreenAttribute(context, userRealm, tenantAwareUsername);
if (screenValue != null) {
url = url + SMSOTPConstants.SCREEN_VALUE + screenValue;
}
}
response.sendRedirect(url);
}
} catch (IOException e) {
throw new AuthenticationFailedException("Error while sending the HTTP request. ", e);
} catch (UserStoreException e) {
throw new AuthenticationFailedException("Failed to get the user from user store. ", e);
}
}
use of org.wso2.iot.integration.ui.pages.login.LoginPage in project identity-outbound-auth-sms-otp by wso2-extensions.
the class SMSOTPAuthenticator method checkStatusCode.
/**
* Check the status codes when resend and retry enabled.
*
* @param response the HttpServletResponse
* @param context the AuthenticationContext
* @param queryParams the queryParams
* @param errorPage the errorPage
* @throws AuthenticationFailedException
*/
private void checkStatusCode(HttpServletResponse response, AuthenticationContext context, String queryParams, String errorPage) throws AuthenticationFailedException {
boolean isRetryEnabled = SMSOTPUtils.isRetryEnabled(context, getName());
String loginPage = getLoginPage(context);
String url = getURL(loginPage, queryParams);
if (StringUtils.isNotEmpty(getScreenValue(context))) {
url = url + SMSOTPConstants.SCREEN_VALUE + getScreenValue(context);
}
try {
String statusCode = (String) context.getProperty(SMSOTPConstants.STATUS_CODE);
if (statusCode == null && isRetryEnabled) {
response.sendRedirect(url + SMSOTPConstants.RESEND_CODE + SMSOTPUtils.isEnableResendCode(context, getName()) + SMSOTPConstants.RETRY_PARAMS);
} else {
if (Boolean.parseBoolean((String) context.getProperty(SMSOTPConstants.CODE_MISMATCH)) && !isRetryEnabled) {
url = getURL(errorPage, queryParams);
response.sendRedirect(url + SMSOTPConstants.RESEND_CODE + SMSOTPUtils.isEnableResendCode(context, getName()) + SMSOTPConstants.ERROR_CODE_MISMATCH);
} else {
response.sendRedirect(url + SMSOTPConstants.RESEND_CODE + SMSOTPUtils.isEnableResendCode(context, getName()) + SMSOTPConstants.RETRY_PARAMS);
}
}
} catch (IOException e) {
throw new AuthenticationFailedException("Authentication Failed: An IOException was caught. ", e);
}
}
use of org.wso2.iot.integration.ui.pages.login.LoginPage in project identity-outbound-auth-sms-otp by wso2-extensions.
the class SMSOTPAuthenticator method redirectToMobileNoReqPage.
/**
* Redirect the user to mobile number request page.
*
* @param response the HttpServletResponse
* @param context the AuthenticationContext
* @param queryParams the queryParams
* @throws AuthenticationFailedException
*/
private void redirectToMobileNoReqPage(HttpServletResponse response, AuthenticationContext context, String queryParams) throws AuthenticationFailedException {
boolean isEnableMobileNoUpdate = SMSOTPUtils.isEnableMobileNoUpdate(context, getName());
if (isEnableMobileNoUpdate) {
String loginPage = SMSOTPUtils.getMobileNumberRequestPage(context, getName());
try {
String url = getURL(loginPage, queryParams);
if (log.isDebugEnabled()) {
log.debug("Redirecting to mobile number request page : " + url);
}
response.sendRedirect(url);
} catch (IOException e) {
throw new AuthenticationFailedException("Authentication failed!. An IOException was caught. ", e);
}
} else {
throw new AuthenticationFailedException("Authentication failed!. Update mobile no in your profile.");
}
}
use of org.wso2.iot.integration.ui.pages.login.LoginPage in project product-iots by wso2.
the class IOTHomePage method logout.
/**
* Performs the logout function.
* @return : IOT login page.
*/
public LoginPage logout() throws IOException {
driver.findElement(By.xpath(uiElementMapper.getElement("iot.user.registered.name"))).click();
WebElement logout = driver.findElement(By.xpath(uiElementMapper.getElement("iot.user.logout.link.xpath")));
logout.click();
return new LoginPage(driver);
}
use of org.wso2.iot.integration.ui.pages.login.LoginPage in project product-iots by wso2.
the class LoginTest method testAdminLogin.
@Test(description = "Verify logins to IOT server dashboard")
public void testAdminLogin() throws IOException, XPathExpressionException {
LoginPage loginPage = new LoginPage(driver);
IOTAdminDashboard dashboard = loginPage.loginAsAdmin(automationContext.getSuperTenant().getTenantAdmin().getUserName(), automationContext.getSuperTenant().getTenantAdmin().getPassword());
dashboard.logout();
}
Aggregations