boolean userLogin = false;
if (platformRequestWrapper.getOpenSocialViewerId() == null) {
log.warning("opensocial_viewer_id is null");
throw new RequestException(ReqErrorTypes.USER_NOT_LOGGEDIN);
}
if (!validateSignedRequestWithContainer(platformRequestWrapper)) {
userLogin = false;
throw new RequestException(ReqErrorTypes.USER_NOT_LOGGEDIN);
}
DomainUser domainUser = null;
domainUser = (DomainUser) platformRequestWrapper.getSession()
.getAttribute("domainUser");
if (domainUser != null
&& domainUser.getOauthConsumerKey().equals(
platformRequestWrapper.getOpenSocialConsumerKey())
&& domainUser.getOpensocialViewerId().equals(
platformRequestWrapper.getOpenSocialViewerId())) {
NamespaceManager.set(domainUser.getAccount());
return true;
}
else
domainUser = DomainUserUtils.getDomainUserByOpenSocial(platformRequestWrapper);
if (domainUser != null){
if (domainUser.getStatus() != DomainUserStatus.ACTIVE.getUserStatus())
throw new RequestException(ReqErrorTypes.USER_NOT_ACTIVE);
// set user in session
if (platformRequestWrapper != null && domainUser != null) {
platformRequestWrapper.getSession().setAttribute("domainUser",
domainUser);
NamespaceManager.set(domainUser.getAccount());
return true;
}
}
if (domainUser == null) {
// Registration
RegistrationToken token = null;
// 5 cases:
// - token is ready with both OAUTH + SIGNED - send registration url
// - token is ready for SIGNED and only SIGNED is needed - send
// registration url
// - token is already SIGNED created - send do to OAUTH
// - token is OAUTH created and id in the session - update SIGNED and
// send registration url
// - token is null. send request failed
String tokenId = null;
if (platformRequestWrapper.getRegistrationTokenId() != null) {
tokenId = platformRequestWrapper.getRegistrationTokenId();
try {
token = RegistrationTokenUtils.updateTokenForOpenSocial(
tokenId,
platformRequestWrapper.getOpenSocialViewerId(),
platformRequestWrapper.getOpenSocialConsumerKey());
} catch (Exception e) {
printStackTrace(e);
}
}
if (token == null) {
try {
token = RegistrationTokenUtils
.createNew(platformRequestWrapper);
platformRequestWrapper.getSession().setAttribute(SharedConstants.registrationTokenParamName,token.getTokenID());
} catch (Exception e) {
log.warning(e.getMessage());
}
}
if(token ==null)
log.warning("token is null we have a problem");
else if (token.isTokenReady())
jsonResponse.addCustomFieldError(
SharedConstants.registrationTokenParamName,
token.getTokenID());
else if (token.isOpenSocialReady() && userRegistrationMethod.equalsIgnoreCase(SharedConstants.registrationMethodSigned))
jsonResponse.addCustomFieldError(
SharedConstants.registrationTokenParamName,
token.getTokenID());
else if (!token.isOauthReady()){
jsonResponse.addCustomFieldError(
SharedConstants.registrationTokenParamName,
token.getTokenID());
jsonResponse.addCustomFieldError(SharedConstants.registrationProcessParamName, SharedConstants.registrationDoOAuth);
}
else
token =null;
if (token != null)
throw new RequestException(ReqErrorTypes.USER_NOT_REGISTERED);
else
throw new RequestException(ReqErrorTypes.REQUEST_FAILED);
}
return userLogin;
}