Package org.mitre.openid.connect.model

Examples of org.mitre.openid.connect.model.ApprovedSite


     * @throws IOException
     */
    private void readGrants(JsonReader reader) throws IOException {
        reader.beginArray();
        while (reader.hasNext()) {
            ApprovedSite site = new ApprovedSite();
            Long currentId = null;
            Long whitelistedSiteId = null;
            Set<Long> tokenIds = null;
            reader.beginObject();
            while (reader.hasNext()) {
                switch (reader.peek()) {
                    case END_OBJECT:
                        continue;
                    case NAME:
                        String name = reader.nextName();
                        if (reader.peek() == JsonToken.NULL) {
                            reader.skipValue();
                        } else if (name.equals("id")) {
                            currentId = reader.nextLong();
                        } else if (name.equals("accessDate")) {
                            Date date = DateUtil.utcToDate(reader.nextString());
                            site.setAccessDate(date);
                        } else if (name.equals("clientId")) {
                            site.setClientId(reader.nextString());
                        } else if (name.equals("creationDate")) {
                            Date date = DateUtil.utcToDate(reader.nextString());
                            site.setCreationDate(date);
                        } else if (name.equals("timeoutDate")) {
                            Date date = DateUtil.utcToDate(reader.nextString());
                            site.setTimeoutDate(date);
                        } else if (name.equals("userId")) {
                            site.setUserId(reader.nextString());
                        } else if (name.equals("allowedScopes")) {
                            Set<String> allowedScopes = readSet(reader);
                            site.setAllowedScopes(allowedScopes);
                        } else if (name.equals("whitelistedSiteId")) {
                            whitelistedSiteId = reader.nextLong();
                        } else if (name.equals("approvedAccessTokens")) {
                            tokenIds = readSet(reader);
                        } else {
View Full Code Here


        for (Long oldGrantId : grantToWhitelistedSiteRefs.keySet()) {
            Long oldWhitelistedSiteId = grantToWhitelistedSiteRefs.get(oldGrantId);
            Long newWhitelistedSiteId = whitelistedSiteOldToNewIdMap.get(oldWhitelistedSiteId);
            WhitelistedSite wlSite = wlSiteRepository.getById(newWhitelistedSiteId);
            Long newGrantId = grantOldToNewIdMap.get(oldGrantId);
            ApprovedSite approvedSite = approvedSiteRepository.getById(newGrantId);
            approvedSite.setWhitelistedSite(wlSite);
            approvedSiteRepository.save(approvedSite);
        }
        grantToWhitelistedSiteRefs.clear();
        for (Long oldGrantId : grantToAccessTokensRefs.keySet()) {
            Set<Long> oldAccessTokenIds = grantToAccessTokensRefs.get(oldGrantId);
            Set<OAuth2AccessTokenEntity> tokens = new HashSet<OAuth2AccessTokenEntity>();
            for(Long oldTokenId : oldAccessTokenIds) {
                Long newTokenId = accessTokenOldToNewIdMap.get(oldTokenId);
                tokens.add(tokenRepository.getAccessTokenById(newTokenId));
            }
            Long newGrantId = grantOldToNewIdMap.get(oldGrantId);
            ApprovedSite site = approvedSiteRepository.getById(newGrantId);
            site.setApprovedAccessTokens(tokens);
            approvedSiteRepository.save(site);
        }
        accessTokenOldToNewIdMap.clear();
        grantOldToNewIdMap.clear();
    }
View Full Code Here

   * Delete an approved site
   *
   */
  @RequestMapping(value="/{id}", method = RequestMethod.DELETE)
  public String deleteApprovedSite(@PathVariable("id") Long id, ModelMap m, Principal p) {
    ApprovedSite approvedSite = approvedSiteService.getById(id);

    if (approvedSite == null) {
      logger.error("deleteApprovedSite failed; no approved site found for id: " + id);
      m.put("code", HttpStatus.NOT_FOUND);
      m.put("errorMessage", "Could not delete approved site. The requested approved site with id: " + id + " could not be found.");
      return JsonErrorView.VIEWNAME;
    } else if (!approvedSite.getUserId().equals(p.getName())) {
      logger.error("deleteApprovedSite failed; principal "
          + p.getName() + " does not own approved site" + id);
      m.put("code", HttpStatus.FORBIDDEN);
      m.put("errorMessage", "You do not have permission to delete this approved site. The approved site decision will not be deleted.");
      return JsonErrorView.VIEWNAME;
View Full Code Here

  /**
   * Get a single approved site
   */
  @RequestMapping(value="/{id}", method = RequestMethod.GET, produces = "application/json")
  public String getApprovedSite(@PathVariable("id") Long id, ModelMap m, Principal p) {
    ApprovedSite approvedSite = approvedSiteService.getById(id);
    if (approvedSite == null) {
      logger.error("getApprovedSite failed; no approved site found for id: " + id);
      m.put("code", HttpStatus.NOT_FOUND);
      m.put("errorMessage", "The requested approved site with id: " + id + " could not be found.");
      return JsonErrorView.VIEWNAME;
    } else if (!approvedSite.getUserId().equals(p.getName())) {
      logger.error("getApprovedSite failed; principal "
          + p.getName() + " does not own approved site" + id);
      m.put("code", HttpStatus.FORBIDDEN);
      m.put("errorMessage", "You do not have permission to view this approved site.");
      return JsonErrorView.VIEWNAME;
View Full Code Here

  }

  @Override
  @Transactional
  public void remove(ApprovedSite approvedSite) {
    ApprovedSite found = manager.find(ApprovedSite.class, approvedSite.getId());

    if (found != null) {
      manager.remove(found);
    } else {
      throw new IllegalArgumentException();
View Full Code Here

  }

  @Override
  @Transactional
  public ApprovedSite save(ApprovedSite approvedSite) {
    ApprovedSite a = approvedSiteRepository.save(approvedSite);
    statsService.resetCache();
    return a;
  }
View Full Code Here

  @Override
  @Transactional
  public ApprovedSite createApprovedSite(String clientId, String userId, Date timeoutDate, Set<String> allowedScopes,
      WhitelistedSite whitelistedSite) {

    ApprovedSite as = approvedSiteRepository.save(new ApprovedSite());

    Date now = new Date();
    as.setCreationDate(now);
    as.setAccessDate(now);
    as.setClientId(clientId);
    as.setUserId(userId);
    as.setTimeoutDate(timeoutDate);
    as.setAllowedScopes(allowedScopes);
    as.setWhitelistedSite(whitelistedSite);

    return save(as);

  }
View Full Code Here

     * @throws IOException
     */
    private void readGrants(JsonReader reader) throws IOException {
        reader.beginArray();
        while (reader.hasNext()) {
            ApprovedSite site = new ApprovedSite();
            Long currentId = null;
            Long whitelistedSiteId = null;
            Set<Long> tokenIds = null;
            reader.beginObject();
            while (reader.hasNext()) {
                switch (reader.peek()) {
                    case END_OBJECT:
                        continue;
                    case NAME:
                        String name = reader.nextName();
                        if (reader.peek() == JsonToken.NULL) {
                            reader.skipValue();
                        } else if (name.equals("id")) {
                            currentId = reader.nextLong();
                        } else if (name.equals("accessDate")) {
                            Date date = DateUtil.utcToDate(reader.nextString());
                            site.setAccessDate(date);
                        } else if (name.equals("clientId")) {
                            site.setClientId(reader.nextString());
                        } else if (name.equals("creationDate")) {
                            Date date = DateUtil.utcToDate(reader.nextString());
                            site.setCreationDate(date);
                        } else if (name.equals("timeoutDate")) {
                            Date date = DateUtil.utcToDate(reader.nextString());
                            site.setTimeoutDate(date);
                        } else if (name.equals("userId")) {
                            site.setUserId(reader.nextString());
                        } else if (name.equals("allowedScopes")) {
                            Set<String> allowedScopes = readSet(reader);
                            site.setAllowedScopes(allowedScopes);
                        } else if (name.equals("whitelistedSiteId")) {
                            whitelistedSiteId = reader.nextLong();
                        } else if (name.equals("approvedAccessTokens")) {
                            tokenIds = readSet(reader);
                        } else {
View Full Code Here

        for (Long oldGrantId : grantToWhitelistedSiteRefs.keySet()) {
            Long oldWhitelistedSiteId = grantToWhitelistedSiteRefs.get(oldGrantId);
            Long newWhitelistedSiteId = whitelistedSiteOldToNewIdMap.get(oldWhitelistedSiteId);
            WhitelistedSite wlSite = wlSiteRepository.getById(newWhitelistedSiteId);
            Long newGrantId = grantOldToNewIdMap.get(oldGrantId);
            ApprovedSite approvedSite = approvedSiteRepository.getById(newGrantId);
            approvedSite.setWhitelistedSite(wlSite);
            approvedSiteRepository.save(approvedSite);
        }
        grantToWhitelistedSiteRefs.clear();
        whitelistedSiteOldToNewIdMap.clear();
        for (Long oldGrantId : grantToAccessTokensRefs.keySet()) {
            Set<Long> oldAccessTokenIds = grantToAccessTokensRefs.get(oldGrantId);
            Set<OAuth2AccessTokenEntity> tokens = new HashSet<OAuth2AccessTokenEntity>();
            for(Long oldTokenId : oldAccessTokenIds) {
                Long newTokenId = accessTokenOldToNewIdMap.get(oldTokenId);
                tokens.add(tokenRepository.getAccessTokenById(newTokenId));
            }
            Long newGrantId = grantOldToNewIdMap.get(oldGrantId);
            ApprovedSite site = approvedSiteRepository.getById(newGrantId);
            site.setApprovedAccessTokens(tokens);
            approvedSiteRepository.save(site);
        }
        accessTokenOldToNewIdMap.clear();
        grantOldToNewIdMap.clear();
    }
View Full Code Here

      if (!alreadyApproved) {
        WhitelistedSite ws = whitelistedSiteService.getByClientId(clientId);
        if (ws != null && systemScopes.scopesMatch(ws.getAllowedScopes(), authorizationRequest.getScope())) {

          //Create an approved site
          ApprovedSite newSite = approvedSiteService.createApprovedSite(clientId, userId, null, ws.getAllowedScopes(), ws);
          authorizationRequest.getExtensions().put("approved_site", newSite.getId());
          authorizationRequest.setApproved(true);

          setAuthTime(authorizationRequest);
        }
      }
View Full Code Here

TOP

Related Classes of org.mitre.openid.connect.model.ApprovedSite

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.