Commit 062e43f0 by Nilu Committed by Harsh Shah

social media login for applicant portal

parent 09fa47d6
package performa.utils;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpSession;
import oneit.components.*;
import oneit.logging.LogLevel;
import oneit.logging.LogMgr;
import oneit.logging.LoggingArea;
import oneit.objstore.ObjectTransaction;
import oneit.objstore.services.TransactionServicesFactory;
import oneit.security.Role;
import oneit.security.SecUser;
import oneit.security.oauth.decorator.OAuthCallbackDecorator;
import oneit.security.oauth.utils.BaseOAuthLoginHandler;
import oneit.servlets.security.SessionSecUserDecorator;
import oneit.servlets.utils.BaseHttpServletRequest;
import oneit.servlets.utils.BaseHttpServletResponse;
import oneit.servlets.utils.decorator.ServletDecorator;
import oneit.servlets.utils.decorator.ServletDecoratorConfig;
import oneit.utils.*;
import performa.orm.Candidate;
/**
* This is almost similar class to OAuthCallbackDecorator,
* except setup user extensions using redirect URL before redirect request.
*
* @see OAuthCallbackDecorator
*/
public class PerformaOAuthCallbackDecorator implements ServletDecorator, InitialisationParticipant
{
private LoggingArea LOG = LoggingArea.createLoggingArea("OAuthCallbackDecorator");
private TransactionServicesFactory servicesFactory;
public static final String REDIRECT_URL_ATTRIB_NAME = "oauth.returnURL";
public static final String TOKEN_ATTRIB_NAME = "oauth.token";
public static final String ACCESS_DENY_URL_ATTRIB_NAME = "oauth.accessDenyURL";
public static final String ACCESS_DENY_ERROR_KEY = "oauth.accessDenyError";
/**
* Map <Callback Service, Callback Handler>
*/
public Map handlerMap;
@Override
public void processRequest (ServletDecoratorConfig config, BaseHttpServletRequest request, BaseHttpServletResponse response) throws Exception
{
String callbackURL = request.getServletPath();
HttpSession session = request.getSession();
try
{
LogMgr.log(LOG, LogLevel.DEBUG1, "Entering into OAuthCallbackDecorator");
if(handlerMap != null && handlerMap.containsKey(callbackURL))
{
LogMgr.log(LOG, LogLevel.PROCESSING1, "Catching in OAuthCallbackDecorator RE for callback :: ", callbackURL);
BaseOAuthLoginHandler loginHandler = (BaseOAuthLoginHandler)handlerMap.get(callbackURL);
// Validate request is authorized or not.
loginHandler.validateRequest(request);
// Create or Get Login user from oauth process
ObjectTransaction transaction = new ObjectTransaction (servicesFactory);
String fullURL = (String)session.getAttribute(REDIRECT_URL_ATTRIB_NAME);
try
{
SecUser secUser = loginHandler.getOrCreateSecuser(request, transaction);
if(fullURL.contains(WebUtils.APPLICANT_PORTAL))
{
secUser.addRole(Role.searchNAME(secUser.getTransaction(), Utils.ROLE_APPLICANT));
Candidate candidate = secUser.getExtensionOrCreate(Candidate.REFERENCE_Candidate);
candidate.setUser(secUser);
}
else if(fullURL.contains(WebUtils.ADMIN_PORTAL))
{
secUser.addRole(Role.searchNAME(secUser.getTransaction(), Utils.ROLE_CLIENT));
}
transaction.commit();
transaction.commitResources();
// Store user in session for login.
session.setAttribute(SecUser.SEC_USER_ID, secUser);
session.setAttribute(SessionSecUserDecorator.REFRESH_SECURITY, Boolean.TRUE);
}
finally
{
transaction.releaseResources();
}
LogMgr.log(LOG, LogLevel.PROCESSING1, "Redirecting user to next page after login. ", fullURL);
if(fullURL == null || fullURL.isEmpty())
{
LogMgr.log(LOG, LogLevel.PROCESSING1, "Can't find returnURL in Session.");
config.forwardRequest(request, response);
return;
}
// Redirect user on next page after login
request.setAttribute ("DecoratorFilter.TERMINATE", "YES");
LogMgr.log(LOG, LogLevel.PROCESSING1, "Redirecting form OAuthCallbackDecorator ON :: " + fullURL);
response.sendRedirect(fullURL);
return;
}
LogMgr.log(LOG, LogLevel.DEBUG1, "Exit from OAuthCallbackDecorator");
config.forwardRequest(request, response);
}
catch(Exception e)
{
if (e instanceof BaseOAuthLoginHandler.LoadProfileException)
{
LogMgr.log(LOG, LogLevel.PROCESSING1, e);
Map<String, String> paramsMap = getURLParams((String)session.getAttribute(REDIRECT_URL_ATTRIB_NAME));
if (StringUtils.subBlanks(paramsMap.get(ACCESS_DENY_URL_ATTRIB_NAME)) == null)
{
throw new NestedException(e);
}
request.setAttribute ("DecoratorFilter.TERMINATE", "YES");
session.setAttribute(ACCESS_DENY_ERROR_KEY, e.getMessage());
response.sendRedirect(paramsMap.get(ACCESS_DENY_URL_ATTRIB_NAME));
return;
}
LogMgr.log(LOG, LogLevel.SYSTEMERROR1, e, "Error occurred during decorator filter.");
throw NestedException.wrap(e);
}
finally
{
session.removeAttribute(TOKEN_ATTRIB_NAME);
session.removeAttribute(REDIRECT_URL_ATTRIB_NAME);
}
}
@Override
public void init(ParticipantInitialisationContext context) throws InitialisationException
{
context.setObject(this);
handlerMap = context.getChildMap("Handler");
}
/**
* Get request parameters as a map, from given URL.
*
* @param urlString
* @return
*/
public static Map<String, String> getURLParams(String urlString)
{
Map<String,String> urlParamsMap = new HashMap<String, String>();
URL url;
try
{
url = new URL(urlString);
}
catch (MalformedURLException ex)
{
LogMgr.log(LoggingArea.ALL, LogLevel.SYSTEMERROR1, ex, "\n Malformed URL:" + urlString);
return urlParamsMap;
}
String[] params = url.getQuery() != null ? url.getQuery().split("&") : new String[] {};
for (String param: params)
{
String key = param.substring(0, param.indexOf('='));
urlParamsMap.put( key, param.substring(param.indexOf('=') + 1));
}
return urlParamsMap;
}
}
......@@ -11,8 +11,6 @@ public class PerformaSetupUserHelper extends SetupUserHelper
public void setUpDefaultRole(SecUser secUser)
{
LogMgr.log(LoggingArea.ALL, LogLevel.PROCESSING1, "Inside setUpDefaultRole in PerformaSetupUserHelper for ", secUser);
secUser.addRole(Role.searchNAME(secUser.getTransaction(), Utils.ROLE_CLIENT));
}
@Override
......@@ -24,7 +22,6 @@ public class PerformaSetupUserHelper extends SetupUserHelper
@Override
public void setUpDefaultExtensions(SecUser secUser)
{
//TODO: Handle Company login
LogMgr.log(LoggingArea.ALL, LogLevel.PROCESSING1, "Inside setUpDefaultExtensions in PerformaSetupUserHelper for ", secUser);
}
}
......@@ -78,9 +78,10 @@
<NODE name="SetupUserHelper" factory="Participant" class="performa.utils.PerformaSetupUserHelper"/>
<NODE name="DecoratorFilter::ADMIN_PORTAL">
<DECORATOR factory="Participant" class="oneit.security.oauth.decorator.OAuthCallbackDecorator">
<DECORATOR factory="Participant" class="performa.utils.PerformaOAuthCallbackDecorator">
<NODE name="servicesFactory" factory="ConfigMgr" system="CONFIG.GLOBAL" paramname="TransactionServices" />
......
......@@ -13,16 +13,17 @@
<FORM name="*.sendVerificationMail" factory="Participant" class="performa.form.SendVerificationMailFP">
<AccountVerificationEmailer factory="Participant" class="oneit.email.ConfigurableArticleTemplateEmailer" templateShortcut="AccountVerificationMail"/>
</FORM>
<FORM name="*.facebookOAuthLogin" factory="Participant" class="oneit.security.oauth.form.FacebookOAuthLoginFP"/>
<FORM name="*.googleOAuthLogin" factory="Participant" class="oneit.security.oauth.form.GoogleOAuthLoginFP"/>
<!--<FORM name="*.linkedinOAuthLogin" factory="Participant" class="performa.form.LinkedInOAuthLoginFP"/>-->
</NODE>
<NODE name="dynamic_content_form_applicant" factory="Participant">
<INHERITS factory="Named" nodename="dynamic_content_form"/>
<DECORATOR id="auth" factory="MetaComponent" component="ApplicantPortalAuthDecorator" priv="TL_AccessApplicantPortal"/>
</NODE>
<NODE name="ApplicantPortalAuthDecorator" factory="Participant" class="oneit.servlets.utils.decorator.AuthenticatorDecorator">
<AUTHENTICATOR factory="Participant" class="oneit.security.SecurityAuthenticator">
<PRIVILEGE factory="Parameter" param="priv"/>
......
......@@ -17,12 +17,14 @@
}
Debug.assertion(job != null, "Job is null in applicant portal");
String socialLoginNextPage = nextPage + "&JobID=" + job.getID().toString();
%>
<script type="text/javascript">
$(document.body).addClass('bg-color');
$(document).ready(function() {
recalcFunction = setupRecalc ($("form"), {'recalcOnError':true});
recalcFunction = setupRecalc ($("#applyJob"), {'recalcOnError':true});
$('#applyJob').on('keyup keypress', function(e) {
var keyCode = e.keyCode || e.which;
......@@ -76,10 +78,6 @@
}
</style>
<oneit:form name="applyJob" method="post" enctype="multipart/form-data">
<oneit:dynInclude page="/extensions/applicantportal/inc/multifieldtext.jsp" data="<%= CollectionUtils.EMPTY_MAP%>"/>
<div class="main-verify-identity">
<div class="verify-aust-logo"><img src="images/australia-post.png"></div>
<div class="pl-verify">Please verify your identity before applying to:</div>
......@@ -87,15 +85,39 @@
<oneit:toString value="<%= job.getPageTitle() %>" mode="EscapeHTML"/>
</div>
<div class="main-box-layout verify-i-setpone">
<!-- <div class="box-label">Sign in using your social network of choice</div>
<div class="box-label">Sign in using your social network of choice</div>
<oneit:form name="socialLogin" method="post">
<ul class="social-login">
<li><a href="#"><img src="images/login-linkedin-icon.svg"></a></li>
<li><a href="#"><img src="images/login-facebok-icon.svg"></a></li>
<li><a href="#"><img src="images/login-google.png"></a></li>
<li>
<oneit:button value=" " name="linkedinOAuthLogin" skin="link" cssClass="social_login_btn"
requestAttribs="<%= CollectionUtils.mapEntry ("nextPage", socialLoginNextPage).toMap() %>">
<img src="<%= request.getContextPath() %>/images/login-linkedin-icon.svg" />
</oneit:button>
</li>
<li>
<oneit:button value=" " name="facebookOAuthLogin" skin="link" cssClass="social_login_btn"
requestAttribs="<%= CollectionUtils.mapEntry ("nextPage", socialLoginNextPage).toMap() %>">
<img src="<%= request.getContextPath() %>/images/login-facebok-icon.svg" />
</oneit:button>
</li>
<li>
<oneit:button value=" " name="googleOAuthLogin" skin="link" cssClass="social_login_btn"
requestAttribs="<%= CollectionUtils.mapEntry ("nextPage", socialLoginNextPage).toMap() %>">
<img src="<%= request.getContextPath() %>/images/login-google.png" />
</oneit:button>
</li>
</ul>
<div class="box-br-line"><span></span></div>-->
<!--<div class="box-label">Or sign in via email</div>-->
<div class="box-label">Sign in via email</div>
</oneit:form>
<div class="box-br-line"><span></span></div>
<oneit:form name="applyJob" method="post" enctype="multipart/form-data">
<oneit:dynInclude page="/extensions/applicantportal/inc/multifieldtext.jsp" data="<%= CollectionUtils.EMPTY_MAP%>"/>
<div class="box-label">Or sign in via email</div>
<div class="form-group text-left" id="email-div">
<label>Email Address</label>
<oneit:ormInput obj="<%= job %>" type="text" attributeName="Email" cssClass="form-control second-style" style="text-transform: lowercase"/>
......@@ -130,7 +152,7 @@
.toMap() %>"/>
</div>
</oneit:recalcClass>
</oneit:form>
</div>
</div>
</oneit:form>
</oneit:dynIncluded>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment