@Test public void shouldLoginUsingSharedState() throws Exception { AuthenticationToken s = new DefaultAuthenticationToken("Basic", "Basic " + new String(Base64.encodeBase64(String.format("%s:%s", GOOD_USERNAME, GOOD_PASSWORD).getBytes()))); context.checking(new Expectations() { { oneOf(configuration).getAppConfigurationEntry(REALM_NAME); final String basicLoginModuleName = "org.kaazing.gateway.security.auth.BasicLoginModule"; final HashMap<String, Object> basicOptions = new HashMap<>(); final AppConfigurationEntry basicEntry = new AppConfigurationEntry(basicLoginModuleName, OPTIONAL, basicOptions); final String fileLoginModuleName = "org.kaazing.gateway.security.auth.FileLoginModule"; final HashMap<String, Object> fileOptions = new HashMap<>(); fileOptions.put("file", "src/test/resources/jaas-config.xml"); fileOptions.put("tryFirstPass", "true"); final AppConfigurationEntry fileEntry = new AppConfigurationEntry(fileLoginModuleName, REQUIRED, fileOptions); will(returnValue(new AppConfigurationEntry[]{basicEntry, fileEntry})); } }); Subject subject = new Subject(); DispatchCallbackHandler handler = new DispatchCallbackHandler(); DefaultLoginResult loginResult = new DefaultLoginResult(); handler.register(AuthenticationTokenCallback.class, new AuthenticationTokenCallbackHandler(s)); handler.register(LoginResultCallback.class, new LoginResultCallbackHandler(loginResult)); LoginContext loginContext = new ResultAwareLoginContext("demo", subject, handler, configuration, loginResult); context.assertIsSatisfied(); assertNotNull(loginContext); try { loginContext.login(); } catch (LoginException e) { fail("Login failed to succeed as expected: " + e.getMessage()); } }
@Override public boolean login() throws LoginException { switch (state) { case INITIALIZE_COMPLETE: return login0(); case LOGIN_COMPLETE: return login0(); case COMMIT_COMPLETE: return true; case INITIALIZE_REQUIRED: default: throw new LoginException("Login module is not initialized"); } }
FileLoginModule implements LoginModule { @Override public boolean login() throws LoginException { switch (state) { case INITIALIZE_COMPLETE: return login0(); case LOGIN_COMPLETE: return login0(); case COMMIT_COMPLETE: return true; case INITIALIZE_REQUIRED: default: throw new LoginException("Login module is not initialized"); } } }
FileLoginModule implements LoginModule { @Override public boolean login() throws LoginException { switch (state) { case INITIALIZE_COMPLETE: return login0(); case LOGIN_COMPLETE: return login0(); case COMMIT_COMPLETE: return true; case INITIALIZE_REQUIRED: default: throw new LoginException("Login module is not initialized"); } } FileLoginModule(); }
FileLoginModule implements LoginModule { @Override public boolean login() throws LoginException { switch (state) { case INITIALIZE_COMPLETE: return login0(); case LOGIN_COMPLETE: return login0(); case COMMIT_COMPLETE: return true; case INITIALIZE_REQUIRED: default: throw new LoginException("Login module is not initialized"); } } FileLoginModule(); @Override void initialize(Subject subject, CallbackHandler callback,
                           Map<String, ?> sharedState, Map<String, ?> options); @Override boolean login(); @Override boolean logout(); @Override boolean commit(); @Override boolean abort(); }
FileLoginModule implements LoginModule { @Override public boolean login() throws LoginException { switch (state) { case INITIALIZE_COMPLETE: return login0(); case LOGIN_COMPLETE: return login0(); case COMMIT_COMPLETE: return true; case INITIALIZE_REQUIRED: default: throw new LoginException("Login module is not initialized"); } } FileLoginModule(); @Override void initialize(Subject subject, CallbackHandler callback,
                           Map<String, ?> sharedState, Map<String, ?> options); @Override boolean login(); @Override boolean logout(); @Override boolean commit(); @Override boolean abort(); static final String CLASS_NAME; static final Logger LOG; }