*/
public static String getPPID(RahasData rahasData, String name, OMElement appliesToEpr)
throws IdentityProviderException {
String appliesToHostName = IdentityProviderUtil.getAppliesToHostName(rahasData);
IdentityPersistenceManager db = null;
try {
db = IdentityPersistenceManager.getPersistanceManager();
PPIDValueDO[] ppidValueDOs = db.getPPIDValuesForUser(IdentityTenantUtil.getRegistry(
null, name), name);
PPIDValueDO ppidValueDO = null;
for (int i = 0; i < ppidValueDOs.length; i++) {
String hostName = null;
if (ppidValueDOs[i].getRelyingParty() != null) {
hostName = ppidValueDOs[i].getRelyingParty().getHostName();
} else if (ppidValueDOs[i].getPersonalRelyingParty() != null) {
hostName = ppidValueDOs[i].getPersonalRelyingParty().getIdentifier()
.getHostName();
}
// hostName is not-null on both globally trusted relying parties and
// user trusted relying parties
// Check whether the host name matches
if (appliesToHostName.equals(hostName)) {
ppidValueDO = ppidValueDOs[i];
}
}
if (ppidValueDO != null) {
// If we have already issued a PPID
// Then return that value
return ppidValueDO.getPpid();
} else {
// A new request targeted for a new RP
String newPpid = Base64.encode(UUIDGenerator.getUUID().getBytes());
ppidValueDO = new PPIDValueDO();
ppidValueDO.setUserId(name);
ppidValueDO.setPpid(newPpid);
// If the host is globally trusted
RelyingPartyDO rp = db.getGloballyTrustedRelyingParty(IdentityTenantUtil
.getRegistry(null, name), appliesToHostName);
if (rp != null) {
ppidValueDO.setRelyingParty(rp);
} else {
// Else the host MUST be personally trusted
ppidValueDO.setPersonalRelyingParty(db.getUserTrustedRelyingParty(
IdentityTenantUtil.getRegistry(), name, appliesToHostName));
}
db.createPPIDValue(IdentityTenantUtil.getRegistry(null, name), ppidValueDO);
return newPpid;
}
} catch (Exception e) {
throw new IdentityProviderException(e.getMessage(), e);