/** * @see UserManager#createGroup(String) */ public Group createGroup(String groupID) throws AuthorizableExistsException, RepositoryException { return createGroup(groupID, new PrincipalImpl(groupID), null); }
/** * @see UserManager#createUser(String,String) */ public User createUser(String userID, String password) throws RepositoryException { return createUser(userID, password, new PrincipalImpl(userID), null); }
/** * @see UserManager#createUser(String,String) */ public User createUser(String userID, String password) throws RepositoryException { return createUser(userID, password, new PrincipalImpl(userID), null); }
/** * @see UserManager#createGroup(String) */ public Group createGroup(String groupID) throws AuthorizableExistsException, RepositoryException { return createGroup(groupID, new PrincipalImpl(groupID), null); }
/** * {@inheritDoc} * <p> * This implementation uses the user and node resolver to find the * appropriate nodes. */ @Override protected Principal providePrincipal(String principalName) { try { Principal principal = new PrincipalImpl(principalName); Authorizable ath = userManager.getAuthorizable(principal); if (ath != null) { return ath.getPrincipal(); } else if (EveryonePrincipal.NAME.equals(principalName)) { return everyonePrincipal; } } catch (RepositoryException e) { log.error("Failed to access Authorizable for Principal " + principalName, e); } return null; }
/** * {@inheritDoc} * <p> * This implementation uses the user and node resolver to find the * appropriate nodes. */ @Override protected Principal providePrincipal(String principalName) { try { Principal principal = new PrincipalImpl(principalName); Authorizable ath = userManager.getAuthorizable(principal); if (ath != null) { return ath.getPrincipal(); } else if (EveryonePrincipal.NAME.equals(principalName)) { return everyonePrincipal; } } catch (RepositoryException e) { log.error("Failed to access Authorizable for Principal " + principalName, e); } return null; }
/** * @see Impersonation#getImpersonators() */ public PrincipalIterator getImpersonators() throws RepositoryException { Set<String> impersonators = getImpersonatorNames(); if (impersonators.isEmpty()) { return PrincipalIteratorAdapter.EMPTY; } else { final PrincipalManager pMgr = user.getSession().getPrincipalManager(); Set<Principal> s = new HashSet<Principal>(); for (String pName : impersonators) { Principal p = pMgr.getPrincipal(pName); if (p == null) { log.debug("Impersonator " + pName + " does not correspond to a known Principal."); p = new PrincipalImpl(pName); } s.add(p); } return new PrincipalIteratorAdapter(s); } }
/** * @see Impersonation#getImpersonators() */ public PrincipalIterator getImpersonators() throws RepositoryException { Set<String> impersonators = getImpersonatorNames(); if (impersonators.isEmpty()) { return PrincipalIteratorAdapter.EMPTY; } else { final PrincipalManager pMgr = user.getSession().getPrincipalManager(); Set<Principal> s = new HashSet<Principal>(); for (String pName : impersonators) { Principal p = pMgr.getPrincipal(pName); if (p == null) { log.debug("Impersonator " + pName + " does not correspond to a known Principal."); p = new PrincipalImpl(pName); } s.add(p); } return new PrincipalIteratorAdapter(s); } }
AccessControlManager accessControlManager = session.getAccessControlManager(); userManager.createUser(name, password, new PrincipalImpl(name), null); acl.addAccessControlEntry(new PrincipalImpl(name), privileges); accessControlManager.setPolicy(session.getRootNode().getPath(), acl);
private static Principal initGroup(UserManager uMgr, String principalName) { Principal prnc = new PrincipalImpl(principalName); try { Authorizable auth = uMgr.getAuthorizable(prnc); if (auth == null) { auth = uMgr.createGroup(prnc); } else { if (!auth.isGroup()) { log.warn("Cannot create group '" + principalName + "'; User with that principal already exists."); auth = null; } } if (auth != null) { return auth.getPrincipal(); } } catch (RepositoryException e) { // should never get here log.error("Error while initializing user/group administrators: {}", e.getMessage()); } return null; }
AccessControlManager accessControlManager = session.getAccessControlManager(); userManager.createUser(name, password, new PrincipalImpl(name), null); acl.addAccessControlEntry(new PrincipalImpl(name), privileges); accessControlManager.setPolicy(session.getRootNode().getPath(), acl);
private static Principal initGroup(UserManager uMgr, String principalName) { Principal prnc = new PrincipalImpl(principalName); try { Authorizable auth = uMgr.getAuthorizable(prnc); if (auth == null) { auth = uMgr.createGroup(prnc); } else { if (!auth.isGroup()) { log.warn("Cannot create group '" + principalName + "'; User with that principal already exists."); auth = null; } } if (auth != null) { return auth.getPrincipal(); } } catch (RepositoryException e) { // should never get here log.error("Error while initializing user/group administrators: {}", e.getMessage()); } return null; }
public void testImportInvalidImpersonationAbort() throws IOException, RepositoryException, SAXException, NotExecutableException { List<String> invalid = new ArrayList<String>(); invalid.add("anybody"); // an non-existing princ-name invalid.add("administrators"); // a group invalid.add("t"); // principal of the user itself. for (String principalName : invalid) { String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<sv:node sv:name=\"t\" xmlns:mix=\"http://www.jcp.org/jcr/mix/1.0\" xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\" xmlns:fn_old=\"http://www.w3.org/2004/10/xpath-functions\" xmlns:fn=\"http://www.w3.org/2005/xpath-functions\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:sv=\"http://www.jcp.org/jcr/sv/1.0\" xmlns:rep=\"internal\" xmlns:jcr=\"http://www.jcp.org/jcr/1.0\">" + " <sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:User</sv:value></sv:property>" + " <sv:property sv:name=\"jcr:uuid\" sv:type=\"String\"><sv:value>e358efa4-89f5-3062-b10d-d7316b65649e</sv:value></sv:property>" + " <sv:property sv:name=\"rep:password\" sv:type=\"String\"><sv:value>{sha1}8efd86fb78a56a5145ed7739dcb00c78581c5375</sv:value></sv:property>" + " <sv:property sv:name=\"rep:principalName\" sv:type=\"String\"><sv:value>t</sv:value></sv:property><sv:property sv:name=\"rep:impersonators\" sv:type=\"String\"><sv:value>" +principalName+ "</sv:value></sv:property>" + "</sv:node>"; Subject subj = new Subject(); subj.getPrincipals().add(new PrincipalImpl(principalName)); NodeImpl target = (NodeImpl) sImpl.getNode(umgr.getUsersPath()); try { doImport(target, xml, UserImporter.ImportBehavior.ABORT); fail("UserImporter.ImportBehavior.ABORT -> importing invalid impersonators must throw."); } catch (SAXException e) { // success } finally { sImpl.refresh(false); } } }
} else { principal = new PrincipalImpl(pName);
/** * * @param acNode the acl node * @return the polict * @throws RepositoryException if an error occurs */ private JackrabbitAccessControlPolicy createTemplate(NodeImpl acNode) throws RepositoryException { if (!acNode.isNodeType(NT_REP_PRINCIPAL_ACCESS_CONTROL)) { String msg = "Unable to edit Access Control at "+ acNode.getPath()+ ". Expected node of type rep:PrinicipalAccessControl, was " + acNode.getPrimaryNodeType().getName(); log.debug(msg); throw new AccessControlException(msg); } Principal principal = getPrincipal(acNode.getPath()); if (principal == null) { // use fall back in order to be able to get/remove the policy String principalName = getPathName(acNode.getPath()); log.warn("Principal with name " + principalName + " unknown to PrincipalManager."); principal = new PrincipalImpl(principalName); } return new ACLTemplate(principal, acNode); }
} else { principal = new PrincipalImpl(pName);
/** * * @param acNode the acl node * @return the polict * @throws RepositoryException if an error occurs */ private JackrabbitAccessControlPolicy createTemplate(NodeImpl acNode) throws RepositoryException { if (!acNode.isNodeType(NT_REP_PRINCIPAL_ACCESS_CONTROL)) { String msg = "Unable to edit Access Control at "+ acNode.getPath()+ ". Expected node of type rep:PrinicipalAccessControl, was " + acNode.getPrimaryNodeType().getName(); log.debug(msg); throw new AccessControlException(msg); } Principal principal = getPrincipal(acNode.getPath()); if (principal == null) { // use fall back in order to be able to get/remove the policy String principalName = getPathName(acNode.getPath()); log.warn("Principal with name " + principalName + " unknown to PrincipalManager."); principal = new PrincipalImpl(principalName); } return new ACLTemplate(principal, acNode); }
if (toRemove.remove(princName) == null) { toAdd.add(new PrincipalImpl(princName));
if (toRemove.remove(princName) == null) { toAdd.add(new PrincipalImpl(princName));
if (princ == null) { log.debug("Principal with name " + principalName + " unknown to PrincipalManager."); princ = new PrincipalImpl(principalName);