EntityManager em = emf.createEntityManager();
TypedQuery<IdpUser> q = em.createQuery(
"SELECT u FROM IdpUser u WHERE username = :username and status = :status", IdpUser.class);
q.setParameter("username", userPrincipal.getName()).setParameter("status", IdpUserState.ACTIVE);
IdpUser user = q.getSingleResult();
for (String attributeKey : attributeKeys) {
Object object = null;
if (attributeKey.equals("username")) {
object = user.getUsername();
} else if (attributeKey.equals("firstName")) {
object = user.getFirstName();
} else if (attributeKey.equals("lastName")) {
object = user.getLastName();
} else if (attributeKey.equals("email")) {
object = user.getEmail();
}
if (object != null) {
attributes.put(attributeKey, object);
}