use of io.divide.shared.transitory.Credentials in project divide by HiddenStage.
the class ResponseFilter method filter.
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {
SecurityContext context = requestContext.getSecurityContext();
if (context != null && context instanceof UserContext) {
UserContext userContext = (UserContext) context;
Credentials user = userContext.getUser();
if (user != null && user.getAuthToken() != null) {
responseContext.getHeaders().add("Authorization", user.getAuthToken());
}
}
}
use of io.divide.shared.transitory.Credentials in project divide by HiddenStage.
the class AuthenticationEndpoint method userSignIn.
/**
* Checks username/password against that stored in DB, if same return
* token, if token expired create new.
* @param credentials
* @return authentication token
*/
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response userSignIn(@Context ContainerRequestContext context, Credentials credentials) {
try {
Credentials dbCreds = authServerLogic.userSignIn(credentials);
context.setSecurityContext(new UserContext(context.getUriInfo(), dbCreds));
logger.info("Login Successful. Returning: " + dbCreds);
return ok(dbCreds);
} catch (ServerDAO.DAOException e) {
logger.severe(ExceptionUtils.getStackTrace(e));
return fromDAOExpection(e);
} catch (Exception e) {
logger.severe(ExceptionUtils.getStackTrace(e));
return Response.serverError().build();
}
}
use of io.divide.shared.transitory.Credentials in project divide by HiddenStage.
the class AuthenticationEndpoint method recoverFromOneTimeToken.
@GET
@Path("/recover/{token}")
@Produces(MediaType.APPLICATION_JSON)
public Response recoverFromOneTimeToken(@Context ContainerRequestContext context, @PathParam("token") String token) {
try {
Credentials user = authServerLogic.getUserFromRecoveryToken(token);
context.setSecurityContext(new UserContext(context.getUriInfo(), user));
return Response.ok(user).build();
} catch (ServerDAO.DAOException e) {
e.printStackTrace();
logger.severe(ExceptionUtils.getStackTrace(e));
return fromDAOExpection(e);
}
}
use of io.divide.shared.transitory.Credentials in project divide by HiddenStage.
the class AuthenticationEndpointTest method testUserSignIn.
@Test
public void testUserSignIn() throws Exception {
// create user
Credentials user = signUpUser(this);
// set password for login attempt
System.out.println("User1:" + TestUtils.getTestUser());
user.setPassword(TestUtils.getTestUser().getPassword());
user.encryptPassword(getPublicKey(this));
target("/auth").request().put(TestUtils.toEntity(user), String.class);
}
use of io.divide.shared.transitory.Credentials in project divide by HiddenStage.
the class AuthenticationEndpointTest method testRecoverUserFromToken.
@Test
public void testRecoverUserFromToken() throws Exception {
Credentials user = signUpUser(this);
String token = user.getRecoveryToken();
token = URLEncoder.encode(token, "ISO-8859-1");
int status = target("/auth/recover/").path(token).request().buildGet().invoke().getStatus();
assertEquals(200, status);
}
Aggregations