use of org.forgerock.services.context.RootContext in project OpenAM by OpenRock.
the class RestRouterIT method mockContext.
private Context mockContext(Context parent) {
if (parent == null) {
parent = new RootContext();
}
AttributesContext httpRequestContext = new AttributesContext(new SessionContext(parent, mock(Session.class)));
HttpServletRequest httpServletRequest = mock(HttpServletRequest.class);
httpRequestContext.getAttributes().put(HttpServletRequest.class.getName(), httpServletRequest);
return new RequestAuditContext(httpRequestContext);
}
use of org.forgerock.services.context.RootContext in project OpenAM by OpenRock.
the class ElevatedConnectionFactoryWrapperTest method requestGetsElevatedToAdminSession.
@Test
public void requestGetsElevatedToAdminSession() throws Exception {
// Given
SSOToken ssoToken = mock(SSOToken.class);
given(ssoTokenPrivilegedAction.run()).willReturn(ssoToken);
SSOPrincipal principal = new SSOPrincipal("test");
given(ssoToken.getPrincipal()).willReturn(principal);
SSOTokenID tokenID = mock(SSOTokenID.class);
given(ssoToken.getTokenID()).willReturn(tokenID);
given(internalConnectionFactory.getConnection()).willReturn(connection);
// When
RootContext context = new RootContext();
ReadRequest readRequest = Requests.newReadRequest("/test", "abc");
try (Connection connection = connectionFactory.getConnection()) {
connection.read(context, readRequest);
}
// Then
verify(connection).read(contextCaptor.capture(), eq(readRequest));
Context capturedContext = contextCaptor.getValue();
assertThat(capturedContext.containsContext(SecurityContext.class)).isTrue();
SecurityContext securityContext = capturedContext.asContext(SecurityContext.class);
assertThat(securityContext.getAuthenticationId()).isEqualTo("test");
assertThat(securityContext.getAuthorization()).containsOnlyKeys("authLevel", "tokenId");
}
use of org.forgerock.services.context.RootContext in project OpenAM by OpenRock.
the class RealmContextTest method getRelativeRealmShouldReturnRootRealmWhenNotSet.
@Test
public void getRelativeRealmShouldReturnRootRealmWhenNotSet() {
//Given
RealmContext context = new RealmContext(new RootContext());
//When
String relativeRealm = context.getRelativeRealm();
//Then
assertThat(relativeRealm).isEqualTo("/");
}
use of org.forgerock.services.context.RootContext in project OpenAM by OpenRock.
the class RealmContextTest method staticHelperMethodReturnsAppropriateRealm.
@Test
public void staticHelperMethodReturnsAppropriateRealm() {
//Given
RealmContext context = new RealmContext(new RootContext());
context.setSubRealm("SUB_REALM", "/some/realm");
//When
String realm = RealmContext.getRealm(context);
//Then
assertThat(realm).isEqualTo("/some/realm");
}
use of org.forgerock.services.context.RootContext in project OpenAM by OpenRock.
the class UmaResourceSetRegistrationHook method createAdminContext.
/**
* Used to create a context for deleting policies. If this is being called, we know that the user has the right
* to delete the policies.
* @param realm The realm to delete the policies in.
* @param resourceOwnerId The owner of the ResourceSet that the policies are for.
* @return The generated context.
*/
private Context createAdminContext(String realm, String resourceOwnerId) {
RealmContext realmContext = new RealmContext(new RootContext());
realmContext.setSubRealm(realm, realm);
SubjectContext subjectContext = new AdminSubjectContext(logger, sessionCache, realmContext);
Map<String, String> templateVariables = new HashMap<>();
templateVariables.put("user", resourceOwnerId);
UriRouterContext routerContext = new UriRouterContext(subjectContext, "", "", templateVariables);
return routerContext;
}
Aggregations