Created
May 8, 2012 09:08
-
-
Save BowlingX/2633780 to your computer and use it in GitHub Desktop.
Atmosphere with Scalatra and Apache Shiro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get("/status") { | |
val currentUser = SecurityUtils.getSubject(); | |
// Save current User to request, because this request will be suspended and forked in another thread. | |
// See: http://jfarcand.wordpress.com/2011/07/13/quick-tip-using-apache-shiro-with-your-atmospheres-websocketcomet-app/ | |
request.setAttribute("subject", currentUser); | |
import org.atmosphere.cpr.HeaderConfig._ | |
contentType = ContentType.JSON | |
val m: Meteor = Meteor.build(request) | |
m.addListener(new EventsLogger()) | |
// Create or retrieve Broadcaster for current User | |
val b = BroadcasterFactory.getDefault.lookup(currentUser.getPrincipal.toString, true) | |
// Set Scope explicitly to Application for access on different threads | |
b.setScope(Broadcaster.SCOPE.APPLICATION) | |
m.setBroadcaster(b) | |
if (Option(request.getHeader(X_ATMOSPHERE_TRANSPORT)) | |
.foldLeft(false)(_ || _.equalsIgnoreCase(LONG_POLLING_TRANSPORT))) { | |
m resumeOnBroadcast (true) | |
m suspend(-1, false); | |
} else { | |
m suspend -1; | |
} | |
"" | |
} | |
post("/status") { | |
val subject = Option(request.getAttribute("subject").asInstanceOf[Subject]) | |
.getOrElse(SecurityUtils.getSubject()); | |
val user = User.find(subject.getPrincipal.toString) | |
user foreach (configuration().infoMaster ! Info(_)) | |
"" | |
} |
did you get any solution for this ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Message in Safari after creating a socket: org.apache.shiro.UnavailableSecurityManagerException: No SecurityManager accessible to the calling code, either bound to the org.apache.shiro.util.ThreadContext or as a vm static singleton. This is an invalid application configuration.