beanManager.fireEvent(new DeferredAuthenticationEvent(true));
}
protected void validateManagedUser(OAuthUser principal) {
IdentitySession session = identitySession.get();
try {
// Check that the user's identity exists
if (session.getPersistenceManager().findUser(principal.getId()) == null) {
// The user wasn't found, let's create them
User user = session.getPersistenceManager().createUser(principal.getId());
// TODO allow the OAuth -> IDM attribute mapping to be configured
// e.g.
// session.getAttributesManager().addAttribute(user, "fullName", principal.getUserProfile().getFullName());
// session.getAttributesManager().addAttribute(user, "profileImageUrl",
// principal.getUserProfile().getProfileImageUrl());
// Load the user's roles and groups
try {
Collection<RoleType> roleTypes = session.getRoleManager().findUserRoleTypes(user);
for (RoleType roleType : roleTypes) {
for (Role role : session.getRoleManager().findRoles(user, roleType)) {
identity.get().addRole(role.getRoleType().getName(), role.getGroup().getName(),
role.getGroup().getGroupType());
}
}
for (Group g : session.getRelationshipManager().findAssociatedGroups(user)) {
identity.get().addGroup(g.getName(), g.getGroupType());
}
} catch (FeatureNotSupportedException ex) {
throw new AuthenticationException("Error loading user's roles and groups", ex);
} catch (IdentityException ex) {