Package org.sonatype.security

Examples of org.sonatype.security.SecuritySystem


  protected PlexusRoleResource securityToRestModel(RoleIdentifier role) {
    // TODO: We shouldn't be looking up the role name here anyway... this should get pushed up to the
    // SecuritySystem.
    String roleName = role.getRoleId();

    SecuritySystem securitySystem = this.getSecuritySystem();

    try {
      AuthorizationManager authzManager = securitySystem.getAuthorizationManager(DEFAULT_SOURCE);
      roleName = authzManager.getRole(role.getRoleId()).getName();
    }
    catch (NoSuchAuthorizationManagerException e) {
      this.getLogger().warn("Failed to lookup the users Role: " + role.getRoleId() + " source: "
          + role.getSource() + " but the user has this role.", e);
View Full Code Here


  @Test
  public void testGetUserFromUserManager()
      throws Exception
  {

    SecuritySystem securitySystem = this.getSecuritySystem();
    securitySystem.start();
    User user = securitySystem.getUser("cstamas");
    Assert.assertNotNull(user);
    Assert.assertEquals("cstamas", user.getUserId());
    Assert.assertEquals("cstamas@sonatype.com", user.getEmailAddress());
    Assert.assertEquals("Tamas Cservenak", user.getName());
View Full Code Here

      throws Exception
  {
    IOUtils.copy(getClass().getResourceAsStream("/test-conf/etc/security-users-in-both-realms.xml"),
        new FileOutputStream(getNexusSecurityConfiguration()));

    SecuritySystem securitySystem = this.getSecuritySystem();
    securitySystem.start();

    List<String> realms = new ArrayList<String>();
    realms.add("XmlAuthenticatingRealm");
    realms.add(LdapPlugin.REALM_NAME);

    securitySystem.setRealms(realms);

    // the user developer is in both realms, we need to make sure the order is honored
    User user = securitySystem.getUser("brianf");
    Assert.assertEquals("default", user.getSource());

    realms.clear();
    realms.add(LdapPlugin.REALM_NAME);
    realms.add("XmlAuthenticatingRealm");
    securitySystem.setRealms(realms);

    // now the user should belong to the LDAP realm

    user = securitySystem.getUser("brianf");
    Assert.assertEquals("LDAP", user.getSource());

  }
View Full Code Here

  }

  public void testInvalidRoleMapping()
      throws Exception
  {
    SecuritySystem userManager = this.getSecuritySystem();

    User user = userManager.getUser("jcoder");
    Assert.assertNotNull(user);

    Set<String> roleIds = new HashSet<String>();
    for (RoleIdentifier role : user.getRoles()) {
      Assert.assertNotNull("User has null role.", role);
View Full Code Here

  }

  public void testListUsers()
      throws Exception
  {
    SecuritySystem userManager = this.getSecuritySystem();
    UserSearchCriteria criteria = new UserSearchCriteria(null, null, "MockUserManagerA");
    Set<User> users = userManager.searchUsers(criteria);

    Map<String, User> userMap = this.toUserMap(users);

    User user = userMap.get("jcoder");
    Assert.assertNotNull(user);
View Full Code Here

  }

  private User searchForSingleUser(UserSearchCriteria criteria, String userId, String source)
      throws Exception
  {
    SecuritySystem userManager = this.getSecuritySystem();

    criteria.setSource(source);
    Set<User> users = userManager.searchUsers(criteria);

    Map<String, User> userMap = this.toUserMap(users);

    Assert.assertTrue("More then 1 User was returned: " + userMap.keySet(), users.size() <= 1);
View Full Code Here

    getApplicationConfiguration().saveConfiguration();

    // setup security
    // setup security
    final SecuritySystem securitySystem = this.lookup(SecuritySystem.class);
    securitySystem.setRealms(Collections.singletonList("default"));
  }
View Full Code Here

  private StorageItem getItem(String username, String repositoryId, String path)
      throws AuthenticationException, Exception
  {
    WebSecurityUtil.setupWebContext(username + "-" + repositoryId + "-" + path);

    SecuritySystem securitySystem = this.lookup(SecuritySystem.class);

    Subject subject = securitySystem.login(new UsernamePasswordToken(username, ""));

    Repository repo = this.getRepositoryRegistry().getRepository(repositoryId);

    ResourceStoreRequest request = new ResourceStoreRequest(path, false);

    StorageItem item = repo.retrieveItem(request);

    // not sure if we really need to log the user out, we are not using a remember me,
    // but what can it hurt?
    securitySystem.logout(subject);

    return item;
  }
View Full Code Here

      throws Exception
  {
    // delete the security conf first, start clean
    new File(SECURITY_CONFIG_FILE_PATH).delete();

    SecuritySystem securitySystem = this.lookup(SecuritySystem.class);

    Map<String, String> properties = new HashMap<String, String>();
    properties.put(ApplicationPrivilegeMethodPropertyDescriptor.ID, "read");
    properties.put(ApplicationPrivilegePermissionPropertyDescriptor.ID, "permissionOne");

    securitySystem.getAuthorizationManager("default").addPrivilege(new Privilege(
        "randomId",
        "permissionOne",
        "permissionOne",
        ApplicationPrivilegeDescriptor.TYPE,
        properties, false));
    securitySystem.getAuthorizationManager("default").addRole(new Role("mockrole1", "mockrole1", "mockrole1",
        "default", false, null,
        Collections.singleton("randomId")));

    // add MockRealm to config
    List<String> realms = new ArrayList<String>();
    realms.add("Mock");
    realms.add(XmlAuthorizingRealm.ROLE);
    securitySystem.setRealms(realms);

    // jcohen has the role mockrole1, there is also xml role with the same ID, which means jcohen automaticly has
    // this xml role

    PrincipalCollection jcohen = new SimplePrincipalCollection("jcohen", MockRealm.NAME);

    try {
      securitySystem.checkPermission(jcohen, "permissionOne:invalid");
      Assert.fail("Expected AuthorizationException");
    }
    catch (AuthorizationException e) {
      // expected
    }

    securitySystem.checkPermission(jcohen, "permissionOne:read"); // throws on error, so this is all we need to do

  }
View Full Code Here

    injector = Guice.createInjector(getWireModule());
  }

  @Test
  public void testInjectionIsSetupCorrectly() {
    SecuritySystem securitySystem = injector.getInstance(SecuritySystem.class);
    // See DefaultSecuritySystem, that applies cache
    // TODO: this should be done with Guice binding?
    securitySystem.start();

    SecurityManager securityManager = injector.getInstance(SecurityManager.class);

    RealmSecurityManager realmSecurityManager = injector.getInstance(RealmSecurityManager.class);

    assertThat(securitySystem.getSecurityManager(), sameInstance(securityManager));
    assertThat(securitySystem.getSecurityManager(), sameInstance(realmSecurityManager));

    assertThat(securityManager, instanceOf(DefaultSecurityManager.class));
    DefaultSecurityManager defaultSecurityManager = (DefaultSecurityManager) securityManager;

    assertThat(defaultSecurityManager.getSessionManager(), instanceOf(NexusDefaultSessionManager.class));
View Full Code Here

TOP

Related Classes of org.sonatype.security.SecuritySystem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.