// success
String accountName = AccountImpl.escape(verified.getIdentifier());
AbstractAccount account = (AbstractAccount) OpenIDRealm.instance.getAccount(accountName);
if (account == null) {
Database db = OpenIDRealm.instance.getDatabase();
org.exist.security.Subject currentSubject = db.getSubject();
try {
db.setSubject(db.getSecurityManager().getSystemSubject());
//XXX: set OpenID group by default
account = (AbstractAccount) OpenIDRealm.instance.addAccount(
new UserAider(OpenIDRealm.instance.getId(), accountName)
);
} finally {
db.setSubject(currentSubject);
}
}
org.exist.security.Subject principal =
new SubjectAccreditedImpl( account, verified );
AuthSuccess authSuccess = (AuthSuccess) verification.getAuthResponse();
authSuccess.getExtensions();
if (authSuccess.hasExtension(SRegMessage.OPENID_NS_SREG)) {
MessageExtension ext = authSuccess.getExtension(SRegMessage.OPENID_NS_SREG);
if (ext instanceof SRegResponse) {
SRegResponse sregResp = (SRegResponse) ext;
for (Iterator iter = sregResp.getAttributeNames().iterator(); iter.hasNext();) {
String name = (String) iter.next();
if (LOG.isDebugEnabled())
LOG.debug(name + " : " + sregResp.getParameterValue(name));
principal.setMetadataValue(AXSchemaType.valueOfNamespace(name), sregResp.getParameterValue(name));
}
}
}
if (authSuccess.hasExtension(AxMessage.OPENID_NS_AX)) {
FetchResponse fetchResp = (FetchResponse) authSuccess.getExtension(AxMessage.OPENID_NS_AX);
List aliases = fetchResp.getAttributeAliases();
for (Iterator iter = aliases.iterator(); iter.hasNext();) {
String alias = (String) iter.next();
List values = fetchResp.getAttributeValues(alias);
if (values.size() > 0) {
if (LOG.isDebugEnabled())
LOG.debug(alias + " : " + values.get(0));
principal.setMetadataValue(AXSchemaType.valueOfAlias(alias), (String)values.get(0));
}
}
}
//update metadata
Database db = OpenIDRealm.instance.getDatabase();
org.exist.security.Subject currentSubject = db.getSubject();
try {
db.setSubject(db.getSecurityManager().getSystemSubject());
OpenIDRealm.instance.updateAccount(principal);
} finally {
db.setSubject(currentSubject);
}
OpenIDUtility.registerUser(principal);
return principal;
}