Search in sources :

Example 6 with PersonService

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;
}
Also used : TemplateNode(org.alfresco.repo.template.TemplateNode) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) NodeRef(org.alfresco.service.cmr.repository.NodeRef) InviteInfo(org.alfresco.repo.invitation.site.InviteInfo) PersonService(org.alfresco.service.cmr.security.PersonService)

Example 7 with PersonService

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);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) User(org.alfresco.web.bean.repository.User) PersonService(org.alfresco.service.cmr.security.PersonService) NodeService(org.alfresco.service.cmr.repository.NodeService) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) AuthenticationService(org.alfresco.service.cmr.security.AuthenticationService)

Example 8 with PersonService

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);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) SessionUser(org.alfresco.repo.SessionUser) User(org.alfresco.web.bean.repository.User) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) AuthenticationException(org.alfresco.repo.security.authentication.AuthenticationException) NodeService(org.alfresco.service.cmr.repository.NodeService) PersonService(org.alfresco.service.cmr.security.PersonService) ServiceRegistry(org.alfresco.service.ServiceRegistry)

Example 9 with PersonService

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);
}
Also used : PersonService(org.alfresco.service.cmr.security.PersonService)

Example 10 with 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;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) PersonService(org.alfresco.service.cmr.security.PersonService) NoSuchPersonException(org.alfresco.service.cmr.security.NoSuchPersonException)

Aggregations

PersonService (org.alfresco.service.cmr.security.PersonService)16 NodeRef (org.alfresco.service.cmr.repository.NodeRef)8 NodeService (org.alfresco.service.cmr.repository.NodeService)7 MutableAuthenticationService (org.alfresco.service.cmr.security.MutableAuthenticationService)7 Before (org.junit.Before)4 Serializable (java.io.Serializable)3 TestPersonManager (org.alfresco.repo.security.person.TestPersonManager)3 QName (org.alfresco.service.namespace.QName)3 ApplicationContext (org.springframework.context.ApplicationContext)3 HashMap (java.util.HashMap)2 UserTransaction (javax.transaction.UserTransaction)2 TemplateNode (org.alfresco.repo.template.TemplateNode)2 FileFolderService (org.alfresco.service.cmr.model.FileFolderService)2 ReplicationDefinition (org.alfresco.service.cmr.replication.ReplicationDefinition)2 ContentService (org.alfresco.service.cmr.repository.ContentService)2 SearchService (org.alfresco.service.cmr.search.SearchService)2 AuthenticationService (org.alfresco.service.cmr.security.AuthenticationService)2 AuthorityService (org.alfresco.service.cmr.security.AuthorityService)2 User (org.alfresco.web.bean.repository.User)2 InputStream (java.io.InputStream)1