问题描述:

I have created a login component that has a form and it has a POST action to a URL pointing to the siteminder URL https://test1-myuhc.uhc.com/siteminderagent/forms/login-aa.fcc

<input type="hidden" name="target" value="/bin/uhc/myuhcauthenticationhandler">

Inside the form the 'target' hidden field is where the siteminder forwards the request. The target that I have set here points to a Sling Servlet. The Servlet upon some kind of authentication does redirection to appropriate pages in AEM.The problem is when I submit the login button on the component the siteminder forwards request to https://test1-myuhc.uhc.com/bin/uhc/myuhcauthenticationhandler which gives a 404 error. When I set the target to some real page that exists under /content it works without any issue. What can I do to work this out.

Here is the code :

package com.myuhc.servlets;

import java.io.IOException;

import javax.servlet.ServletException;

import javax.servlet.http.Cookie;

import org.apache.felix.scr.annotations.Component;

import org.apache.felix.scr.annotations.Properties;

import org.apache.felix.scr.annotations.Property;

import org.apache.felix.scr.annotations.Reference;

import org.apache.felix.scr.annotations.Service;

import org.apache.felix.scr.annotations.sling.SlingServlet;

import org.apache.sling.api.SlingHttpServletRequest;

import org.apache.sling.api.SlingHttpServletResponse;

import org.apache.sling.api.servlets.SlingAllMethodsServlet;

import org.apache.sling.settings.SlingSettingsService;

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

// TODO: Auto-generated Javadoc

/**

* The Class LoginAuthenticationHandlerServlet.

*/

/*@SlingServlet(

paths={"/bin/myuhc/authenticationhandler"},

methods = {"POST","GET"},

metatype=true

)*/

@Component(immediate = true, metatype = true)

@Service

@Properties({

@Property(name = "sling.servlet.paths", value = "/bin/uhc/myuhcauthenticationhandler"),

@Property(name = "sling.servlet.methods", value = {"GET","POST"}) })

