Package org.sonatype.security.rest.model

Examples of org.sonatype.security.rest.model.AuthenticationClientPermissions


    TestContainer.getInstance().getTestContext().setSecureTest(true);
  }

  @Test
  public void sourceInLoginResourceTest() throws IOException {
    AuthenticationClientPermissions clientPermissions = this.getPermissions();

    Assert.assertEquals(clientPermissions.getLoggedInUserSource(), "default");
  }
View Full Code Here


    return result;
  }

  private NexusAuthenticationClientPermissions getClientPermissions(Request request) throws ResourceException {
    AuthenticationClientPermissions originalClientPermissions = getClientPermissionsForCurrentUser(request);

    // TODO: this is a modello work around,
    // the SystemStatus could not include a field of type AuthenticationClientPermissions
    // because it is in a different model, but I can extend that class... and include it.

    NexusAuthenticationClientPermissions clientPermissions = new NexusAuthenticationClientPermissions();
    clientPermissions.setLoggedIn(originalClientPermissions.isLoggedIn());
    clientPermissions.setLoggedInUsername(originalClientPermissions.getLoggedInUsername());
    clientPermissions.setLoggedInUserSource(originalClientPermissions.getLoggedInUserSource());
    clientPermissions.setLoggedInUserSource(originalClientPermissions.getLoggedInUserSource());
    clientPermissions.setPermissions(originalClientPermissions.getPermissions());

    return clientPermissions;
  }
View Full Code Here

  private static final int ALL = READ | UPDATE | DELETE | CREATE;

  protected AuthenticationClientPermissions getClientPermissionsForCurrentUser(Request request)
      throws ResourceException
  {
    AuthenticationClientPermissions perms = new AuthenticationClientPermissions();

    Subject subject = SecurityUtils.getSubject();

    if (getSecuritySystem().isAnonymousAccessEnabled()) {
      perms.setLoggedIn(!getSecuritySystem().getAnonymousUsername().equals(subject.getPrincipal()));
    }
    else {
      // anon access is disabled, simply ask JSecurity about this
      perms.setLoggedIn(subject != null && subject.isAuthenticated());
    }

    if (perms.isLoggedIn()) {
      // try to set the loggedInUsername
      Object principal = subject.getPrincipal();

      if (principal != null) {
        perms.setLoggedInUsername(principal.toString());
      }
    }

    // need to set the source of the logged in user
    // The UI might need to show/hide something based on the user's source
    // i.e. like the 'Change Password' link.
    String username = perms.getLoggedInUsername();
    if (StringUtils.isNotEmpty(username)) {
      // look up the realm of the user
      try {
        User user = this.getSecuritySystem().getUser(username);
        String source = (user != null) ? user.getSource() : null;
        perms.setLoggedInUserSource(source);
      }
      catch (UserNotFoundException e) {
        if (getLogger().isDebugEnabled()) {
          getLogger().info("Failed to lookup user: {}", username, e);
        }
        else {
          getLogger().info("Failed to lookup user: {}: {}/{}", username, e.getClass().getName(), e.getMessage());
        }
      }
    }

    Map<String, Integer> privilegeMap = new HashMap<String, Integer>();

    for (Privilege priv : getSecuritySystem().listPrivileges()) {
      if (priv.getType().equals("method")) {
        String permission = priv.getPrivilegeProperty("permission");
        privilegeMap.put(permission, NONE);
      }
    }

    // this will update the privilegeMap
    this.checkSubjectsPermissions(subject, privilegeMap);

    for (Entry<String, Integer> privEntry : privilegeMap.entrySet()) {
      ClientPermission cPermission = new ClientPermission();
      cPermission.setId(privEntry.getKey());
      cPermission.setValue(privEntry.getValue());

      perms.addPermission(cPermission);
    }

    return perms;
  }
View Full Code Here

  @Test
  public void testAuthenticationLoginResourceResponse() {
    AuthenticationLoginResourceResponse resourceResponse = new AuthenticationLoginResourceResponse();
    AuthenticationLoginResource loginResource = new AuthenticationLoginResource();
    AuthenticationClientPermissions perms = new AuthenticationClientPermissions();
    ClientPermission permission = new ClientPermission();
    permission.setId("id");
    permission.setValue(5);
    perms.addPermission(permission);
    perms.setLoggedIn(true);
    perms.setLoggedInUsername("fred");

    loginResource.setClientPermissions(perms);
    resourceResponse.setData(loginResource);

    this.marshalUnmarchalThenCompare(resourceResponse);
View Full Code Here

   
        if (username != null) {
            log.debug("Logging in");

            AuthenticationLoginResource detail = client.login(username, password);
            AuthenticationClientPermissions perms = detail.getClientPermissions();

            if (perms.isLoggedIn()) {
                // TODO: Add colors

                io.println("User: {}", perms.getLoggedInUsername()); // TODO: i18n
                io.println("Source: {}", perms.getLoggedInUserSource()); // TODO: i18n

                // TODO: Add more details
            }
            else {
                io.error("Authentication failed"); // TODO: i18n
View Full Code Here

TOP

Related Classes of org.sonatype.security.rest.model.AuthenticationClientPermissions

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.