Beispiel #1
0
  @SuppressWarnings("unchecked")
  private Role parseRole(Element element) throws RESTLightClientException {
    Role role = new Role();

    role.setResourceURI(element.getChildText(RESOURCE_URI_ELEMENT));
    role.setId(element.getChildText(ROLE_ID_ELEMENT));
    role.setName(element.getChildText(ROLE_NAME_ELEMENT));
    role.setDescription(element.getChildText(ROLE_DESCRIPTION_ELEMENT));
    role.setSessionTimeout(Integer.parseInt(element.getChildText(ROLE_SESSION_TIMEOUT_ELEMENT)));

    Element subRoles = element.getChild(ROLE_ROLES_ELEMENT);

    if (subRoles != null) {
      for (Element subRole : (List<Element>) subRoles.getChildren(ROLE_ROLE_ELEMENT)) {
        role.getRoles().add(subRole.getValue());
      }
    }

    Element privileges = element.getChild(ROLE_PRIVILEGES_ELEMENT);

    if (privileges != null) {
      for (Element privilege : (List<Element>) privileges.getChildren(ROLE_PRIVILEGE_ELEMENT)) {
        role.getPrivileges().add(privilege.getValue());
      }
    }

    role.setUserManaged(
        element.getChildText(ROLE_USER_MANAGED_ELEMENT).equals("true") ? true : false);

    return role;
  }
    protected RoleList defaultRoleList() {
      // Having an empty role list is not valid, they should always have one role
      Role role = new Role();
      role.setName("derpRole");
      role.setId("9");
      role.setDescription("Derp description");

      RoleList roleList = new RoleList();
      roleList.getRole().add(role);
      return roleList;
    }
  private static AuthenticateResponse getServiceResponse() {
    AuthenticateResponse rsp = new AuthenticateResponse();

    Token token = new Token();
    token.setId("tokenid");
    GregorianCalendar cal = new GregorianCalendar(2013, 11, 12);
    token.setExpires(new XMLGregorianCalendarImpl(cal));
    TenantForAuthenticateResponse tenantForAuthenticateResponse =
        new TenantForAuthenticateResponse();
    tenantForAuthenticateResponse.setId("tenantId");
    tenantForAuthenticateResponse.setName("tenantName");
    token.setTenant(tenantForAuthenticateResponse);
    rsp.setToken(token);

    ServiceCatalog catalog = new ServiceCatalog();
    List<ServiceForCatalog> serviceCatalogList = new ArrayList<>();
    ServiceForCatalog serviceForCatalog = new ServiceForCatalog();
    serviceForCatalog.setName("catName");
    serviceForCatalog.setType("type");
    serviceCatalogList.add(serviceForCatalog);
    catalog.getService().addAll(serviceCatalogList);

    rsp.setServiceCatalog(catalog);

    UserForAuthenticateResponse user = new UserForAuthenticateResponse();
    user.setId("userId");
    user.setName("userName");
    RoleList roles = new RoleList();

    Role role = new Role();
    role.setDescription("role description");
    role.setId("roleId");
    role.setName("roleName");
    role.setServiceId("serviceId");
    role.setTenantId("roleTenantId");
    roles.getRole().add(role);

    user.setRoles(roles);

    rsp.setUser(user);

    return rsp;
  }
 /**
  * Metodo di servizio al metodo loadRoles
  *
  * @param result L'oggetto ResultSet precaricato.
  * @return La mappa completa di tutti i ruoli (oggetti Role).
  * @throws SQLException
  */
 private Map<String, Role> loadRoles(ResultSet result) throws SQLException {
   HashMap<String, Role> roles = new HashMap<String, Role>();
   Role role = null;
   String prevRoleName = null;
   while (result.next()) {
     // 1=rolename, 2=descr, 3=permissionname
     String roleName = result.getString(1);
     if (!roleName.equals(prevRoleName)) {
       if (role != null) {
         roles.put(role.getName(), role);
       }
       role = new Role();
       role.setName(roleName);
       role.setDescription(result.getString(2));
       prevRoleName = roleName;
     }
     role.addPermission(result.getString(3));
   }
   if (role != null) {
     roles.put(role.getName(), role);
   }
   return roles;
 }
Beispiel #5
0
  // Process the request
  private String processRequest(HttpServletRequest request, HttpServletResponse response) {
    String command = request.getParameter("command");
    String id = request.getParameter("id");
    String description = request.getParameter("description");
    String status = request.getParameter("rstatus");
    status = (status != null && status.compareTo(" ") > 0) ? status : null;
    String outLine = "";
    // String nextScript = "home.jsp";
    String nextScript = request.getParameter("nextscript");
    OutputStream toClient;
    HttpSession session = request.getSession();
    boolean success = false;
    String userIDs = (String) session.getAttribute("user.id");
    long userID = Long.parseLong(userIDs);

    command = (command != null && command.compareTo(" ") > 0) ? command : "form";
    nextScript = (nextScript != null && nextScript.compareTo(" ") > 0) ? nextScript : "roles.jsp";

    //    inputstring = (inputstring != null && inputstring.compareTo(" ") > 0) ? inputstring : "";

    DbConn myConn = null;
    try {

      Context initCtx = new InitialContext();
      // String csiSchema = (String) initCtx.lookup("java:comp/env/csi-schema-path");
      String acronym = (String) initCtx.lookup("java:comp/env/SystemAcronym");
      myConn = new DbConn();
      String csiSchema = myConn.getSchemaPath();
      if (command.equals("add")) {
        Role item = new Role();
        item.setDescription(description);
        item.setStatus(status);
        getPermissions(request, item);
        getPositions(request, item);
        item.add(myConn, userID);
        GlobalMembership.refresh(myConn);
        success = true;
        outLine = "";

      } else if (command.equals("update")) {
        Role item = new Role(myConn, Long.parseLong(id));
        item.setDescription(description);
        item.setStatus(status);
        getPermissions(request, item);
        getPositions(request, item);
        item.save(myConn, userID);
        GlobalMembership.refresh(myConn);
        success = true;
        outLine = "";
      } else if (command.equals("drop")) {
        Role item = new Role(myConn, Long.parseLong(id));
        item.drop(myConn, userID);
        success = true;
        outLine = "Role " + item.getDescription() + " Removed";
      } else if (command.equals("test")) {
        outLine = "test";
      }

    } catch (IllegalArgumentException e) {
      outLine = outLine + "IllegalArgumentException caught: " + e.getMessage();
      ALog.logActivity(userID, "csi", 0, "Role error: '" + outLine + "'");
      // log(outLine);
    } catch (NullPointerException e) {
      outLine = outLine + "NullPointerException caught: " + e.getMessage();
      ALog.logActivity(userID, "csi", 0, "Role error: '" + outLine + "'");
      // log(outLine);
    }

    // catch (IOException e) {
    //    outLine = outLine + "IOException caught: " + e.getMessage();
    //    ALog.logActivity(userID, "csi", 0, "Role error: '" + outLine + "'");
    //    //log(outLine);
    // }

    catch (Exception e) {
      outLine = outLine + "Exception caught: " + e.getMessage();
      ALog.logActivity(userID, "csi", 0, "Role error: '" + outLine + "'");
      // log(outLine);
    } finally {
      try {
        generateResponse(outLine, command, nextScript, success, response);
      } catch (Exception i) {
      }

      myConn.release();
      // log("Test log message\n");
    }

    return outLine;
  }