UserAuthentication implements Authentication, UserConstants { @Nullable @Override public String getUserId() { if (userId == null) { throw new IllegalStateException("UserId can only be retrieved after successful authentication."); } return userId; } UserAuthentication(@NotNull UserConfiguration config, @NotNull Root root, @Nullable String loginId); @Override boolean authenticate(@Nullable Credentials credentials); @Nullable @Override String getUserId(); @Nullable @Override Principal getUserPrincipal(); static final String PARAM_PASSWORD_EXPIRY_FOR_ADMIN; }
@Test(expected = IllegalStateException.class) public void testGetUserIdBeforeLogin() { authentication.getUserId(); }
@Test public void testGetUserId() throws LoginException { authentication.authenticate(new SimpleCredentials(userId, userId.toCharArray())); assertEquals(userId, authentication.getUserId()); }