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

@ -27,7 +27,6 @@ public class LoginResource {
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@RolesAllowed({"anonymous"}) @RolesAllowed({"anonymous"})
public Response login(@FormParam("login") String login, @FormParam("pass") String pass) { public Response login(@FormParam("login") String login, @FormParam("pass") String pass) {
// System.out.println(login + " : " + pass);
if (login.equals("demo") && pass.equals("demo")) { if (login.equals("demo") && pass.equals("demo")) {
SessionInfo si = new SessionInfo().role("admin");//.name("demo"); SessionInfo si = new SessionInfo().role("admin");//.name("demo");
return sessionCache.loginSuccessResponse(si); return sessionCache.loginSuccessResponse(si);

@ -1,6 +1,5 @@
package org.pagan.janitor; package org.pagan.janitor;
import javax.annotation.security.PermitAll; import javax.annotation.security.PermitAll;
import javax.annotation.security.RolesAllowed; import javax.annotation.security.RolesAllowed;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.RequestScoped;
@ -11,22 +10,10 @@ import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import org.pagan.janitor.cache.SessionInfo; import org.pagan.janitor.cache.SessionInfo;
//import org.eclipse.microprofile.jwt.JsonWebToken;
/**
* Version 2 of the TokenSecuredResource
*/
@Path("/test") @Path("/test")
@RequestScoped @RequestScoped
public class TokenSecuredResource { public class TokenSecuredResource {
// @Inject
// CayenneSupport cayenne;
//
// @Inject
// JedisSupport jedis;
@Inject @Inject
SessionInfo session; SessionInfo session;
@ -34,90 +21,14 @@ public class TokenSecuredResource {
@Produces(MediaType.TEXT_PLAIN) @Produces(MediaType.TEXT_PLAIN)
@PermitAll @PermitAll
public String get() { public String get() {
// System.out.println(session.role());
return "permit-all"; return "permit-all";
} }
@GET @GET
@Path("/admin") @Path("/admin")
@Produces(MediaType.TEXT_PLAIN) @Produces(MediaType.TEXT_PLAIN)
@RolesAllowed({"devel", "admin", "user"}) @RolesAllowed({"devel", "admin", "user"})
public String init() { public String init() {
long start = System.currentTimeMillis(); return session.sessionId() + " : " + session.expiresAt();
// 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);
} }
// @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