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
trait TokenAuthenticator { | |
def apiTokenAuth(implicit dbSession: Session) = new ApiTokenAuthenticator() | |
} | |
class ApiTokenAuthenticator(implicit val dbSession: Session, implicit val executionContext: ExecutionContext) extends HttpAuthenticator[User] { | |
override def getChallengeHeaders(httpRequest: HttpRequest): List[HttpHeader] = | |
`WWW-Authenticate`(HttpChallenge(scheme = "Token", realm = "Manta", params = Map.empty)) :: Nil | |
override def authenticate(credentials: Option[HttpCredentials], ctx: RequestContext): Future[Option[User]] = | |
Future.successful( |
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
package manta | |
import manta.routes.Users | |
import spray.routing.HttpService | |
import scala.concurrent.ExecutionContext.Implicits.global | |
trait SecuredRoutes extends HttpService with Users with TokenAuthenticator { | |
val routes = authenticate(basicTokenAuth) { implicit user => | |
usersRoute |
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
apply plugin: 'java' | |
apply plugin: 'eclipse' | |
repositories { | |
mavenCentral() | |
} | |
dependencies { | |
compile "joda-time:joda-time:2.2" | |
} |
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
source :rubygems | |
# We are not loading Active Record, nor Active Resources etc. | |
# We can do this in any app by simply replacing the rails gem | |
# by the parts we want to use. | |
gem "actionpack", "~> 3.2" | |
gem "railties", "~> 3.2" | |
gem "tzinfo" | |
# Let's use thin |
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
package com.ab.jersey.dto; | |
public class AppError { | |
private String message; | |
public AppError() { } | |
public AppError(String message) { | |
this.message = message; | |
} |
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
public class UserDao extends SimpleJdbcDaoSupport { | |
private static final String CREATE_USER_SQL = "insert into users(name, created_at, updated_at) values (?,?,?)"; | |
public int createUser(String username) { | |
Connection cnn = null; | |
PreparedStatement pstmt = null; | |
ResultSet rsId = null; | |
int id = 0; | |
try { |
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
import java.io.IOException; | |
import java.io.InputStream; | |
import java.util.Properties; | |
import javax.mail.Address; | |
import javax.mail.Authenticator; | |
import javax.mail.Message; | |
import javax.mail.MessagingException; | |
import javax.mail.PasswordAuthentication; | |
import javax.mail.Session; |
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
.horizontal_list { | |
font-size: 14px; | |
width: 100%; | |
overflow: hidden; | |
} | |
.horizontal_list ul { | |
margin: 3px; | |
text-align: center; | |
float: right; |
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
public static Calendar convertTimeToEST(long timeInMillSec) { | |
Calendar cal = Calendar.getInstance(); | |
TimeZone tz = cal.getTimeZone(); | |
cal.setTimeInMillis(timeInMillSec); | |
TimeZone estTz = TimeZone.getTimeZone("America/New_York"); | |
Calendar estCal = Calendar.getInstance(estTz); | |
estCal.setTimeInMillis(timeInMillSec); | |
int tzOffset = tz.getOffset(cal.getTime().getTime()); | |
int estTzOffset = estTz.getOffset(estCal.getTime().getTime()); |
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
import static org.mockito.Mockito.verify; | |
import static org.mockito.Mockito.when; | |
import static org.mockito.Mockito.*; | |
import java.io.ByteArrayInputStream; | |
import java.io.ByteArrayOutputStream; | |
import java.io.IOException; | |
import java.net.Socket; | |
import junit.framework.Assert; |