use of org.apereo.portal.security.provider.RestrictedPerson in project uPortal by Jasig.
the class UpdatePreferencesServlet method removeSubscription.
protected void removeSubscription(IPerson per, String elementId, IUserLayoutManager ulm) {
// get the fragment owner's ID from the element string
String userIdString = StringUtils.substringBetween(elementId, Constants.FRAGMENT_ID_USER_PREFIX, Constants.FRAGMENT_ID_LAYOUT_PREFIX);
int userId = NumberUtils.toInt(userIdString, 0);
// construct a new person object representing the fragment owner
RestrictedPerson fragmentOwner = PersonFactory.createRestrictedPerson();
fragmentOwner.setID(userId);
fragmentOwner.setUserName(userIdentityStore.getPortalUserName(userId));
// attempt to find a subscription for this fragment
IUserFragmentSubscription subscription = userFragmentInfoDao.getUserFragmentInfo(per, fragmentOwner);
// if a subscription was found, remove it's registration
if (subscription != null) {
userFragmentInfoDao.deleteUserFragmentInfo(subscription);
ulm.loadUserLayout(true);
} else // otherwise, delete the node
{
ulm.deleteNode(elementId);
}
}
use of org.apereo.portal.security.provider.RestrictedPerson in project uPortal by Jasig.
the class UserLayoutHelperImpl method resetUserLayout.
/**
* @param personAttributes
* @see
* org.apereo.portal.layout.IUserLayoutHelper#resetUserLayout(org.jasig.services.persondir.IPersonAttributes)
*/
public void resetUserLayout(final IPersonAttributes personAttributes) {
// Create an empty RestrictedPerson object
RestrictedPerson person = PersonFactory.createRestrictedPerson();
// populate the person with the supplied attributes
person.setAttributes(personAttributes.getAttributes());
// get the integer uid into the person object without creating any new person data
int uid = userIdentityStore.getPortalUID(person, false);
person.setID(uid);
try {
// determine user profile
IUserProfile userProfile = userLayoutStore.getUserProfileByFname(person, DEFAULT_LAYOUT_FNAME);
// Finally set the layout id to 0. This orphans the existing layout but it will be replaced by the default
// when the user logs in
userProfile.setLayoutId(0);
// persist the change
userLayoutStore.updateUserProfile(person, userProfile);
logger.info("resetUserLayout complete for " + person);
} catch (Exception e) {
final String msg = "Exception caught during resetUserLayout for " + person;
logger.error(msg, e);
throw new PortalException(msg, e);
}
}
use of org.apereo.portal.security.provider.RestrictedPerson in project uPortal by Jasig.
the class UserLayoutHelperImpl method resetUserLayoutAllProfiles.
/**
* Resets a users layout for all the users profiles
*
* @param personAttributes
*/
public void resetUserLayoutAllProfiles(final IPersonAttributes personAttributes) {
RestrictedPerson person = PersonFactory.createRestrictedPerson();
person.setAttributes(personAttributes.getAttributes());
// get the integer uid into the person object without creating any new person data
int uid = userIdentityStore.getPortalUID(person, false);
person.setID(uid);
try {
Hashtable<Integer, UserProfile> userProfileList = userLayoutStore.getUserProfileList(person);
for (Integer key : userProfileList.keySet()) {
UserProfile userProfile = userProfileList.get(key);
userProfile.setLayoutId(0);
userLayoutStore.updateUserProfile(person, userProfile);
logger.info("resetUserLayout complete for " + person + "for profile " + userProfile);
}
} catch (Exception e) {
final String msg = "Exception caught during resetUserLayout for " + person;
logger.error(msg, e);
throw new PortalException(msg, e);
}
return;
}
use of org.apereo.portal.security.provider.RestrictedPerson in project uPortal by Jasig.
the class UpdatePreferencesServlet method subscribeToTab.
/**
* Subscribe a user to a pre-formatted tab (pulled DLM fragment).
*
* @param request
* @param response
* @return
* @throws IOException
*/
@RequestMapping(method = RequestMethod.POST, params = "action=subscribeToTab")
public ModelAndView subscribeToTab(HttpServletRequest request, HttpServletResponse response) throws IOException {
IUserInstance ui = userInstanceManager.getUserInstance(request);
IPerson per = getPerson(ui, response);
UserPreferencesManager upm = (UserPreferencesManager) ui.getPreferencesManager();
IUserLayoutManager ulm = upm.getUserLayoutManager();
// Get the fragment owner's name from the request and construct
// an IPerson object representing that user
String fragmentOwnerName = request.getParameter("sourceID");
if (StringUtils.isBlank(fragmentOwnerName)) {
logger.warn("Attempted to subscribe to tab with null owner ID");
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
return new ModelAndView("jsonView", Collections.singletonMap("error", "Attempted to subscribe to tab with null owner ID"));
}
RestrictedPerson fragmentOwner = PersonFactory.createRestrictedPerson();
fragmentOwner.setUserName(fragmentOwnerName);
// Mark the currently-authenticated user as subscribed to this fragment.
// If an inactivated fragment registration already exists, update it
// as an active subscription. Otherwise, create a new fragment
// subscription.
IUserFragmentSubscription userFragmentInfo = userFragmentInfoDao.getUserFragmentInfo(per, fragmentOwner);
if (userFragmentInfo == null) {
userFragmentInfo = userFragmentInfoDao.createUserFragmentInfo(per, fragmentOwner);
} else {
userFragmentInfo.setActive(true);
userFragmentInfoDao.updateUserFragmentInfo(userFragmentInfo);
}
try {
// reload user layout and stylesheet to incorporate new DLM fragment
ulm.loadUserLayout(true);
// get the target node this new tab should be moved after
String destinationId = request.getParameter("elementID");
// get the user layout for the currently-authenticated user
int uid = userIdentityStore.getPortalUID(fragmentOwner, false);
final DistributedUserLayout userLayout = userLayoutStore.getUserLayout(per, upm.getUserProfile());
Document layoutDocument = userLayout.getLayout();
// attempt to find the new subscribed tab in the layout so we can
// move it
StringBuilder expression = new StringBuilder("//folder[@type='root']/folder[starts-with(@ID,'").append(Constants.FRAGMENT_ID_USER_PREFIX).append(uid).append("')]");
XPathFactory fac = XPathFactory.newInstance();
XPath xpath = fac.newXPath();
NodeList nodes = (NodeList) xpath.evaluate(expression.toString(), layoutDocument, XPathConstants.NODESET);
String sourceId = nodes.item(0).getAttributes().getNamedItem("ID").getTextContent();
ulm.moveNode(sourceId, ulm.getParentId(destinationId), destinationId);
ulm.saveUserLayout();
return new ModelAndView("jsonView", Collections.singletonMap("tabId", sourceId));
} catch (XPathExpressionException e) {
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return new ModelAndView("jsonView", Collections.singletonMap("error", "Xpath error"));
} catch (PortalException e) {
return handlePersistError(request, response, e);
}
}
use of org.apereo.portal.security.provider.RestrictedPerson in project uPortal by Jasig.
the class EntityPersonAttributesGroupStore method contains.
@Override
public boolean contains(IEntityGroup group, IGroupMember member) {
if (!IPERSON_CLASS.equals(member.getLeafType())) {
// group.getLeafType() is (presumably) IPerson.class.
return false;
}
if (member.isGroup()) {
// PAGS groups may only contain other PAGS groups (and people, of course)
final IEntityGroup ieg = (IEntityGroup) member;
if (!PagsService.SERVICE_NAME_PAGS.equals(ieg.getServiceName().toString())) {
return false;
}
}
final MembershipCacheKey cacheKey = new MembershipCacheKey(group.getEntityIdentifier(), member.getUnderlyingEntityIdentifier());
Element element = membershipCache.get(cacheKey);
if (element == null) {
logger.debug("Checking if group {} contains member {}/{}", group.getName(), member.getKey(), member.getLeafType().getSimpleName());
// default
boolean answer = false;
final PagsGroup groupDef = convertEntityToGroupDef(group);
if (member.isGroup()) {
final String key = ((IEntityGroup) member).getLocalKey();
answer = groupDef.hasMember(key);
} else {
try {
final IPersonAttributeDao pa = PersonAttributeDaoLocator.getPersonAttributeDao();
final IPersonAttributes personAttributes = pa.getPerson(member.getKey());
if (personAttributes != null) {
final RestrictedPerson rp = PersonFactory.createRestrictedPerson();
rp.setAttributes(personAttributes.getAttributes());
answer = groupDef.contains(rp);
}
} catch (Exception ex) {
logger.error("Exception acquiring attributes for member " + member + " while checking if group " + group + " contains this member.", ex);
return false;
}
}
element = new Element(cacheKey, answer);
membershipCache.put(element);
}
return (Boolean) element.getObjectValue();
}
Aggregations