Examples of ChallengeRequest


Examples of org.restlet.data.ChallengeRequest

               } catch (IllegalArgumentException ex) {
                  getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
                  return null;
               }
            }
            getResponse().setChallengeRequests(Collections.singletonList(new ChallengeRequest(ChallengeScheme.HTTP_BASIC,realm==null ? "users" : "realm "+realm.getName())));
            getResponse().setStatus(Status.CLIENT_ERROR_UNAUTHORIZED);
            return null;
         }
         String authid = authorization.getIdentifier().trim();
         String password = new String(authorization.getSecret());
         User user = null;
         if (realm!=null) {
            RealmUser ruser = findRealmUser(db,realm,authid);
            if (ruser!=null) {
               user = ruser.getUser();
            }
            if (user==null) {
               // see if the user is a super user across realms
               user = findUser(db,authid);
               if (user!=null) {
                  // The user must either be a superuser or have the cross-realm permission
                  Permission superuser = db.getPermission(AuthDB.SUPERUSER_PERMISSION);
                  Permission crossrealm = db.getPermission(AuthDB.ACROSS_REALM_PERMISSION);
                  if (!user.hasPermission(superuser) && !user.hasPermission(crossrealm)) {
                     user = null;
                  }
               }
            }
         } else {
            user = findUser(db,authid);
         }
         if (user!=null) {
            try {
               String seconds = requestForm.getFirstValue("expiration");
               long requestExpiration = seconds==null ? expiration : Long.parseLong(seconds)*1000;
               if ("false".equals(requestForm.getFirstValue("session"))) {
                  requestExpiration = 0;
               }
               User.Authenticated authd = user.authenticate(realm,password,requestExpiration);
               if (authd!=null) {
                  String userAlias = authd.getUser().getAlias();
                  UUID userId = authd.getUser().getUUID();
                  String name = authd.getUser().getName();
                  String email = authd.getUser().getEmail();
                  Iterator<Group> groups = null;
                  Iterator<Role> roles = authd.getUser().getRoles();
                  // If we have a realm, we need the realm user to get the right alias
                  if (realm!=null) {
                     RealmUser ruser = db.findRealmUser(realm,authd.getUser());
                     if (ruser!=null) {
                        userAlias = ruser.getAlias();
                        name = ruser.getName();
                        email = ruser.getEmail();
                        groups = ruser.getGroups();
                     }
                  }
                  getResponse().setStatus(Status.SUCCESS_OK);
                  return getSessionEntity(authd.getSession(),userId,userAlias,name,email,roles,groups);
               }
            } catch (Exception ex) {
               getContext().getLogger().log(Level.SEVERE,"Failed to authenticate due to exception.",ex);
               getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
               return null;
            }
         }
         getResponse().setStatus(Status.CLIENT_ERROR_UNAUTHORIZED);
         getResponse().setChallengeRequests(Collections.singletonList(new ChallengeRequest(ChallengeScheme.HTTP_BASIC,realm==null ? "Realm Users" : "Users")));
      } catch (SQLException ex) {
         getContext().getLogger().log(Level.SEVERE,"Cannot get user data from database.",ex);
         getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
      }
      return null;
View Full Code Here

Examples of org.restlet.data.ChallengeRequest

   }
  
   protected void afterHandle(Request request, Response response) {
      if (response.getStatus()==Status.CLIENT_ERROR_UNAUTHORIZED) {
         List<ChallengeRequest> requests = new ArrayList<ChallengeRequest>();
         requests.add(new ChallengeRequest(challengeScheme,challengeRealm));
         response.setChallengeRequests(requests);
      }
   }
View Full Code Here

