|
|
|
|
@ -1,6 +1,5 @@
|
|
|
|
|
package org.pagan.janitor;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.security.PermitAll;
|
|
|
|
|
import javax.annotation.security.RolesAllowed;
|
|
|
|
|
import javax.enterprise.context.RequestScoped;
|
|
|
|
|
@ -11,22 +10,10 @@ 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;
|
|
|
|
|
|
|
|
|
|
@ -34,90 +21,14 @@ public class TokenSecuredResource {
|
|
|
|
|
@Produces(MediaType.TEXT_PLAIN)
|
|
|
|
|
@PermitAll
|
|
|
|
|
public String get() {
|
|
|
|
|
// System.out.println(session.role());
|
|
|
|
|
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"
|
|
|
|
|
// }
|
|
|
|
|
}
|