use of org.alfresco.service.cmr.security.PersonService in project alfresco-remote-api by Alfresco.
the class InviteByTicket method toInviteInfo.
private InviteInfo toInviteInfo(NominatedInvitation invitation) {
final PersonService personService = serviceRegistry.getPersonService();
// get the site info
SiteInfo siteInfo = siteService.getSite(invitation.getResourceName());
String invitationStatus = getInvitationStatus(invitation);
NodeRef inviterRef = personService.getPerson(invitation.getInviterUserName());
TemplateNode inviterPerson = null;
if (inviterRef != null) {
inviterPerson = new TemplateNode(inviterRef, serviceRegistry, null);
}
// fetch the person node for the invitee
NodeRef inviteeRef = personService.getPerson(invitation.getInviteeUserName());
TemplateNode inviteePerson = null;
if (inviteeRef != null) {
inviteePerson = new TemplateNode(inviteeRef, serviceRegistry, null);
}
InviteInfo ret = new InviteInfo(invitationStatus, invitation.getInviterUserName(), inviterPerson, invitation.getInviteeUserName(), inviteePerson, invitation.getRoleName(), invitation.getResourceName(), siteInfo, invitation.getSentInviteDate(), invitation.getInviteId());
return ret;
}
use of org.alfresco.service.cmr.security.PersonService in project acs-community-packaging by Alfresco.
the class GuestTemplateContentServlet method buildModel.
@Override
protected Map<String, Object> buildModel(ServiceRegistry services, HttpServletRequest req, NodeRef templateRef) {
// setup the guest user to pass to the build model helper method
AuthenticationService auth = (AuthenticationService) services.getAuthenticationService();
PersonService personService = (PersonService) services.getPersonService();
NodeService nodeService = (NodeService) services.getNodeService();
NodeRef guestRef = personService.getPerson(AuthenticationUtil.getGuestUserName());
User guestUser = new User(AuthenticationUtil.getGuestUserName(), auth.getCurrentTicket(), guestRef);
NodeRef guestHomeRef = (NodeRef) nodeService.getProperty(guestRef, ContentModel.PROP_HOMEFOLDER);
if (nodeService.exists(guestHomeRef) == false) {
throw new InvalidNodeRefException(guestHomeRef);
}
guestUser.setHomeSpaceId(guestHomeRef.getId());
// build the default model
return DefaultModelHelper.buildDefaultModel(services, guestUser, templateRef, this.imageResolver);
}
use of org.alfresco.service.cmr.security.PersonService in project acs-community-packaging by Alfresco.
the class AuthenticationHelper method createUser.
/**
* Creates an object for an authentication user.
*
* @param wc
* the web application context
* @param currentUsername
* the current user name
* @param ticket
* a validated ticket
* @return the user object
*/
private static User createUser(final WebApplicationContext wc, final String currentUsername, final String ticket) {
if (logger.isDebugEnabled())
logger.debug("Creating an object for " + currentUsername + " with ticket: " + ticket);
final ServiceRegistry services = (ServiceRegistry) wc.getBean(ServiceRegistry.SERVICE_REGISTRY);
// If the repository is read only, we have to settle for a read only transaction. Auto user creation
// will not be possible.
boolean readOnly = services.getTransactionService().isReadOnly();
return services.getTransactionService().getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<User>() {
public User execute() throws Throwable {
NodeService nodeService = services.getNodeService();
PersonService personService = (PersonService) wc.getBean(PERSON_SERVICE);
NodeRef personRef = personService.getPerson(currentUsername);
User user = new User(currentUsername, ticket, personRef);
NodeRef homeRef = (NodeRef) nodeService.getProperty(personRef, ContentModel.PROP_HOMEFOLDER);
if (homeRef == null || !nodeService.exists(homeRef)) {
throw new AuthenticationException("Home folder is missing for user " + currentUsername);
}
user.setHomeSpaceId(homeRef.getId());
return user;
}
}, readOnly, false);
}
use of org.alfresco.service.cmr.security.PersonService in project alfresco-remote-api by Alfresco.
the class Node method mapMinimalInfo.
protected void mapMinimalInfo(Map<QName, Serializable> nodeProps, Map<String, UserInfo> mapUserInfo, ServiceRegistry sr) {
PersonService personService = sr.getPersonService();
this.name = (String) nodeProps.get(ContentModel.PROP_NAME);
if (mapUserInfo == null) {
// minor: save one lookup if creator & modifier are the same
mapUserInfo = new HashMap<>(2);
}
this.createdAt = (Date) nodeProps.get(ContentModel.PROP_CREATED);
this.createdByUser = lookupUserInfo((String) nodeProps.get(ContentModel.PROP_CREATOR), mapUserInfo, personService);
this.modifiedAt = (Date) nodeProps.get(ContentModel.PROP_MODIFIED);
this.modifiedByUser = lookupUserInfo((String) nodeProps.get(ContentModel.PROP_MODIFIER), mapUserInfo, personService);
}
use of org.alfresco.service.cmr.security.PersonService in project alfresco-remote-api by Alfresco.
the class Node method lookupUserInfo.
public static UserInfo lookupUserInfo(String userName, Map<String, UserInfo> mapUserInfo, PersonService personService, boolean displayNameOnly) {
UserInfo userInfo = mapUserInfo.get(userName);
if ((userInfo == null) && (userName != null)) {
String sysUserName = AuthenticationUtil.getSystemUserName();
if (userName.equals(sysUserName) || (AuthenticationUtil.isMtEnabled() && userName.startsWith(sysUserName + "@"))) {
userInfo = new UserInfo((displayNameOnly ? null : userName), userName, "");
} else {
PersonService.PersonInfo pInfo = null;
try {
NodeRef pNodeRef = personService.getPerson(userName, false);
if (pNodeRef != null) {
pInfo = personService.getPerson(pNodeRef);
}
} catch (NoSuchPersonException nspe) {
// drop-through
} catch (AccessDeniedException ade) {
// SFS-610
// drop-through
}
if (pInfo != null) {
userInfo = new UserInfo((displayNameOnly ? null : userName), pInfo.getFirstName(), pInfo.getLastName());
} else {
logger.warn("Unknown person: " + userName);
userInfo = new UserInfo((displayNameOnly ? null : userName), userName, "");
}
}
mapUserInfo.put(userName, userInfo);
}
return userInfo;
}
Aggregations