use of com.sun.identity.federation.message.common.OldProvidedNameIdentifier in project OpenAM by OpenRock.
the class FSNameRegistrationRequest method parseURLEncodedRequest.
/**
* Returns <code>FSNameRegistrationRequest</code> object. The
* object is creating by parsing the <code>HttpServletRequest</code>
* object.
*
* @param request the <code>HttpServletRequest</code> object.
* @throws FSMsgException if there is an error
* creating this object.
* @throws SAMLException if there is an error.
*/
public static FSNameRegistrationRequest parseURLEncodedRequest(HttpServletRequest request) throws FSMsgException, SAMLException {
FSNameRegistrationRequest retNameRegistrationRequest = new FSNameRegistrationRequest();
try {
FSUtils.debug.message("checking minor version");
retNameRegistrationRequest.majorVersion = Integer.parseInt(request.getParameter("MajorVersion"));
retNameRegistrationRequest.minorVersion = Integer.parseInt(request.getParameter("MinorVersion"));
} catch (NumberFormatException ex) {
FSUtils.debug.error("FSNameRegistrationRequest.parseURLEncoded" + "Request: Invalid versions", ex);
throw new FSMsgException("invalidNumber", null);
}
FSUtils.debug.message("checking RequestID");
if (request.getParameter("RequestID") != null) {
retNameRegistrationRequest.requestID = request.getParameter("RequestID");
} else {
FSUtils.debug.error("FSNameRegistrationRequest.parseURLEncoded" + "Request: RequestID not found");
String[] args = { IFSConstants.REQUEST_ID };
throw new FSMsgException("missingAttribute", args);
}
FSUtils.debug.message("checking instantString");
String instantString = request.getParameter("IssueInstant");
FSUtils.debug.message("instantString : " + instantString);
if (instantString == null || instantString.length() == 0) {
FSUtils.debug.error("FSNameRegistrationRequest.parseURLEncoded" + "Request: IssueInstant not found");
String[] args = { IFSConstants.ISSUE_INSTANT };
throw new FSMsgException("missingAttribute", args);
}
try {
FSUtils.debug.message("calling : DateUtils.stringToDate.issueInstant");
retNameRegistrationRequest.issueInstant = DateUtils.stringToDate(instantString);
} catch (ParseException e) {
FSUtils.debug.error("FSNameRegistrationRequest.parseURLEncoded" + "Request: Can not parse IssueInstant", e);
throw new FSMsgException("parseError", null);
}
if (request.getParameter("ProviderID") != null) {
retNameRegistrationRequest.providerId = request.getParameter("ProviderID");
} else {
FSUtils.debug.error("FSNameRegistrationRequest.parseURLEncoded" + "Request: Can not find ProviderID");
throw new FSMsgException("missingElement", null);
}
FSUtils.debug.message("start identifier processing");
String spNameFormat = "";
String spNameQualifier = "";
String spName = "";
if (request.getParameter("SPNameFormat") != null) {
spNameFormat = request.getParameter("SPNameFormat");
}
if (request.getParameter("SPNameQualifier") != null) {
spNameQualifier = request.getParameter("SPNameQualifier");
}
if (request.getParameter("SPProvidedNameIdentifier") != null) {
spName = request.getParameter("SPProvidedNameIdentifier");
}
if (spName != null && !(spName.length() < 1)) {
retNameRegistrationRequest.setSPProvidedNameIdentifier(new SPProvidedNameIdentifier(spName, spNameQualifier, spNameFormat));
}
String idpNameFormat = null;
String idpNameQualifier = null;
String idpName = null;
if (request.getParameter("IDPNameFormat") != null) {
idpNameFormat = request.getParameter("IDPNameFormat");
}
if (request.getParameter("IDPNameQualifier") != null) {
idpNameQualifier = request.getParameter("IDPNameQualifier");
}
if (request.getParameter("IDPProvidedNameIdentifier") != null) {
idpName = request.getParameter("IDPProvidedNameIdentifier");
}
if (idpName != null && !(idpName.length() < 1)) {
retNameRegistrationRequest.idpProvidedNameIdentifier = new IDPProvidedNameIdentifier(idpName, idpNameQualifier, idpNameFormat);
}
String oldNameFormat = null;
String oldNameQualifier = null;
String oldName = null;
if (request.getParameter("OldNameFormat") != null) {
oldNameFormat = request.getParameter("OldNameFormat");
}
if (request.getParameter("OldNameQualifier") != null) {
oldNameQualifier = request.getParameter("OldNameQualifier");
}
if (request.getParameter("OldProvidedNameIdentifier") != null) {
oldName = request.getParameter("OldProvidedNameIdentifier");
}
if (oldName != null && !(oldName.length() < 1)) {
retNameRegistrationRequest.oldProvidedNameIdentifier = new OldProvidedNameIdentifier(oldName, oldNameQualifier, oldNameFormat);
}
if (request.getParameter("RelayState") != null) {
retNameRegistrationRequest.relayState = request.getParameter("RelayState");
}
return retNameRegistrationRequest;
}
use of com.sun.identity.federation.message.common.OldProvidedNameIdentifier in project OpenAM by OpenRock.
the class FSNameRegistrationHandler method setUserDN.
/**
* Determines the user based on the registration request received from
* a remote provider.
* @param regisRequest the name registration request
* @return <code>true</code> a user is found; <code>false</code> otherwise.
*/
public boolean setUserDN(FSNameRegistrationRequest regisRequest) {
try {
/**
* UserDN needs to be figured from registration request
* 1. If OldNameIdentifier does not exist then its from SP to IdP
* (first time)
* 2. If OldNameIdentifier exist then we could be SP, IdP
* Need to find out whether to replace with SPNI or IDPNI based on
* acctFedInfo that is retrieved based on OldNameIdentifier or
* IdpNameIdentifier
* If isIDP true then remote is IdP so replace remoteIdentifier
* with IDPNameIdentifier.
* If isIDP false then remote is SP so replace remoteIdentifier
* with SPNameIdentifier
*/
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("remoteEntityId : " + remoteEntityId);
}
Map env = new HashMap();
env.put(IFSConstants.FS_USER_PROVIDER_ENV_REGISTRATION_KEY, regisRequest);
OldProvidedNameIdentifier oldNameIdentifier = regisRequest.getOldProvidedNameIdentifier();
IDPProvidedNameIdentifier idpNameIdentifier = regisRequest.getIDPProvidedNameIdentifier();
SPProvidedNameIdentifier spNameIdentifier = regisRequest.getSPProvidedNameIdentifier();
if (oldNameIdentifier == null) {
FSUtils.debug.message("oldProvidedNameIdentifier is null :");
String opaqueHandle = idpNameIdentifier.getName();
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("processRegistrationRequest IdPName : " + opaqueHandle);
}
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("Realm : " + realm);
}
String searchDomain = hostedEntityId;
String nameQualifier = idpNameIdentifier.getNameQualifier();
if (nameQualifier != null && (nameQualifier.length() != 0) && !nameQualifier.equals(remoteEntityId)) {
searchDomain = nameQualifier;
}
FSAccountFedInfoKey acctkey = new FSAccountFedInfoKey(searchDomain, opaqueHandle);
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("Search based on:" + hostedEntityId + opaqueHandle);
}
this.userID = managerInst.getUserID(acctkey, realm, env);
if (this.userID == null) {
FSUtils.debug.message("UserID is null");
return false;
}
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("user id is " + userID);
}
try {
acctInfo = managerInst.readAccountFedInfo(userID, remoteEntityId, opaqueHandle);
} catch (FSAccountMgmtException e) {
FSUtils.debug.message("Failed to read account information");
return false;
}
newAcctInfo = new FSAccountFedInfo(remoteEntityId, idpNameIdentifier, spNameIdentifier, false);
newAcctInfo.setAffiliation(acctInfo.getAffiliation());
newAcctKey = new FSAccountFedInfoKey(searchDomain, idpNameIdentifier.getName());
return true;
} else {
FSUtils.debug.message("oldProvidedNameIdentifier not null");
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("Realm : " + realm);
}
String opaqueHandle = "";
String nameQualifier = null;
boolean isSPEmpty = false;
String searchDomain = hostedEntityId;
if (spNameIdentifier != null && !(spNameIdentifier.equals(oldNameIdentifier))) {
opaqueHandle = spNameIdentifier.getName();
nameQualifier = spNameIdentifier.getNameQualifier();
} else {
isSPEmpty = true;
opaqueHandle = idpNameIdentifier.getName();
nameQualifier = idpNameIdentifier.getNameQualifier();
}
if (nameQualifier != null && (nameQualifier.length() != 0) && !nameQualifier.equals(hostedEntityId)) {
searchDomain = nameQualifier;
}
FSAccountFedInfoKey acctkey = new FSAccountFedInfoKey(searchDomain, opaqueHandle);
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("Search based on :" + searchDomain + " " + opaqueHandle);
}
this.userID = managerInst.getUserID(acctkey, realm, env);
if (this.userID == null) {
FSUtils.debug.message("UserID is null in step 3");
opaqueHandle = idpNameIdentifier.getName();
nameQualifier = idpNameIdentifier.getNameQualifier();
if (nameQualifier != null && (nameQualifier.length() != 0) && !nameQualifier.equals(hostedEntityId)) {
searchDomain = nameQualifier;
}
acctkey = new FSAccountFedInfoKey(searchDomain, opaqueHandle);
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("Search based on :" + searchDomain + " " + opaqueHandle);
}
this.userID = managerInst.getUserID(acctkey, realm, env);
if (this.userID == null) {
opaqueHandle = idpNameIdentifier.getName();
searchDomain = hostedEntityId;
acctkey = new FSAccountFedInfoKey(searchDomain, opaqueHandle);
this.userID = managerInst.getUserID(acctkey, realm, env);
if (this.userID == null) {
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("UserID is null in " + "step 4");
}
opaqueHandle = oldNameIdentifier.getName();
searchDomain = oldNameIdentifier.getNameQualifier();
if ((searchDomain != null) && (searchDomain.length() != 0)) {
acctkey = new FSAccountFedInfoKey(searchDomain, opaqueHandle);
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("Search based on :" + searchDomain + " " + opaqueHandle);
}
this.userID = managerInst.getUserID(acctkey, realm, env);
}
}
if (this.userID == null) {
return false;
} else {
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("Found user : " + userID);
}
acctInfo = managerInst.readAccountFedInfo(userID, searchDomain, opaqueHandle);
if (acctInfo == null || !acctInfo.isFedStatusActive()) {
acctInfo = managerInst.readAccountFedInfo(userID, remoteEntityId, opaqueHandle);
}
if (acctInfo.isRoleIDP()) {
if (isSPEmpty) {
// set spNI to null since is empty
newAcctInfo = new FSAccountFedInfo(remoteEntityId, null, idpNameIdentifier, acctInfo.isRoleIDP());
newAcctInfo.setAffiliation(acctInfo.getAffiliation());
newAcctKey = new FSAccountFedInfoKey(searchDomain, idpNameIdentifier.getName());
} else {
newAcctInfo = new FSAccountFedInfo(remoteEntityId, spNameIdentifier, idpNameIdentifier, acctInfo.isRoleIDP());
newAcctInfo.setAffiliation(acctInfo.getAffiliation());
newAcctKey = new FSAccountFedInfoKey(searchDomain, spNameIdentifier.getName());
}
} else {
newAcctInfo = new FSAccountFedInfo(remoteEntityId, idpNameIdentifier, spNameIdentifier, acctInfo.isRoleIDP());
newAcctInfo.setAffiliation(acctInfo.getAffiliation());
newAcctKey = new FSAccountFedInfoKey(hostedEntityId, idpNameIdentifier.getName());
}
}
} else {
acctInfo = managerInst.readAccountFedInfo(userID, searchDomain, opaqueHandle);
if (acctInfo == null || !acctInfo.isFedStatusActive()) {
acctInfo = managerInst.readAccountFedInfo(userID, remoteEntityId, opaqueHandle);
}
newAcctInfo = new FSAccountFedInfo(remoteEntityId, idpNameIdentifier, spNameIdentifier, false);
newAcctInfo.setAffiliation(acctInfo.getAffiliation());
newAcctKey = new FSAccountFedInfoKey(searchDomain, idpNameIdentifier.getName());
}
} else {
acctInfo = managerInst.readAccountFedInfo(userID, searchDomain, opaqueHandle);
if (acctInfo == null || !acctInfo.isFedStatusActive()) {
acctInfo = managerInst.readAccountFedInfo(userID, remoteEntityId, opaqueHandle);
}
if (acctInfo.isRoleIDP()) {
if (isSPEmpty) {
// set spNI to null since is empty
newAcctInfo = new FSAccountFedInfo(remoteEntityId, null, idpNameIdentifier, acctInfo.isRoleIDP());
newAcctInfo.setAffiliation(acctInfo.getAffiliation());
newAcctKey = new FSAccountFedInfoKey(remoteEntityId, idpNameIdentifier.getName());
} else {
newAcctInfo = new FSAccountFedInfo(remoteEntityId, spNameIdentifier, idpNameIdentifier, acctInfo.isRoleIDP());
newAcctInfo.setAffiliation(acctInfo.getAffiliation());
newAcctKey = new FSAccountFedInfoKey(hostedEntityId, spNameIdentifier.getName());
}
} else {
newAcctInfo = new FSAccountFedInfo(remoteEntityId, idpNameIdentifier, spNameIdentifier, acctInfo.isRoleIDP());
newAcctInfo.setAffiliation(acctInfo.getAffiliation());
newAcctKey = new FSAccountFedInfoKey(hostedEntityId, idpNameIdentifier.getName());
}
}
}
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("user id is " + userID);
}
return true;
} catch (FSAccountMgmtException e) {
FSUtils.debug.error("In FSNameRegistrationHandler::setUserID: ", e);
}
this.userID = null;
return false;
}
use of com.sun.identity.federation.message.common.OldProvidedNameIdentifier in project OpenAM by OpenRock.
the class FSNameRegistrationHandler method createNameRegistrationRequest.
/**
* Generates the Name Registration request.
* @return FSNameRegistrationRequest
*/
private FSNameRegistrationRequest createNameRegistrationRequest(FSAccountFedInfo acctInfo) {
try {
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("Entered FSNameRegistrationHandler:: " + "createNameRegistrationRequest");
}
FSNameRegistrationRequest reqName = new FSNameRegistrationRequest();
if (reqName != null) {
reqName.setProviderId(hostedEntityId);
if (acctInfo.isRoleIDP()) {
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("calling of generateNameIdentifier Role : IdP ? " + acctInfo.isRoleIDP());
}
NameIdentifier nameIdentifier = generateNameIdentifier();
if (acctInfo.getAffiliation()) {
String affiliationID = FSServiceUtils.getAffiliationID(realm, remoteEntityId);
if (affiliationID != null) {
nameIdentifier.setNameQualifier(affiliationID);
}
} else {
nameIdentifier.setNameQualifier(hostedEntityId);
}
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("out of generateNameIdentifier ****" + "\nNew SP nameIdentifier Qualifier: " + nameIdentifier.getNameQualifier() + "\nNew SP nameIdentifier Name :" + nameIdentifier.getName());
}
SPProvidedNameIdentifier newNameIdenifier = new SPProvidedNameIdentifier(nameIdentifier.getName(), nameIdentifier.getNameQualifier(), nameIdentifier.getFormat());
NameIdentifier remoteIdentifier = acctInfo.getRemoteNameIdentifier();
NameIdentifier localIdentifier = acctInfo.getLocalNameIdentifier();
reqName.setIDPProvidedNameIdentifier(new IDPProvidedNameIdentifier(remoteIdentifier.getName(), remoteIdentifier.getNameQualifier(), remoteIdentifier.getFormat()));
reqName.setSPProvidedNameIdentifier(newNameIdenifier);
if (localIdentifier != null) {
reqName.setOldProvidedNameIdentifier(new OldProvidedNameIdentifier(localIdentifier.getName(), localIdentifier.getNameQualifier(), localIdentifier.getFormat()));
try {
oldAcctKey = new FSAccountFedInfoKey(localIdentifier.getNameQualifier(), localIdentifier.getName());
} catch (FSAccountMgmtException e) {
oldAcctKey = null;
}
} else {
// when Service Provider sends the name reg. request
// for the first time, OldProvidedNameIdentifier is
// same as the IDPProvidedNameIdentifier as per the spec
reqName.setOldProvidedNameIdentifier(new OldProvidedNameIdentifier(remoteIdentifier.getName(), remoteIdentifier.getNameQualifier(), remoteIdentifier.getFormat()));
try {
oldAcctKey = new FSAccountFedInfoKey(remoteIdentifier.getNameQualifier(), remoteIdentifier.getName());
} catch (FSAccountMgmtException e) {
oldAcctKey = null;
}
}
try {
FSAccountFedInfoKey tmpKey = new FSAccountFedInfoKey(nameIdentifier.getNameQualifier(), nameIdentifier.getName());
FSAccountFedInfo tmpInfo = new FSAccountFedInfo(remoteEntityId, newNameIdenifier, remoteIdentifier, acctInfo.isRoleIDP());
tmpInfo.setAffiliation(acctInfo.getAffiliation());
returnMap.put("userID", userID);
returnMap.put("OldAccountKey", oldAcctKey);
if (oldAcctKey != null) {
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("Get OldAcctKet Name : " + oldAcctKey.getName() + "\nGet OldAcctKet Qualifier : " + oldAcctKey.getNameSpace());
}
} else {
FSUtils.debug.message("OldAccount Key is null");
}
returnMap.put("AccountKey", tmpKey);
returnMap.put("AccountInfo", tmpInfo);
returnMap.put("RegisSource", regisSource);
returnMap.put(IFSConstants.LRURL, returnURL);
} catch (FSAccountMgmtException e) {
return null;
}
} else {
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("calling of generateNameIdenti" + "fier Role : IdP ? " + acctInfo.isRoleIDP());
}
NameIdentifier nameIdentifier = generateNameIdentifier();
if (acctInfo.getAffiliation()) {
String affiliationID = FSServiceUtils.getAffiliationID(realm, remoteEntityId);
if (affiliationID != null) {
nameIdentifier.setNameQualifier(affiliationID);
}
}
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("New IDP nameIdentifier Name : " + nameIdentifier.getName() + "\nNew IDP nameIdentifier Qualifier :" + nameIdentifier.getNameQualifier() + "out of generateNameIdentifier*****");
}
IDPProvidedNameIdentifier newNameIdenifier = new IDPProvidedNameIdentifier(nameIdentifier.getName(), nameIdentifier.getNameQualifier(), nameIdentifier.getFormat());
NameIdentifier remoteIdentifier = // SP
acctInfo.getRemoteNameIdentifier();
NameIdentifier localIdentifier = // IdP
acctInfo.getLocalNameIdentifier();
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("Old IDP nameIdentifier Name : " + localIdentifier.getName() + "\nOld IDP nameIdentifier Qualifier :" + localIdentifier.getNameQualifier());
}
FSUtils.debug.message("To set OldProvidedNameIdentifier");
reqName.setOldProvidedNameIdentifier(new OldProvidedNameIdentifier(localIdentifier.getName(), localIdentifier.getNameQualifier(), localIdentifier.getFormat()));
FSUtils.debug.message("To set IdpProvidedNameIdentifier");
reqName.setIDPProvidedNameIdentifier(newNameIdenifier);
if (remoteIdentifier != null) {
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("SP nameIdentifier Name : " + remoteIdentifier.getName() + "SP nameIdentifier Qualifier :" + remoteIdentifier.getNameQualifier());
}
SPProvidedNameIdentifier spNameIdentifier = new SPProvidedNameIdentifier(remoteIdentifier.getName(), remoteIdentifier.getNameQualifier(), remoteIdentifier.getFormat());
reqName.setSPProvidedNameIdentifier(spNameIdentifier);
}
try {
oldAcctKey = new FSAccountFedInfoKey(hostedEntityId, localIdentifier.getName());
FSAccountFedInfoKey tmpKey = new FSAccountFedInfoKey(nameIdentifier.getNameQualifier(), nameIdentifier.getName());
FSAccountFedInfo tmpInfo = new FSAccountFedInfo(remoteEntityId, newNameIdenifier, remoteIdentifier, acctInfo.isRoleIDP());
returnMap.put("userID", userID);
returnMap.put("OldAccountKey", oldAcctKey);
returnMap.put("AccountKey", tmpKey);
returnMap.put("AccountInfo", tmpInfo);
returnMap.put("RegisSource", regisSource);
returnMap.put(IFSConstants.LRURL, returnURL);
if (oldAcctKey != null) {
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("Get OldAcctKet Name : " + oldAcctKey.getName() + "\nGet OldAcctKet Qualifier: " + oldAcctKey.getNameSpace());
}
} else {
FSUtils.debug.message("OldAccount Key is null");
}
} catch (FSAccountMgmtException e) {
return null;
}
}
reqName.setMinorVersion(FSServiceUtils.getMinorVersion(remoteDescriptor.getProtocolSupportEnumeration()));
return reqName;
}
} catch (SAMLException e) {
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("got SAMLException:", e);
}
}
return null;
}
Aggregations