@Override
public User getUserObject(JsonSessionState session) {
RapidAafUser user = (RapidAafUser) session.get("jwt_user");
long now = new Date().getTime() / 1000;
if (user == null) {
JsonSimple jwt_json = (JsonSimple) session.get("jwt_json");
Integer jwt_exp = (Integer) session.get("jwt_exp");
if (jwt_json == null || jwt_exp == null) {
logger.error("Session does not have jwt_json or jwt_exp, might be expired.");
return null;
}
if (now > jwt_exp.longValue()) {
logger.error("Session has expired, exp: " + jwt_exp + ", now:" + now);
return null;
}
String username = jwt_json.getString(null, attrParentField, usernameField);
if (username == null) {
logger.error("JWT has no username attribute: "+attrParentField + "->" + usernameField);
return null;
}
String realName = jwt_json.getString(username, attrParentField, "displayname");
user = new RapidAafUser(realName);
// set the attributes...
user.setUsername(username);
user.set("jti", jwt_json.getString("", "jti"));
user.set("exp", jwt_exp.toString());
List<String> userFieldNames = ssoConfig.getStringList("userFields");
for (String userFieldName : userFieldNames) {
String fieldVal = jwt_json.getString(null, attrParentField, userFieldName);
if (fieldVal != null) {
logger.debug("Setting '"+userFieldName+"' with value: " + fieldVal);
user.set(userFieldName, fieldVal);
} else {
logger.debug("Skipping setting of " + userFieldName + ", null value.");