use of org.restlet.engine.adapter.HttpRequest in project OpenAM by OpenRock.
the class RestletHeaderAccessTokenVerifierTest method shouldCheckHttpHeader.
@Test
public void shouldCheckHttpHeader() throws Exception {
// Given
ServerCall serverCall = mock(ServerCall.class);
HttpRequest request = mock(HttpRequest.class);
OAuth2Request req = new RestletOAuth2Request(null, request);
when(request.getHttpCall()).thenReturn(serverCall);
Series<Header> requestHeaders = new Series<Header>(Header.class);
requestHeaders.add(new Header(HeaderConstants.HEADER_AUTHORIZATION, "Bearer freddy"));
when(request.getHttpCall().getRequestHeaders()).thenReturn(requestHeaders);
// When
AccessTokenVerifier.TokenState result = verifier.verify(req);
// Then
assertThat(result.isValid()).isFalse();
verify(tokenStore).readAccessToken(req, "freddy");
}
use of org.restlet.engine.adapter.HttpRequest in project OpenAM by OpenRock.
the class RestletRealmRouterTest method shouldHandleQueryParamRealmWithNoLeadingSlash.
@Test
public void shouldHandleQueryParamRealmWithNoLeadingSlash() throws IdRepoException, SSOException {
//Given
SSOToken adminToken = mock(SSOToken.class);
Restlet next = mock(Restlet.class);
HttpServletRequest httpRequest = mock(HttpServletRequest.class);
Request request = setUpRequest(httpRequest, adminToken);
Response response = mock(Response.class);
setUpServerName(request, adminToken, "/");
Reference reference = mock(Reference.class);
given(request.getResourceRef()).willReturn(reference);
Reference baseRef = mock(Reference.class);
given(reference.getBaseRef()).willReturn(baseRef);
given(baseRef.toString()).willReturn("The base url");
Form queryForm = mock(Form.class);
given(reference.getQueryAsForm()).willReturn(queryForm);
given(queryForm.getFirstValue("realm")).willReturn("REALM");
setUpRealmValidator("REALM", false, adminToken);
//When
router.doHandle(next, request, response);
//Then
assertThat(request.getAttributes()).containsEntry("realm", "/REALM");
verify(httpRequest).setAttribute("realm", "/REALM");
}
use of org.restlet.engine.adapter.HttpRequest in project OpenAM by OpenRock.
the class RestletRealmRouterTest method shouldRouteToRealm.
@Test(dataProvider = "realmRoutingDataProvider")
public void shouldRouteToRealm(String realmLocation, boolean isRealmAlias) throws Exception {
//Given
SSOToken adminToken = mock(SSOToken.class);
Restlet next = mock(Restlet.class);
HttpServletRequest httpRequest = mock(HttpServletRequest.class);
Request request = setUpRequest(httpRequest, adminToken);
Response response = mock(Response.class);
String realm;
if (!isRealmAlias) {
realm = "REALM";
} else {
realm = "REALM_ALIAS";
}
if ("dns".equalsIgnoreCase(realmLocation)) {
//set up server name
setUpServerName(request, adminToken, realm);
}
if ("query".equalsIgnoreCase(realmLocation)) {
//set up query string
setUpServerName(request, adminToken, "/");
setUpQueryString(request, realm);
}
if ("uri".equalsIgnoreCase(realmLocation)) {
//set up uri
setUpServerName(request, adminToken, "/");
setUpUri(request, realm);
}
//set up validate realm
setUpRealmValidator(realm, isRealmAlias, adminToken);
//When
router.doHandle(next, request, response);
//Then
assertThat(request.getAttributes()).containsEntry("realm", "/REALM");
verify(httpRequest).setAttribute("realm", "/REALM");
assertThat(request.getAttributes()).containsEntry("realmUrl", "The base url");
}
use of org.restlet.engine.adapter.HttpRequest in project OpenAM by OpenRock.
the class RestletRealmRouterTest method setUpRequest.
private Request setUpRequest(HttpServletRequest httpRequest, SSOToken adminToken) {
HttpRequest request = generateRequest();
ServletCall serverCall = mock(ServletCall.class);
given(request.getHttpCall()).willReturn(serverCall);
given(serverCall.getRequest()).willReturn(httpRequest);
Reference reference = mock(Reference.class);
given(request.getResourceRef()).willReturn(reference);
Form queryForm = mock(Form.class);
given(reference.getQueryAsForm()).willReturn(queryForm);
Reference baseReference = mock(Reference.class);
given(reference.getBaseRef()).willReturn(baseReference);
given(baseReference.toString()).willReturn("The base url");
given(coreWrapper.getAdminToken()).willReturn(adminToken);
return request;
}
use of org.restlet.engine.adapter.HttpRequest in project OpenAM by OpenRock.
the class RestletHeaderAccessTokenVerifier method getChallengeResponse.
/**
* Returns the authentication response sent by a client to an origin server
* instead of org.restlet.engine.adapter.HttpRequest.
*
* @return The authentication response sent by a client to an origin server.
*/
public ChallengeResponse getChallengeResponse(Request request) {
if (request instanceof HttpRequest) {
// Extract the header value
final Series<Header> headers = ((HttpRequest) request).getHttpCall().getRequestHeaders();
final String authorization = headers.getValues(HeaderConstants.HEADER_AUTHORIZATION);
if (authorization != null) {
int space = authorization.indexOf(' ');
if (space != -1) {
String scheme = authorization.substring(0, space);
if (scheme.equalsIgnoreCase("Bearer")) {
ChallengeResponse result = new ChallengeResponse(new ChallengeScheme("HTTP_" + scheme, scheme));
result.setRawValue(authorization.substring(space + 1));
request.setChallengeResponse(result);
return result;
}
}
}
}
return request.getChallengeResponse();
}
Aggregations