protected RepositoryTargetResource getNexusToRestResource(Target target, Request request) { RepositoryTargetResource resource = new RepositoryTargetResource(); resource.setId(target.getId()); resource.setName(target.getName()); resource.setResourceURI(request.getResourceRef().getPath()); resource.setContentClass(target.getContentClass().getId()); List<String> patterns = new ArrayList<String>(target.getPatternTexts()); for (String pattern : patterns) { resource.addPattern(pattern); } return resource; }
@Override public void addManagedGroupId(String groupId) throws ConfigurationException, IOException, NoSuchAuthorizationManagerException, NoSuchRoleException { final Logger logger = this.getLogger(); // Validate the groupId and convert it to a repo target pattern final String targetPattern = groupIdToTargetPattern(groupId); // Get or Create the Target and persist the changes final String targetId = GIDM_ID_PREFIX + groupId; Target managedTarget = this.targetRegistry.getRepositoryTarget(targetId); if (managedTarget == null) { // Just using the name as the id ... hope thats ok! managedTarget = new Target( targetId, GIDM_NAME_PREFIX + groupId, M2_CONTENT_CLASS, Collections.singleton(targetPattern)); logger.info("Created new repository target: " + managedTarget.getName()); } else { final Set<String> patternTexts = managedTarget.getPatternTexts(); patternTexts.clear(); patternTexts.add(targetPattern); logger.info("Updated existing repository target: " + managedTarget.getName()); } this.targetRegistry.addRepositoryTarget(managedTarget); final AuthorizationManager authorizationManager = this.securitySystem.getAuthorizationManager(SECURITY_CONTEXT); // Get or Create the deployer and readonly Roles, need these here to add the privs to them as // they are created in the next step final Role deployerRole = getOrCreateRole(authorizationManager, groupId, DEPLOYER_ROLE_SUFFIX); final Set<String> deployerPrivs = deployerRole.getPrivileges(); deployerPrivs.clear(); final Role readOnlyRole = getOrCreateRole(authorizationManager, groupId, READONLY_ROLE_SUFFIX); final Set<String> readOnlyPrivs = readOnlyRole.getPrivileges(); readOnlyPrivs.clear(); // Assumes priv name is unique final Map<String, Privilege> existingPrivs = new HashMap<String, Privilege>(); for (final Privilege priv : authorizationManager.listPrivileges()) { existingPrivs.put(priv.getName(), priv); } /* * Adds create/read privs for each managed repository */ final ManagedRepositories managedRepositoriesObj = this.getManagedRepositories(); for (final ManagedRepository repository : managedRepositoriesObj.getManagedRepositories()) { addRepositoryForGroupId( groupId, repository, managedTarget, authorizationManager, deployerPrivs, readOnlyPrivs, existingPrivs); } // Add the roles authorizationManager.updateRole(deployerRole); authorizationManager.updateRole(readOnlyRole); this.nexusConfiguration.saveConfiguration(); }