master
Edward M. Kagan 6 years ago
parent bd2623d913
commit a0fadd0534

@ -18,7 +18,7 @@ public class LoginResource {
@Inject
SessionInfo session;
@Inject
SessionCacheImpl sessionCache;
@ -26,8 +26,7 @@ public class LoginResource {
@Path("/login")
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed({"anonymous"})
public Response login (@FormParam("login") String login, @FormParam("pass") String pass) {
// System.out.println(login + " : " + pass);
public Response login(@FormParam("login") String login, @FormParam("pass") String pass) {
if (login.equals("demo") && pass.equals("demo")) {
SessionInfo si = new SessionInfo().role("admin");//.name("demo");
return sessionCache.loginSuccessResponse(si);
@ -36,4 +35,4 @@ public class LoginResource {
}
}
}
}

@ -1,6 +1,5 @@
package org.pagan.janitor;
import javax.annotation.security.PermitAll;
import javax.annotation.security.RolesAllowed;
import javax.enterprise.context.RequestScoped;
@ -11,113 +10,25 @@ import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.pagan.janitor.cache.SessionInfo;
//import org.eclipse.microprofile.jwt.JsonWebToken;
/**
* Version 2 of the TokenSecuredResource
*/
@Path("/test")
@RequestScoped
public class TokenSecuredResource {
// @Inject
// CayenneSupport cayenne;
//
// @Inject
// JedisSupport jedis;
@Inject
SessionInfo session;
@GET
@Produces(MediaType.TEXT_PLAIN)
@PermitAll
public String get () {
// System.out.println(session.role());
public String get() {
return "permit-all";
}
@GET
@Path("/admin")
@Produces(MediaType.TEXT_PLAIN)
@RolesAllowed({"devel", "admin", "user"})
public String init() {
long start = System.currentTimeMillis();
// StringBuilder sb = new StringBuilder();
//
// for (int i = 0; i < 20; i++) {
// try (Jedis jedisContext = jedis.context()) {
//
// HashMap<String, String> info = new HashMap<String, String>() {
// {
// put("created_at", "100100");
// put("expires_at", "200200");
// put("role", "admin");
// put("last_action_at", String.valueOf(System.currentTimeMillis()));
// }
// };
// jedisContext.hset("<session_" + i + ">", info);
// }
// }
//
// ObjectContext cayenneContext = cayenne.context();
// long count = ObjectSelect.query(SecUser.class).selectCount(cayenneContext);
//// System.out.println("count = " + count);
// System.out.println(System.currentTimeMillis());
// ObjectSelect.query(SecUser.class).iterate(cayenneContext, (SecUser a) -> {
////// System.out.println(a.getFirstName() + " " + a.getLastName());
// });
//// try (ResultBatchIterator<SecUser> batchIterator = ObjectSelect.query(SecUser.class).batchIterator(cayenneContext, 100)) {
//// for (List<SecUser> list : batchIterator) {
//// for (SecUser a : list) {
////// sb.append(a.getFirstName().substring(0,1) + "");
//// for (int i = 0; i < 20; i++) {
////// sb.append(a.getLastName() + " " + a.getFirstName() + " " + a.getMiddleName() + " (" + a.getContactEmail() + ") ");
//// }
////
////// System.out.println(a.getFirstName() + " " + a.getLastName() + " ");
//// }
//// }
//// }
//// while (batchIterator.hasNext()) {
//// List<SecUser> next = batchIterator.next();
//// for (SecUser user : next) {
////// System.out.println("user = " + user.getFirstName() + ":" + user.getLastName());
//// }
//// }
//
//// throw new UnsupportedOperationException("asd");
//// ObjectContext newContext = serverRuntime.newContext();
return String.valueOf(System.currentTimeMillis() - start);
return session.sessionId() + " : " + session.expiresAt();
}
// @Inject
// JsonWebToken jwt;
// @GET()
// @Path("permit-all")
// @PermitAll
// @Produces(MediaType.TEXT_PLAIN)
// public String hello(@Context SecurityContext ctx) {
// Principal caller = ctx.getUserPrincipal();
// String name = caller == null ? "anonymous" : caller.getName();
// String helloReply = String.format("hello + %s, isSecure: %s, authScheme: %s", name, ctx.isSecure(), ctx.getAuthenticationScheme());
// return helloReply;
// }
//
// @GET()
// @Path("roles-allowed")
// @RolesAllowed({"Echoer", "Subscriber"})
// @Produces(MediaType.TEXT_PLAIN)
// public String helloRolesAllowed(@Context SecurityContext ctx) {
// Principal caller = ctx.getUserPrincipal();
// String name = caller == null ? "anonymous" : caller.getName();
//// boolean hasJWT = jwt.getClaimNames() != null;
//// String helloReply = String.format("hello + %s, isSecure: %s, authScheme: %s, hasJWT: %s", name, ctx.isSecure(), ctx.getAuthenticationScheme(), hasJWT);
//// return helloReply;
// return "2"
// }
}
}

Loading…
Cancel
Save