@Test public void testStartupSuccess() throws Exception { RunAsImplAuthenticationProvider provider = new RunAsImplAuthenticationProvider(); provider.setKey("hello_world"); assertThat(provider.getKey()).isEqualTo("hello_world"); provider.afterPropertiesSet(); }
@Test public void testAuthenticationSuccess() { RunAsUserToken token = new RunAsUserToken("my_password", "Test", "Password", AuthorityUtils.createAuthorityList("ROLE_ONE", "ROLE_TWO"), UsernamePasswordAuthenticationToken.class); RunAsImplAuthenticationProvider provider = new RunAsImplAuthenticationProvider(); provider.setKey("my_password"); Authentication result = provider.authenticate(token); Assert.assertTrue("Should have returned RunAsUserToken", result instanceof RunAsUserToken); RunAsUserToken resultCast = (RunAsUserToken) result; assertThat(resultCast.getKeyHash()).isEqualTo("my_password".hashCode()); }
@Test(expected = BadCredentialsException.class) public void testAuthenticationFailDueToWrongKey() { RunAsUserToken token = new RunAsUserToken("wrong_key", "Test", "Password", AuthorityUtils.createAuthorityList("ROLE_ONE", "ROLE_TWO"), UsernamePasswordAuthenticationToken.class); RunAsImplAuthenticationProvider provider = new RunAsImplAuthenticationProvider(); provider.setKey("hello_world"); provider.authenticate(token); }
@Bean public AuthenticationProvider runAsAuthenticationProvider() { RunAsImplAuthenticationProvider provider = new RunAsImplAuthenticationProvider(); provider.setKey("Job Execution"); return provider; }
@Bean public RunAsImplAuthenticationProvider runAsAuthenticationProvider() { RunAsImplAuthenticationProvider runAsImplAuthenticationProvider = new RunAsImplAuthenticationProvider(); //TODO not so smart!! runAsImplAuthenticationProvider.setKey("secretRunAsKey"); return runAsImplAuthenticationProvider; } }