LoginModule with it. <Realm className="org.apache.catalina.realm.JAASRealm" appName="ServiceLoginModule" userClassNames="org.apache.openejb.core.security.jaas.UserPrincipal" roleClassNames="org.apache.openejb.core.security.jaas.GroupPrincipal"> </Realm> ServiceLoginModule is in the login.config file ServiceLoginModule { org.apache.openejb.core.security.jaas.ServiceProviderLoginModule required; }; CATALINA_OPTS: -Djava.security.auth.login.config=$CATALINA_BASE/conf/login.config System.setProperty("java.security.auth.login.config", “yourPath/login.config"); LoginModule implementations:ServiceProviderLoginModule and write our own LoginProvider'a implementation: public class SimpleLoginProvider implements LoginProvider { @Override public List<String> authenticate(String user, String password) throws FailedLoginException { if ("admin".equals(user) && "admin".equals(password)) { return Arrays.asList("ADMIN"); } if ("user".equals(user) && "user".equals(password)) { return Arrays.asList("USER"); } throw new FailedLoginException(); } } @RolesAllowed("ADMIN") annotation, for example, and restrict access to a method: @Stateless public class TestBean { @RolesAllowed("ADMIN") public String getProtectedInfo() { return "It's protected information."; } } LoginProvider , you must create the file org.apache.openejb.core.security.jaas.LoginProvider in the project directory / src / main / resources / META-INF / services /, which contains our LoginProvider'a full name LoginProvider'a : org.psa.vaadinauth.secure.SimpleLoginProvider HttpServletRequest'a . After filling out the web-form for authorization, we will call the following method: public void login(String user, String password, HttpServletRequest request) throws ServletException { request.login(user, password); } HttpServletRequest we will send to our login method: login(username, password, (HttpServletRequest) VaadinService.getCurrentRequest()); getNavigator().addView(LoginView.NAME, LoginView.class); getNavigator().addView(MainView.NAME, MainView.class); getNavigator().navigateTo(LoginView.NAME); Source: https://habr.com/ru/post/183550/
All Articles