use of com.enonic.xp.context.LocalScope in project xp by enonic.
the class AuthResourceTest method testAuthenticated_authenticated.
@Test
public void testAuthenticated_authenticated() throws Exception {
final User user = User.create().key(PrincipalKey.ofUser(IdProviderKey.system(), "user1")).displayName("User 1").modifiedTime(Instant.now(clock)).email("user1@enonic.com").login("user1").build();
final LocalScope localScope = ContextAccessor.current().getLocalScope();
final AuthenticationInfo authInfo = AuthenticationInfo.create().user(user).principals(RoleKeys.ADMIN_LOGIN).build();
localScope.setAttribute(authInfo);
localScope.setSession(new SessionMock());
String jsonString = request().path("auth/authenticated").get().getAsString();
assertJson("authenticated_success.json", jsonString);
}
use of com.enonic.xp.context.LocalScope in project xp by enonic.
the class LoginHandler method createSession.
private void createSession(final AuthenticationInfo authInfo) {
final LocalScope localScope = this.context.get().getLocalScope();
final Session session = localScope.getSession();
if (session != null) {
final var attributes = session.getAttributes();
session.invalidate();
final Session newSession = localScope.getSession();
if (newSession != null) {
attributes.forEach(newSession::setAttribute);
session.setAttribute(authInfo);
if (this.sessionTimeout != null) {
setSessionTimeout();
}
}
}
}
use of com.enonic.xp.context.LocalScope in project xp by enonic.
the class ContextMapper method getAttributes.
private Map<String, Object> getAttributes() {
LocalScope localScope = this.context.getLocalScope();
Map<String, Object> attributes = this.context.getAttributes();
Map<String, Object> localAttributes = localScope.getAttributes();
Session session = localScope.getSession();
Map<String, Object> sessionAttributes = session == null ? Map.of() : session.getAttributes();
return Stream.of(attributes, localAttributes, sessionAttributes).flatMap(map -> map.entrySet().stream()).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (v1, v2) -> v1, HashMap::new));
}
use of com.enonic.xp.context.LocalScope in project xp by enonic.
the class HtmlMacroProcessor method process.
public String process(final String text) {
final LocalScope localScope = ContextAccessor.current().getLocalScope();
return macroService.evaluateMacros(text, (macro) -> {
Integer macroDocCounter = (Integer) localScope.getAttribute(MACRO_DOCUMENT_COUNTER);
macroDocCounter = macroDocCounter == null ? 1 : macroDocCounter + 1;
final String documentRef = MACRO_DOCUMENT_REF_PREFIX + macroDocCounter;
localScope.setAttribute(documentRef, text);
localScope.setAttribute(MACRO_DOCUMENT_COUNTER, macroDocCounter);
macro = Macro.copyOf(macro).param(MacroInstruction.MACRO_DOCUMENT, documentRef).build();
return macroService.postProcessInstructionSerialize(macro);
});
}
Aggregations