Skip to content

Commit

Permalink
Merge pull request #1706 from akto-api-security/hotfix/logs_saml_sso
Browse files Browse the repository at this point in the history
Added debug logs
  • Loading branch information
ankush-jain-akto authored Nov 8, 2024
2 parents ede964f + ad52aed commit 709ce08
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion apps/dashboard/src/main/java/com/akto/action/SignupAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -562,30 +562,36 @@ public String sendRequestToSamlIdP() throws IOException{
String emailId = Util.getValueFromQueryString(queryString, "email");
if(emailId.length() == 0){
code = "Error, user email cannot be empty";
logger.error(code);
servletResponse.sendRedirect("/login");
return ERROR.toUpperCase();
}
logger.info("Trying to sign in for: " + emailId);
setUserEmail(emailId);
SAMLConfig samlConfig = SSOConfigsDao.instance.getSSOConfig(userEmail);
if(samlConfig == null){
code = "Error, cannot login via SSO, redirecting to login";
logger.error(code);
servletResponse.sendRedirect("/login");
return ERROR.toUpperCase();
}
int tempAccountId = Integer.parseInt(samlConfig.getId());
logger.info("Account id: " + tempAccountId + " found for " + emailId);
setAccountId(tempAccountId);

Saml2Settings settings = null;
settings = CustomSamlSettings.getSamlSettings(samlConfig);

if(settings == null){
code= "Error, cannot find sso for this organization, redirecting to login";
logger.error(code);
return ERROR.toUpperCase();
}
try {
Auth auth = new Auth(settings, servletRequest, servletResponse);
String relayState = String.valueOf(tempAccountId);
auth.login(relayState);
logger.info("Initiated login from saml of " + userEmail);
} catch (Exception e) {
servletResponse.sendRedirect("/login");
return ERROR.toUpperCase();
Expand All @@ -597,15 +603,18 @@ public String registerViaAzure() throws Exception{
Auth auth;
try {
String tempAccountId = servletRequest.getParameter("RelayState");
logger.info("Account id found in registerViaAzure: " + tempAccountId);
if(tempAccountId == null || tempAccountId.isEmpty()){
loggerMaker.errorAndAddToDb("Account id not found");
return ERROR.toUpperCase();
}
setAccountId(Integer.parseInt(tempAccountId));
Saml2Settings settings = CustomSamlSettings.getSamlSettings(ConfigType.AZURE, this.accountId);
HttpServletRequest wrappedRequest = SsoUtils.getWrappedRequest(servletRequest,ConfigType.AZURE, this.accountId);
logger.info("Before sending request to Azure Idp");
auth = new Auth(settings, wrappedRequest, servletResponse);
auth.processResponse();
logger.info("After processing response from Azure Idp");
if (!auth.isAuthenticated()) {
loggerMaker.errorAndAddToDb("Error reason: " + auth.getLastErrorReason(), LogDb.DASHBOARD);
servletResponse.sendRedirect("/login");
Expand All @@ -620,13 +629,15 @@ public String registerViaAzure() throws Exception{
} else {
Map<String, List<String>> attributes = auth.getAttributes();
if (attributes.isEmpty()) {
logger.error("Returning as attributes were not found");
return ERROR.toUpperCase();
}
String nameId = auth.getNameId();
useremail = nameId;
username = nameId;
}
shouldLogin = "true";
logger.info("Successful signing with Azure Idp for: "+ useremail);
SignupInfo.SamlSsoSignupInfo signUpInfo = new SignupInfo.SamlSsoSignupInfo(username, useremail, Config.ConfigType.AZURE);
createUserAndRedirect(useremail, username, signUpInfo, this.accountId, Config.ConfigType.AZURE.toString(), RBAC.Role.MEMBER);
} catch (Exception e1) {
Expand Down Expand Up @@ -786,7 +797,7 @@ private void createUserAndRedirect(String userEmail, String username, SignupInfo
}

boolean isSSOLogin = Config.isConfigSSOType(signupInfo.getConfigType());

logger.info("Is sso login: " + isSSOLogin);
if (user == null) {

if (accountId == 0) {
Expand Down Expand Up @@ -814,6 +825,7 @@ private void createUserAndRedirect(String userEmail, String username, SignupInfo

} else if (StringUtils.isEmpty(code) && !isSSOLogin) {
if (accountId == 0) {
logger.info("Returning as accountId was found 0");
throw new IllegalStateException("The account doesn't exist.");
}
} else {
Expand Down

0 comments on commit 709ce08

Please sign in to comment.