final String[] fields = fieldNames.split(",");
String identityType = ((OClassImpl) cls).getCustom(OSecurityShared.ONCREATE_IDENTITY_TYPE);
if (identityType == null)
identityType = "user";
final ODatabaseRecord db = ODatabaseRecordThreadLocal.INSTANCE.get();
ODocument identity = null;
if (identityType.equals("user")) {
final OUser user = db.getUser();
if (user != null)
identity = user.getDocument();
} else if (identityType.equals("role")) {
final Set<ORole> roles = db.getUser().getRoles();
if (!roles.isEmpty())
identity = roles.iterator().next().getDocument();
} else
throw new OConfigurationException("Wrong custom field '" + OSecurityShared.ONCREATE_IDENTITY_TYPE + "' in class '"
+ cls.getName() + "' with value '" + identityType + "'. Supported ones are: 'user', 'role'");
if (identity != null) {
for (String f : fields)
db.getMetadata().getSecurity().allowIdentity(iDocument, f, identity);
return RESULT.RECORD_CHANGED;
}
}
return RESULT.RECORD_NOT_CHANGED;
}