| .. | .. |
|---|
| 1 | 1 | package net.curisit.securis;
|
|---|
| 2 | 2 |
|
|---|
| 3 | 3 | import java.net.URI;
|
|---|
| 4 | +import java.util.Properties;
|
|---|
| 4 | 5 |
|
|---|
| 5 | 6 | import javax.inject.Inject;
|
|---|
| 6 | 7 | import javax.inject.Named;
|
|---|
| .. | .. |
|---|
| 29 | 30 | import com.google.inject.Injector;
|
|---|
| 30 | 31 | import com.google.inject.Key;
|
|---|
| 31 | 32 | import com.google.inject.name.Names;
|
|---|
| 33 | +import com.google.inject.persist.PersistFilter;
|
|---|
| 34 | +import com.google.inject.persist.jpa.JpaPersistModule;
|
|---|
| 32 | 35 |
|
|---|
| 33 | 36 | public class MainApp {
|
|---|
| 34 | 37 |
|
|---|
| .. | .. |
|---|
| 44 | 47 | public static void main(String[] args) throws Exception {
|
|---|
| 45 | 48 | log.info("SeCuris init...");
|
|---|
| 46 | 49 |
|
|---|
| 47 | | - injector = Guice.createInjector(new SecurisModule(), new RequestsModule());
|
|---|
| 48 | | - // createBiDirectionalGuiceBridge(ServiceLocatorFactory.getInstance().create("default"), new SecurisModule());
|
|---|
| 50 | + SecurisModule securisModule = new SecurisModule();
|
|---|
| 51 | + JpaPersistModule jpaPersistModule = new JpaPersistModule("localdb");
|
|---|
| 52 | + Properties props = new Properties();
|
|---|
| 53 | + props.put("javax.persistence.jdbc.password", securisModule.getPassword());
|
|---|
| 54 | + props.put("javax.persistence.jdbc.url", securisModule.getUrl(securisModule.getAppDir()));
|
|---|
| 55 | + log.info("BD Url: {} {}", securisModule.getUrl(securisModule.getAppDir()), securisModule.getPassword());
|
|---|
| 56 | + jpaPersistModule.properties(props);
|
|---|
| 57 | +
|
|---|
| 58 | + injector = Guice.createInjector(securisModule, new RequestsModule(), jpaPersistModule);
|
|---|
| 59 | + // injector.getInstance(JpaInitializer.class);
|
|---|
| 60 | +
|
|---|
| 49 | 61 | startServer(injector.getInstance(Key.get(URI.class, Names.named("base-uri"))));
|
|---|
| 50 | 62 | while (true) {
|
|---|
| 51 | 63 | Thread.currentThread().sleep(100);
|
|---|
| .. | .. |
|---|
| 63 | 75 | context.setInitParameter("resteasy.role.based.security", "true");
|
|---|
| 64 | 76 | context.setInitParameter("resteasy.providers", DefaultExceptionHandler.class.getName());
|
|---|
| 65 | 77 | context.addFilter(new FilterHolder(injector.getInstance(AuthFilter.class)), "/*", null);
|
|---|
| 66 | | -
|
|---|
| 78 | + context.addFilter(new FilterHolder(injector.getInstance(PersistFilter.class)), "/*", null);
|
|---|
| 67 | 79 | ServletHolder sh = new ServletHolder(HttpServletDispatcher.class);
|
|---|
| 68 | 80 | sh.setName("resteasy");
|
|---|
| 69 | 81 | context.addServlet(sh, "/*");
|
|---|
| .. | .. |
|---|
| 97 | 109 |
|
|---|
| 98 | 110 | }
|
|---|
| 99 | 111 |
|
|---|
| 100 | | - /**
|
|---|
| 101 | | - * User: Nuwan.N.Bandara
|
|---|
| 102 | | - */
|
|---|
| 103 | 112 | @Provider
|
|---|
| 104 | 113 | public static class DefaultExceptionHandler implements ExceptionMapper<Exception> {
|
|---|
| 105 | 114 |
|
|---|
| .. | .. |
|---|
| 122 | 131 | }
|
|---|
| 123 | 132 |
|
|---|
| 124 | 133 | }
|
|---|
| 125 | | -
|
|---|
| 126 | | -/*
|
|---|
| 127 | | - * Constraint constraint = new Constraint(); constraint.setName(Constraint.__FORM_AUTH);; constraint.setRoles(new String[]{"user","admin","moderator"}); constraint.setAuthenticate(true);
|
|---|
| 128 | | - *
|
|---|
| 129 | | - * ConstraintMapping constraintMapping = new ConstraintMapping(); constraintMapping.setConstraint(constraint); constraintMapping.setPathSpec("/*");
|
|---|
| 130 | | - *
|
|---|
| 131 | | - * ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler(); securityHandler.addConstraintMapping(constraintMapping); HashLoginService loginService = new HashLoginService(); loginService.putUser("username", new
|
|---|
| 132 | | - * Password("password"), new String[] {"user"}); securityHandler.setLoginService(loginService);
|
|---|
| 133 | | - *
|
|---|
| 134 | | - * FormAuthenticator authenticator = new FormAuthenticator("/login", "/login", false); securityHandler.setAuthenticator(authenticator);
|
|---|
| 135 | | - *
|
|---|
| 136 | | - * context.setSecurityHandler(securityHandler);
|
|---|
| 137 | | - */ |
|---|