Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Merge remote branch 'origin/release' into integration/master
Browse files Browse the repository at this point in the history
Conflicts:
	functional-test/pom.xml
	pom.xml
	zanata-model/pom.xml
	zanata-war/pom.xml
  • Loading branch information
seanf committed Oct 23, 2013
2 parents 4a2113d + 1f0d6df commit d16230a
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 8 deletions.
Expand Up @@ -49,6 +49,10 @@ public class AuthenticationEvents implements Serializable {
@Observer(JpaIdentityStore.EVENT_USER_AUTHENTICATED)
public void loginSuccessful(HAccount account) {
log.info("Account {0} authenticated", account.getUsername());
injectAuthenticatedPersonIntoWorkingMemory(account);
}

public void injectAuthenticatedPersonIntoWorkingMemory(HAccount account) {
HPerson authenticatedPerson = account.getPerson();
// insert authenticatedPerson for use in security.drl rules
RuleBasedPermissionResolver.instance().getSecurityContext()
Expand Down
Expand Up @@ -24,6 +24,7 @@

import javax.security.auth.Subject;

import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Name;
Expand All @@ -32,14 +33,16 @@
import org.jboss.seam.security.RunAsOperation;

import lombok.extern.slf4j.Slf4j;
import org.zanata.action.AuthenticationEvents;
import org.zanata.dao.AccountDAO;
import org.zanata.model.HAccount;

/**
* This class executes a Runnable Process asynchronously. Do not use this class
* directly. Use {@link org.zanata.async.TaskExecutor} instead as this is just a
* wrapper to make sure Seam can run the task in the background.
* {@link TaskExecutor} is able to do this as well as return an instance of the
* task handle to keep track of the task's progress.
*
* @author Carlos Munoz <a
* href="mailto:camunoz@redhat.com">camunoz@redhat.com</a>
*/
Expand All @@ -48,16 +51,27 @@
@AutoCreate
@Slf4j
public class AsynchronousTaskExecutor {

/**
* Runs the provided task asynchronously with the given security
* constraints.
*
* @param task Task to run asynchronously.
* @param runAsPpal Security Principal to tun the task.
* @param runAsSubject Security Subject to run the task.
* @param username The username to run the task.
*/
@Asynchronous
public <V, H extends AsyncTaskHandle<V>> void runAsynchronously(
final AsyncTask<V, H> task, final Principal runAsPpal,
final Subject runAsSubject) {
final Subject runAsSubject, final String username) {
AsyncUtils.outject(task.getHandle(), ScopeType.EVENT);

RunAsOperation runAsOp = new RunAsOperation() {
@Override
public void execute() {
try {
prepareSecurityContext(username);
V returnValue = task.call();
task.getHandle().set(returnValue);
} catch (Exception t) {
Expand All @@ -82,4 +96,26 @@ public Subject getSubject() {
runAsOp.run();
}

/**
* Prepares the Drools security context so that it contains all the
* necessary facts for security checking.
*/
private static void prepareSecurityContext(String username) {
/*
* TODO This should be changed to not need the username. There should be
* a way to simulate a login for asyn tasks, or at least to inherit the
* caller's context
*/
if( username != null ) {
// Only if it's an authenticated task should it try and do this
// injection
AccountDAO accountDAO =
(AccountDAO) Component.getInstance(AccountDAO.class);
AuthenticationEvents authEvts =
(AuthenticationEvents) Component
.getInstance(AuthenticationEvents.class);
HAccount authenticatedAccount = accountDAO.getByUsername(username);
authEvts.injectAuthenticatedPersonIntoWorkingMemory(authenticatedAccount);
}
}
}
5 changes: 3 additions & 2 deletions zanata-war/src/main/java/org/zanata/async/TaskExecutor.java
Expand Up @@ -61,8 +61,9 @@ public <V, H extends AsyncTaskHandle<V>> AsyncTaskHandle<V> startTask(
}

Identity identity = Identity.instance();
asynchronousTaskExecutor.runAsynchronously(task,
identity.getPrincipal(), identity.getSubject());
asynchronousTaskExecutor.runAsynchronously(task, identity
.getPrincipal(), identity.getSubject(),
identity.getCredentials().getUsername());
return handle;
}

Expand Down
Expand Up @@ -26,8 +26,8 @@
<link type="text/css" rel="stylesheet"
href="//fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,400italic"/>

<script src="codemirror-compressed.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="codemirror.css"/>
<script src="codemirror/codemirror-compressed-3.16.cache.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="codemirror/codemirror-3.16.cache.css"/>

<script src="diff_match_patch/javascript/diff_match_patch.js"
type="text/javascript"></script>
Expand Down
Expand Up @@ -10,8 +10,8 @@
<link rel="stylesheet" href="images/fontello/css/fontello.css"/>
<link rel="stylesheet" href="../stylesheet/menu.css"/>

<script src="codemirror-compressed.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="codemirror.css"/>
<script src="codemirror/codemirror-compressed-3.16.cache.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="codemirror/codemirror-3.16.cache.css"/>

<script src="diff_match_patch/javascript/diff_match_patch.js"
type="text/javascript"></script>
Expand Down
@@ -0,0 +1,36 @@
The codemirror version number is incorporated in the filename to enable
correct caching in browsers.

When updating codemirror, be sure to change the filenames for
codemirror-*.cache.css and codemirror-compressed-*.cache.js and the
references to them in Application.xhtml and Dummy.html.


Recipe for codemirror-compressed.js:

codemirror-compressed.js is generated at http://codemirror.net/doc/compress.html
includes:
- codemirror.js
- css.js
- htmlmixed.js
- javascript.js
- xml.js
- runmode.js
- searchcursor.js (to enable highlight search term within codemirror"
- overlay.js (to support visible space)

added following custom code when generating the codemirror-compressed.js (to support visible space):

CodeMirror.defineMode("visibleSpace", function(config, parserConfig) {
var visibleSpaceOverlay = {
token: function(stream, state) {
var ch = stream.next();
if (ch == " ") {
return "space";
} else {
return null;
}
}
};
return CodeMirror.overlayMode(CodeMirror.getMode(config, parserConfig.backdrop || "htmlmixed"), visibleSpaceOverlay);
});

0 comments on commit d16230a

Please sign in to comment.