/** * Utility method to get the authenticated account username. This differs from * org.jboss.seam.security.Credentials.getUsername() in that this returns the actual account's * username, not the user provided one (which for some authentication systems is non-existent). * * @return The currently authenticated account username, or null if the session is not * authenticated. */ @Nullable public String getAccountUsername() { HAccount authenticatedAccount = ServiceLocator.instance().getInstance(HAccount.class, new AuthenticatedLiteral()); if (authenticatedAccount != null) { return authenticatedAccount.getUsername(); } return null; }
private void prepareTransUnitUpdatedEvent( int previousVersionNum, ContentState previousState, HTextFlowTarget target) { LocaleId localeId = target.getLocaleId(); HTextFlow textFlow = target.getTextFlow(); HDocument document = textFlow.getDocument(); HProjectIteration projectIteration = document.getProjectIteration(); String iterationSlug = projectIteration.getSlug(); String projectSlug = projectIteration.getProject().getSlug(); ProjectType projectType = projectIteration.getProjectType(); WorkspaceId workspaceId = new WorkspaceId(new ProjectIterationId(projectSlug, iterationSlug, projectType), localeId); Optional<TranslationWorkspace> workspaceOptional = translationWorkspaceManager.tryGetWorkspace(workspaceId); if (!workspaceOptional.isPresent()) { return; } TransUnitTransformer transUnitTransformer = serviceLocator.getInstance(TransUnitTransformer.class); TransUnit transUnit = transUnitTransformer.transform(textFlow, target, target.getLocale()); DocumentId documentId = new DocumentId(document.getId(), document.getDocId()); int wordCount = textFlow.getWordCount().intValue(); TransUnitUpdateInfo updateInfo = createTransUnitUpdateInfo( transUnit, documentId, wordCount, previousVersionNum, previousState); CacheValue context = updateContext.getIfPresent(new CacheKey(transUnit.getId(), transUnit.getLocaleId())); TransUnitUpdated updated; if (context != null) { updated = new TransUnitUpdated(updateInfo, context.editorClientId, context.updateType); log.debug("about to publish trans unit updated event {}", updated); } else if (ServletContexts.instance().getRequest() != null) { String sessionId = ServletContexts.instance().getRequest().getSession().getId(); EditorClientId editorClientId = new EditorClientId(sessionId, -1); updated = new TransUnitUpdated( updateInfo, editorClientId, TransUnitUpdated.UpdateType.NonEditorSave); } else { updated = new TransUnitUpdated( updateInfo, new EditorClientId("unknown", -1), TransUnitUpdated.UpdateType.NonEditorSave); } if (Events.exists()) { Events.instance() .raiseTransactionSuccessEvent( TextFlowTargetUpdatedEvent.EVENT_NAME, new TextFlowTargetUpdatedEvent(workspaceOptional.get(), target.getId(), updated)); } }
@Override public void afterOpenIdAuth(OpenIdAuthenticationResult result) { if (result.isAuthenticated()) { AccountDAO accountDAO = ServiceLocator.instance().getInstance(AccountDAO.class); HAccount account = accountDAO.getByCredentialsId(result.getAuthenticatedId()); if (account == null) { account = new HAccount(); // In case an account is not found } Contexts.getSessionContext().set("obsoleteAccount", account); // Outject // the // account } }
public static ZanataIdentity instance() { return ServiceLocator.instance().getInstance(ZanataIdentity.class); }