use of org.restlet.Request in project OpenAM by OpenRock.
the class AbstractRestletAccessAuditFilterTest method shouldCallHandleOnRestlet.
@Test
public void shouldCallHandleOnRestlet() {
// Given
Request request = mock(Request.class);
Response response = new Response(request);
Representation representation = mock(Representation.class);
when(request.getEntity()).thenReturn(representation);
when(request.getAttributes()).thenReturn(new ConcurrentHashMap<String, Object>());
when(representation.isTransient()).thenReturn(false);
when(eventPublisher.isAuditing(anyString(), anyString(), any(EventName.class))).thenReturn(false);
// When
auditFilter.handle(request, response);
// Then
verify(restlet, times(1)).handle(any(Request.class), any(Response.class));
}
use of org.restlet.Request in project OpenAM by OpenRock.
the class XacmlService method checkPermission.
/**
* Check if this user has permission to perform the given action (which will be "read" in the case of export
* and "modify" in the case of import).
*
* @return true if the user has permission, false otherwise.
*/
@VisibleForTesting
boolean checkPermission(String action) throws EntitlementException {
try {
Request restletRequest = getRequest();
String urlLastSegment = restletRequest.getResourceRef().getLastSegment();
String realm = RestletRealmRouter.getRealmFromRequest(restletRequest);
final Map<String, String> context = (Map<String, String>) ServletUtils.getRequest(getRequest()).getAttribute(FORGEROCK_AUTH_CONTEXT);
final String tokenId = context.get("tokenId");
final SSOToken token = SSOTokenManager.getInstance().createSSOToken(tokenId);
return checkPermission(action, urlLastSegment, realm, token);
} catch (SSOException e) {
debug.warning("XacmlService permission evaluation failed", e);
throw new EntitlementException(INTERNAL_ERROR, e);
}
}
use of org.restlet.Request in project OpenAM by OpenRock.
the class OpenAMTokenStoreTest method setUp.
@BeforeMethod
public void setUp() {
tokenStore = mock(OAuthTokenStore.class);
providerSettingsFactory = mock(OAuth2ProviderSettingsFactory.class);
oAuth2UrisFactory = mock(OAuth2UrisFactory.class);
clientRegistrationStore = mock(OpenIdConnectClientRegistrationStore.class);
realmNormaliser = mock(RealmNormaliser.class);
ssoTokenManager = mock(SSOTokenManager.class);
request = mock(Request.class);
cookieExtractor = mock(CookieExtractor.class);
auditLogger = mock(OAuth2AuditLogger.class);
debug = mock(Debug.class);
failureFactory = mock(ClientAuthenticationFailureFactory.class);
oAuth2RequestFactory = new RestletOAuth2RequestFactory(new JacksonRepresentationFactory(new ObjectMapper()));
ClientAuthenticationFailureFactory failureFactory = mock(ClientAuthenticationFailureFactory.class);
InvalidClientException expectedResult = mock(InvalidClientException.class);
when(expectedResult.getError()).thenReturn(new String("invalid_client"));
when(failureFactory.getException()).thenReturn(expectedResult);
when(failureFactory.getException(anyString())).thenReturn(expectedResult);
when(failureFactory.getException(any(OAuth2Request.class), anyString())).thenReturn(expectedResult);
openAMtokenStore = new OpenAMTokenStore(tokenStore, providerSettingsFactory, oAuth2UrisFactory, clientRegistrationStore, realmNormaliser, ssoTokenManager, cookieExtractor, auditLogger, debug, new SecureRandom(), failureFactory);
}
use of org.restlet.Request in project OpenAM by OpenRock.
the class AccessTokenProtectionFilterTest method testBeforeHandleWithoutNeedingScope.
@Test
public void testBeforeHandleWithoutNeedingScope() throws Exception {
//Given
filter = new AccessTokenProtectionFilter(null, tokenStore, requestFactory, null);
Request req = mock(Request.class);
Response resp = mock(Response.class);
OAuth2Request oAuth2Request = mock(OAuth2Request.class);
when(requestFactory.create(req)).thenReturn(oAuth2Request);
ChallengeResponse challengeResponse = new ChallengeResponse(ChallengeScheme.HTTP_BASIC);
challengeResponse.setRawValue("tokenId");
when(req.getChallengeResponse()).thenReturn(challengeResponse);
AccessToken accessToken = new AccessToken(json(object(field("id", "tokenId"), field("tokenName", "access_token"), field("scope", asSet("a")), field("expireTime", System.currentTimeMillis() + 5000))));
when(tokenStore.readAccessToken(oAuth2Request, "tokenId")).thenReturn(accessToken);
//When
int result = filter.beforeHandle(req, resp);
//Then
assertThat(result).isEqualTo(Filter.CONTINUE);
}
use of org.restlet.Request in project OpenAM by OpenRock.
the class RestletFormBodyAccessTokenVerifierTest method shouldCheckBodyType.
@Test
public void shouldCheckBodyType() throws Exception {
// Given
Request request = new Request();
request.setEntity(new EmptyRepresentation());
OAuth2Request req = new RestletOAuth2Request(null, request);
// When
AccessTokenVerifier.TokenState result = verifier.verify(req);
// Then
assertThat(result.isValid()).isFalse();
}
Aggregations