Examples of org.restlet.data.ChallengeRequest

    {
        ChallengeResponse challenge = Request.getCurrent().getChallengeResponse();
        if( challenge == null )
        {
            Response.getCurrent()
                .setChallengeRequests( Collections.singletonList( new ChallengeRequest( ChallengeScheme.HTTP_BASIC, "Forum" ) ) );
            throw new ResourceException( Status.CLIENT_ERROR_UNAUTHORIZED );
        }

        User user = module.currentUnitOfWork().newQuery( module.newQueryBuilder( User.class ).where( QueryExpressions
                                                                                                         .eq( QueryExpressions
View Full Code Here

Examples of org.restlet.data.ChallengeRequest

    }
    else {
      res.setStatus(Status.CLIENT_ERROR_FORBIDDEN);
    }

    res.getChallengeRequests().add(new ChallengeRequest(challengeScheme, realm));

    // TODO: this below would be _slightly_ better.
    // HttpServletRequest servletRequest = ( (ServletCall) ( (HttpRequest) req ).getHttpCall() ).getRequest();
    //
    // if ( servletRequest.getAttribute( NexusHttpAuthenticationFilter.ANONYMOUS_LOGIN ) != null )
View Full Code Here

Examples of org.restlet.data.ChallengeRequest

     * @param header
     *                The HTTP header value to parse.
     * @return The parsed challenge request.
     */
    public static ChallengeRequest parseRequest(String header) {
        ChallengeRequest result = null;

        if (header != null) {
            int space = header.indexOf(' ');

            if (space != -1) {
                String scheme = header.substring(0, space);
                String realm = header.substring(space + 1);
                int equals = realm.indexOf('=');
                String realmValue = realm.substring(equals + 2,
                        realm.length() - 1);
                result = new ChallengeRequest(new ChallengeScheme("HTTP_"
                        + scheme, scheme), realmValue);
            }
        }

        return result;
View Full Code Here

Examples of org.restlet.data.ChallengeRequest

                                "Error during cookie setting parsing. Header: "
                                        + header.getValue(), e);
                    }
                } else if (header.getName().equalsIgnoreCase(
                        HttpConstants.HEADER_WWW_AUTHENTICATE)) {
                    ChallengeRequest request = SecurityUtils
                            .parseRequest(header.getValue());
                    response.setChallengeRequest(request);
                } else if (header.getName().equalsIgnoreCase(
                        HttpConstants.HEADER_SERVER)) {
                    response.getServerInfo().setAgent(header.getValue());
View Full Code Here

Examples of org.restlet.data.ChallengeRequest

                                "Error during cookie setting parsing. Header: "
                                        + header.getValue(), e);
                    }
                } else if (header.getName().equalsIgnoreCase(
                        HttpConstants.HEADER_WWW_AUTHENTICATE)) {
                    ChallengeRequest request = SecurityUtils
                            .parseRequest(header.getValue());
                    response.setChallengeRequest(request);
                } else if (header.getName().equalsIgnoreCase(
                        HttpConstants.HEADER_SERVER)) {
                    response.getServerInfo().setAgent(header.getValue());
View Full Code Here

Examples of org.restlet.data.ChallengeRequest

     * @param header
     *                The HTTP header value to parse.
     * @return The parsed challenge request.
     */
    public static ChallengeRequest parseRequest(String header) {
        ChallengeRequest result = null;

        if (header != null) {
            int space = header.indexOf(' ');

            if (space != -1) {
                String scheme = header.substring(0, space);
                String realm = header.substring(space + 1);
                int equals = realm.indexOf('=');
                String realmValue = realm.substring(equals + 2,
                        realm.length() - 1);
                result = new ChallengeRequest(new ChallengeScheme("HTTP_"
                        + scheme, scheme), realmValue);
            }
        }

        return result;
View Full Code Here

Examples of org.restlet.data.ChallengeRequest

                            "Error during cookie setting parsing. Header: "
                                    + header.getValue(), e);
                }
            } else if (header.getName().equalsIgnoreCase(
                    HttpConstants.HEADER_WWW_AUTHENTICATE)) {
                final ChallengeRequest request = AuthenticationUtils
                        .parseAuthenticateHeader(header.getValue());
                response.setChallengeRequest(request);
            } else if (header.getName().equalsIgnoreCase(
                    HttpConstants.HEADER_SERVER)) {
                response.getServerInfo().setAgent(header.getValue());
View Full Code Here

Examples of org.restlet.data.ChallengeRequest

            response.getAttributes().put("stale", "true");
        }

        // This is temporary, pending Guard re-factoring. We still assume
        // there is only one challenge scheme, that of the Guard.
        ChallengeRequest mainChallengeRequest = null;
        for (final ChallengeRequest challengeRequest : response
                .getChallengeRequests()) {
            if (challengeRequest.getScheme().equals(guard.getScheme())) {
                mainChallengeRequest = challengeRequest;
                break;
            }
        }
        final Series<Parameter> parameters = mainChallengeRequest
                .getParameters();
        final StringBuffer domain = new StringBuffer();

        for (final String baseUri : guard.getDomainUris()) {
            domain.append(baseUri).append(' ');
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.