Refine search
protected void setupAuth(Request request) { if (authType == AUTH_TYPE_BASIC) { ChallengeScheme scheme = ChallengeScheme.HTTP_BASIC; ChallengeResponse authentication = new ChallengeResponse(scheme, userName, password); request.setChallengeResponse(authentication); } else if (authType == AUTH_TYPE_SECRET) { Series<Parameter> additionnalHeaders = new Form(); Map<String, String> securityHeaders = PortalSSOAuthenticationProvider.getHeaders(secretToken, userName); for (String hn : securityHeaders.keySet()) { additionnalHeaders.add(hn, securityHeaders.get(hn)); } request.getAttributes().put("org.restlet.http.headers", additionnalHeaders); } }
/** * Invoked upon failed authentication. By default, it updates the request's * clientInfo and challengeResponse "authenticated" properties, and returns * {@link Filter#STOP}. * * @param request * The request sent. * @param response * The response to update. * @return The filter continuation code. */ protected int unauthenticated(Request request, Response response) { boolean loggable = request.isLoggable() && getLogger().isLoggable(Level.FINE); if (request.getChallengeResponse() != null && loggable) { getLogger().log( Level.FINE, "The authentication failed for the identifer \"" + request.getChallengeResponse().getIdentifier() + "\" using the " + request.getChallengeResponse().getScheme() + " scheme."); } // Update the client info accordingly if (request.getClientInfo() != null) { request.getClientInfo().setAuthenticated(false); } // Stop the filtering chain return STOP; }
@Override public void formatCredentials( StringBuilder sb, ChallengeResponse challenge, Request request, Series<Parameter> httpHeaders ) { try { final String credentials = challenge.getIdentifier() + ':' + new String( challenge.getSecret() ); sb.append( Base64.encode( credentials.getBytes( "US-ASCII" ), false ) ); } catch ( final UnsupportedEncodingException e ) { throw new RuntimeException( "Unsupported encoding, unable to encode credentials" ); } }
/** {@inheritDoc} */ @Override public int hashCode() { return Engine.hashCode(getScheme(), getIdentifier(), (getSecret() == null) ? null : new String(getSecret()), getCredentials()); }
/** {@inheritDoc} */ @Override public int hashCode() { // Note that the secret is simply discarded from hash code calculation // because we don't want it to be materialized as a string return SystemUtils .hashCode(getScheme(), getIdentifier(), getRawValue()); }
if (!Objects.equals(getRawValue(), that.getRawValue()) || !Objects.equals(getIdentifier(), that.getIdentifier()) || !Objects.equals(getScheme(), that.getScheme())) { return false; if ((getSecret() == null) || (that.getSecret() == null)) { return (getSecret() == that.getSecret()); if (getSecret().length != that.getSecret().length) { return false; for (int i = 0; equals && (i < getSecret().length); i++) { equals = (getSecret()[i] == that.getSecret()[i]);
result = (this.request != null) ? this.request.getAttributes().get(variableName) : null; if (result != null) { return result; ChallengeResponse cr = this.request.getChallengeResponse(); Representation entity = this.request.getEntity(); return this.request.getClientInfo().getAgent(); case "cri": return (cr != null) ? cr.getIdentifier() : null; case "crs": return (cr != null && cr.getScheme() != null) ? cr.getScheme().getTechnicalName() : null; case "d": return DateUtils.format(new Date(), FORMAT_RFC_1123.get(0));
@Override public void handle(Request request, Response response) { try { if (Protocol.FTP.equals(request.getProtocol())) { if (Method.GET.equals(request.getMethod())) { Reference ftpRef = request.getResourceRef(); String userInfo = null; if ((request.getChallengeResponse() != null) && ChallengeScheme.FTP_PLAIN.equals(request .getChallengeResponse().getScheme()) && (request.getChallengeResponse().getIdentifier() != null)) { userInfo = request.getChallengeResponse() .getIdentifier(); if (request.getChallengeResponse().getSecret() != null) { userInfo += ":" + new String(request.getChallengeResponse() .getSecret());
@Override protected void afterHandle(Request request, Response response) { super.afterHandle(request, response); Cookie cookie = request.getCookies().getFirst("Credentials"); if (request.getClientInfo().isAuthenticated() && (cookie == null)) { String identifier = request.getChallengeResponse().getIdentifier(); String secret = new String(request.getChallengeResponse() .getSecret()); CookieSetting cookieSetting = new CookieSetting("Credentials", identifier + "=" + secret); cookieSetting.setAccessRestricted(true); cookieSetting.setPath("/"); cookieSetting.setComment("Unsecured cookie based authentication"); cookieSetting.setMaxAge(30); response.getCookieSettings().add(cookieSetting); } }
@Override protected int beforeHandle(Request request, Response response) { Cookie cookie = request.getCookies().getFirst("Credentials"); if (cookie != null) { // Extract the challenge response from the cookie String[] credentials = cookie.getValue().split("="); if (credentials.length == 2) { String identifier = credentials[0]; String secret = credentials[1]; request.setChallengeResponse(new ChallengeResponse( ChallengeScheme.HTTP_COOKIE, identifier, secret)); } } else if (Method.POST.equals(request.getMethod()) && request.getResourceRef().getQueryAsForm().getFirst("login") != null) { // Intercepting a login form Form credentials = new Form(request.getEntity()); String identifier = credentials.getFirstValue("identifier"); String secret = credentials.getFirstValue("secret"); request.setChallengeResponse(new ChallengeResponse( ChallengeScheme.HTTP_COOKIE, identifier, secret)); // Continue call processing to return the target representation if // authentication is successful or a new login page request.setMethod(Method.GET); } return super.beforeHandle(request, response); }
String clientAddress = request.getClientInfo().getUpstreamAddress(); sb.append((clientAddress == null) ? "-" : clientAddress); sb.append('\t'); request.getClientInfo().getUpstreamAddress(), request .getClientInfo().getPort(), response .getServerInfo().getPort()); sb.append((ic.getUserIdentifier() == null) ? "-" : ic .getUserIdentifier()); } else if ((request.getChallengeResponse() != null) && (request.getChallengeResponse().getIdentifier() != null)) { sb.append(request.getChallengeResponse().getIdentifier()); } else { sb.append('-');
@Override public int verify(Request request, Response response) { final String token; try { ChallengeResponse cr = request.getChallengeResponse(); if (cr == null) { return RESULT_MISSING; } else if (ChallengeScheme.HTTP_OAUTH_BEARER.equals(cr.getScheme())) { final String bearer = cr.getRawValue(); if (bearer == null || bearer.isEmpty()) { return RESULT_MISSING; } token = bearer; } else { return RESULT_UNSUPPORTED; } } catch (Exception ex) { return RESULT_INVALID; } Try<User> user = accessTokenVerificationCommandFactory.createVerificationCommand(token).executeCommand(); return user.map(u -> { org.restlet.security.User restletUser = createRestletUser(u); request.getClientInfo().setUser(restletUser); request.getAttributes().put("token", token); return RESULT_VALID; }).orElse(RESULT_INVALID); }
public int verify(Request request, Response response) { final String clientId; final char[] clientSecret; ChallengeResponse cr = request.getChallengeResponse(); if (cr == null) { if (!isAcceptBodyMethod()) { Form params = new Form(request.getEntity()); clientId = params.getFirstValue(OAuthServerResource.CLIENT_ID); if (clientId == null || clientId.isEmpty()) { request.setEntity(params.getWebRepresentation()); } else { if (!cr.getScheme().equals(ChallengeScheme.HTTP_BASIC)) { clientId = cr.getIdentifier(); clientSecret = cr.getSecret();
Representation entity = request.getEntity(); if (entity != null && entity.getMediaType().equals( Form form = new Form(entity); form.add(ACCESS_TOKEN, token.getAccessToken()); request.setEntity(form.getWebRepresentation()); } else { request.getResourceRef().addQueryParameter(ACCESS_TOKEN, token.getAccessToken()); ChallengeResponse cr = new ChallengeResponse( ChallengeScheme.HTTP_OAUTH_BEARER); cr.setRawValue(token.getAccessToken()); request.setChallengeResponse(cr);
private HandlerCommand invokeQuery( Reference ref, Object queryRequest, ResponseHandler resourceHandler, ResponseHandler processingErrorHandler ) Request request = new Request( Method.GET, ref ); User user = request.getClientInfo().getUser(); if ( user != null) request.setChallengeResponse( new ChallengeResponse( ChallengeScheme.HTTP_BASIC, user.getName(), user.getSecret() ) );
public static void main(String[] args) throws Exception { // Prepare the request Request request = new Request(Method.GET, "http://s3.amazonaws.com/quotes/nelson"); request.setChallengeResponse(new ChallengeResponse( ChallengeScheme.HTTP_AWS_S3, "44CF9590006BF252F707", "OtxrzxIsfpFjA7SwPzILwy8Bw21TLhquhboDYROV")); // Add some extra headers Series<Header> extraHeaders = new Series<Header>(Header.class); extraHeaders.add("X-Amz-Meta-Author", "foo@bar.com"); extraHeaders.add("X-Amz-Magic", "abracadabra"); // For the test we hard coded a special date header. Normally you don't // need this as the // HTTP client connector will automatically provide an accurate Date // header and use it // for authentication. // extraHeaders.add("X-Amz-Date", "Thu, 17 Nov 2005 18:49:58 GMT"); request.getAttributes().put(HeaderConstants.ATTRIBUTE_HEADERS, extraHeaders); // Handle it using an HTTP client connector Client client = new Client(Protocol.HTTP); Response response = client.handle(request); // Write the response entity on the console Representation output = response.getEntity(); output.write(System.out); }
@Override public List<Car> list() { Client client = new Client(new Context(), Protocol.HTTPS); Series<Parameter> parameters = client.getContext().getParameters(); parameters.add("truststorePath", System.getProperty("javax.net.ssl.trustStore")); ClientResource clientResource = new ClientResource("https://localhost:8043/api/cars/cars"); clientResource.setNext(client); ChallengeResponse challenge = new ChallengeResponse(ChallengeScheme.HTTP_OAUTH_BEARER); challenge.setRawValue(Request.getCurrent().getAttributes().getOrDefault("token", "").toString()); clientResource.setChallengeResponse(challenge); CarServiceInterface carServiceInterface = clientResource.wrap(CarServiceInterface.class); Car[] allCars = carServiceInterface.getAllCars(); try { client.stop(); } catch (Exception e) { throw new RuntimeException(e); } return asList(allCars); } }
if (challengeResponse.getScheme().equals(c.getScheme())) { challengeRequest = c; break; realm = challengeRequest.getRealm(); nonce = challengeRequest.getServerNonce(); challengeResponse.setOpaque(challengeRequest.getOpaque()); challengeResponse.setRealm(realm); challengeResponse.setServerNonce(nonce); challengeResponse.setDigestRef(new Reference(request.getResourceRef() .getPath()));
/** * Sets the authentication response sent by a client to an origin server * given a scheme, identifier and secret. * * @param scheme * The challenge scheme. * @param identifier * The user identifier, such as a login name or an access key. * @param secret * The user secret, such as a password or a secret key. */ public void setChallengeResponse(ChallengeScheme scheme, final String identifier, String secret) { setChallengeResponse(new ChallengeResponse(scheme, identifier, secret)); }
@SubResource public void administration() { 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 = select( Users.class, Users.USERS_ID ).userNamed( challenge.getIdentifier() ); if( user == null || !user.isCorrectPassword( new String( challenge.getSecret() ) ) ) { throw new ResourceException( Status.CLIENT_ERROR_UNAUTHORIZED ); } current().select( user ); subResource( AdministrationResource.class ); }