public class LoginAuthenticationHandlerServlet extends SlingAllMethodsServlet {

/** The Constant serialVersionUID. */

private static final long serialVersionUID = 1L;

/** The Constant log. */

private static final Logger log = LoggerFactory.getLogger(LoginAuthenticationHandlerServlet.class);

@Reference

private SlingSettingsService settingsService;

/* (non-Javadoc)

* @see org.apache.sling.api.servlets.SlingAllMethodsServlet#doPost(org.apache.sling.api.SlingHttpServletRequest, org.apache.sling.api.SlingHttpServletResponse)

*/

@Override

protected void doPost(SlingHttpServletRequest request,SlingHttpServletResponse response) {

try {

if (settingsService.getRunModes().contains("publish")) {

//response.setStatus(HttpServletResponse.SC_OK);

response.setContentType("text/plain");

Cookie[] cookies = request.getCookies();

String cookieValue = null;

String uhcRole = null;

String uhcaccountstatus = null;

String url = null;

String LOGIN_PAGE = "/content/myuhc/en/myuhc-login-page.html";

String HOME_PAGE = "/content/myuhc/en/myuhc-home-page.html";

//getting headers

uhcRole = request.getHeader("uhcRole");

uhcaccountstatus = request.getHeader("uhcaccountstatus");

//getting SMRESPONSECODE cookie set by Siteminder

if (cookies !=null) {

for (Cookie cookie : cookies) {

if(cookie.getName().equals("SMRESPONSECODE")) {

cookieValue = cookie.getValue();

}

// TODO:: Needs to be validated

cookie.setMaxAge(-1);

}

//Setting the URL by checking the different conditions

if (cookieValue !=null) {

if (cookieValue.equals("1")) {

request.setAttribute("message", "Member not found");

url = LOGIN_PAGE;

}

else if(cookieValue.equals("2")) {

request.setAttribute("message", "Wrong password. Please try again.");

url = LOGIN_PAGE;

}

else if((uhcaccountstatus!=null) && !uhcaccountstatus.equals("A") && cookieValue.equals("3")) {

request.setAttribute("message", "Member not found");

url = LOGIN_PAGE;

}

else if((uhcaccountstatus!=null) && (uhcRole!=null) && !uhcRole.equals("employer") && uhcaccountstatus.equals("A") && cookieValue.equals("0")) {

url = HOME_PAGE;

}

else if((uhcRole!=null) && uhcRole.equals("employer") && cookieValue.equals("4")) {

url = HOME_PAGE;

}

else if (cookieValue.equals("5") || cookieValue.equals("6")) {

request.setAttribute("message", "Member not found or Wrong password");

url = LOGIN_PAGE;

}

}else {

log.info("No Cookies found!");

}

}

//Forwarding the request to the url set above

request.getRequestDispatcher(url).forward(request, response);

}

}

catch (ServletException e) {

log.info("Inside ServletException -->"+e.getMessage());

}

catch (IOException e) {

log.info("Inside IOException -->"+e.getMessage());

}

}

/* (non-Javadoc)

* @see org.apache.sling.api.servlets.SlingAllMethodsServlet#doGet(org.apache.sling.api.SlingHttpServletRequest, org.apache.sling.api.SlingHttpServletResponse)

*/

@Override

protected void doGet(SlingHttpServletRequest request,SlingHttpServletResponse response) {

try {

if (settingsService.getRunModes().contains("publish")) {

//response.setStatus(HttpServletResponse.SC_OK);

response.setContentType("text/plain");

Cookie[] cookies = request.getCookies();

String cookieValue = null;

String uhcRole = null;

String uhcaccountstatus = null;

String url = null;

String LOGIN_PAGE = "/content/myuhc/en/myuhc-login-page.html";

String HOME_PAGE = "/content/myuhc/en/myuhc-home-page.html";

//getting headers

uhcRole = request.getHeader("uhcRole");

uhcaccountstatus = request.getHeader("uhcaccountstatus");

//getting SMRESPONSECODE cookie set by Siteminder

if (cookies !=null) {

for (Cookie cookie : cookies) {

if(cookie.getName().equals("SMRESPONSECODE")) {

cookieValue = cookie.getValue();

}

// TODO:: Needs to be validated

cookie.setMaxAge(-1);

}

//Setting the URL by checking the different conditions

if (cookieValue !=null) {

if (cookieValue.equals("1")) {

request.setAttribute("message", "Member not found");

url = LOGIN_PAGE;

}

else if(cookieValue.equals("2")) {

request.setAttribute("message", "Wrong password. Please try again.");

url = LOGIN_PAGE;

}

else if((uhcaccountstatus!=null) && !uhcaccountstatus.equals("A") && cookieValue.equals("3")) {

request.setAttribute("message", "Member not found");

url = LOGIN_PAGE;

}

else if((uhcaccountstatus!=null) && (uhcRole!=null) && !uhcRole.equals("employer") && uhcaccountstatus.equals("A") && cookieValue.equals("0")) {

url = HOME_PAGE;

}

else if((uhcRole!=null) && uhcRole.equals("employer") && cookieValue.equals("4")) {

url = HOME_PAGE;

}

else if (cookieValue.equals("5") || cookieValue.equals("6")) {

request.setAttribute("message", "Member not found or Wrong password");

url = LOGIN_PAGE;

}

}else {

log.info("No Cookies found!");

}

}

//Forwarding the request to the url set above

request.getRequestDispatcher(url).forward(request, response);

}

}

catch (ServletException e) {

log.info("Inside ServletException -->"+e.getMessage());

}

catch (IOException e) {

log.info("Inside IOException -->"+e.getMessage());

}

}

}

and here is the form

<form id="site-login" method="post" action="https://test1-myuhc.uhc.com/siteminderagent/forms/login-aa.fcc">

<fieldset class="borderless">

<legend class="hide-text">

${xss:encodeForHTML(xssAPI, loginTitle)}

</legend>

<div>

<label for="username" class="micro strong label--inline">${xss:encodeForHTML(xssAPI, usrnamelbl)}</label>

<input type="text" id="username" name="USER" class="input--login" />

</div>

<div>

<label for="password" class="micro strong label--inline">${xss:encodeForHTML(xssAPI, pswrdlbl)}</label>

<input type="password" id="password" name="PASSWORD" class="input--login" />

</div>

<button class="button--blue milli float-right">${xss:encodeForHTML(xssAPI, btnlbl)}</button>

</fieldset>

<input type="hidden" name="IDToken0" value="">

<input type="hidden" name="SMENC" value="ISO-8859-1">

<input type="hidden" name="SMLOCALE" value="en-us">

<input type="hidden" name="target" value="/bin/uhc/myuhcauthenticationhandler">

<input type="hidden" name="theme" value="myuhc">

</form>

Thanks in advance

相关阅读:
Top