Package com.denimgroup.threadfix.data.entities

Examples of com.denimgroup.threadfix.data.entities.APIKey


    apiKeyDao.saveOrUpdate(apiKey);
  }

  @Override
  public APIKey createAPIKey(String note, boolean restricted) {
    APIKey key = new APIKey();
   
    String editedNote = note;
   
    if (editedNote != null && editedNote.length() > 255)
      editedNote = editedNote.substring(0, 254);
   
    String keyString = generateNewSecureRandomKey();
   
    if (keyString != null && keyString.length() > 50)
      keyString = keyString.substring(0, 49);
   
    key.setNote(editedNote);
    key.setIsRestrictedKey(restricted);
    key.setApiKey(keyString);
   
    return key;
  }
View Full Code Here


  }
 
  @RequestMapping(method = RequestMethod.GET)
  public String index(HttpServletRequest request, Model model) {
    model.addAttribute("apiKeyList", apiKeyService.loadAll());
    model.addAttribute("apiKey", new APIKey());

    return "config/keys/index";
  }
View Full Code Here

                                                        @RequestParam(required = false) String note) {

        // checkboxes can be difficult
    boolean restricted = request.getParameter("isRestrictedKey") != null;
   
    APIKey newAPIKey = apiKeyService.createAPIKey(note, restricted);
    apiKeyService.storeAPIKey(newAPIKey);
   
    String currentUser = SecurityContextHolder.getContext().getAuthentication().getName();
    log.debug(currentUser + " has created an API key with the note " + note +
        ", and the ID " + newAPIKey.getId());
   
    return RestResponse.success(newAPIKey);
  }
View Full Code Here

  @RequestMapping(value = "/{keyId}/delete", method = RequestMethod.POST)
  public @ResponseBody RestResponse<String> delete(@PathVariable("keyId") int keyId) {

        // TODO validate authentication

    APIKey newAPIKey = apiKeyService.loadAPIKey(keyId);
   
    if (newAPIKey != null) {
      apiKeyService.deactivateApiKey(newAPIKey);
    } else {
      log.warn(ResourceNotFoundException.getLogMessage("API Key", keyId));
View Full Code Here

  }
 
  @RequestMapping(value = "/{keyId}/edit", method = RequestMethod.POST)
  public @ResponseBody RestResponse<APIKey> saveEdit(HttpServletRequest request,
      @PathVariable("keyId") int keyId, @RequestParam(required = false) String note) {
    APIKey apiKey = apiKeyService.loadAPIKey(keyId);

        String isRestrictedKeyStr= request.getParameter("isRestrictedKey");
   
    boolean restricted = (isRestrictedKeyStr != null && isRestrictedKeyStr.equalsIgnoreCase("true")) ? true : false ;
   
    if (note != null) {
      apiKey.setNote(note);
      apiKey.setIsRestrictedKey(restricted);
      apiKeyService.storeAPIKey(apiKey);

            return RestResponse.success(apiKey);
    } else {
      log.warn(ResourceNotFoundException.getLogMessage("API Key", keyId));
View Full Code Here

            log.warn("Request to " + request.getPathInfo()
                    + " did not contain an API Key(blank).");
            return API_KEY_NOT_FOUND_ERROR;
        }

    APIKey key = apiKeyService.loadAPIKey(apiKey);
    boolean validRequest = key != null;

    if (validRequest) {
      log.info("API key with ID: " + key.getId() + " authenticated successfully on path: "
          + request.getPathInfo() + " for methodName: " + methodName);
     
      if (key.getIsRestrictedKey() &&
        restrictedMethods.contains(methodName)) {
          log.info("The API key attempted to request a protected URL.");
          return RESTRICTED_URL_ERROR;
      } else {
        return API_KEY_SUCCESS;
View Full Code Here

TOP

Related Classes of com.denimgroup.threadfix.data.entities.APIKey

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.