@Test public void nullAuthInfoWhenUserNotActive() throws Exception { when(principalsHelper.getUserStatus(principalCollection)).thenReturn(UserStatus.disabled); assertThat(underTest.doGetAuthenticationInfo(token), is(nullValue())); }
@Override protected AuthenticationInfo doGetAuthenticationInfo(final AuthenticationToken token) { checkNotNull(token); final PrincipalCollection principals = keyStore.getPrincipals(format, (char[]) token.getCredentials()); if (null != principals) { try { if (anonymousAndSupported(principals) || principalsHelper.getUserStatus(principals).isActive()) { ((NexusApiKeyAuthenticationToken) token).setPrincipal(principals.getPrimaryPrincipal()); if (requestProvider != null) { requestProvider.get().setAttribute(IS_TOKEN_AUTH_KEY, Boolean.TRUE); } return new SimpleAuthenticationInfo(principals, token.getCredentials()); } } catch (final UserNotFoundException e) { log.debug("Realm did not find user", e); keyStore.deleteApiKeys(principals); } } return null; }
BearerTokenRealm extends AuthenticatingRealm { @Override protected AuthenticationInfo doGetAuthenticationInfo(final AuthenticationToken token) { checkNotNull(token); final PrincipalCollection principals = keyStore.getPrincipals(format, (char[]) token.getCredentials()); if (null != principals) { try { if (anonymousAndSupported(principals) || principalsHelper.getUserStatus(principals).isActive()) { ((NexusApiKeyAuthenticationToken) token).setPrincipal(principals.getPrimaryPrincipal()); if (requestProvider != null) { requestProvider.get().setAttribute(IS_TOKEN_AUTH_KEY, Boolean.TRUE); } return new SimpleAuthenticationInfo(principals, token.getCredentials()); } } catch (final UserNotFoundException e) { log.debug("Realm did not find user", e); keyStore.deleteApiKeys(principals); } } return null; } }
BearerTokenRealm extends AuthenticatingRealm { @Override protected AuthenticationInfo doGetAuthenticationInfo(final AuthenticationToken token) { checkNotNull(token); final PrincipalCollection principals = keyStore.getPrincipals(format, (char[]) token.getCredentials()); if (null != principals) { try { if (anonymousAndSupported(principals) || principalsHelper.getUserStatus(principals).isActive()) { ((NexusApiKeyAuthenticationToken) token).setPrincipal(principals.getPrimaryPrincipal()); if (requestProvider != null) { requestProvider.get().setAttribute(IS_TOKEN_AUTH_KEY, Boolean.TRUE); } return new SimpleAuthenticationInfo(principals, token.getCredentials()); } } catch (final UserNotFoundException e) { log.debug("Realm did not find user", e); keyStore.deleteApiKeys(principals); } } return null; } BearerTokenRealm(final ApiKeyStore keyStore,
                          final UserPrincipalsHelper principalsHelper,
                          final String format); }
BearerTokenRealm extends AuthenticatingRealm { @Override protected AuthenticationInfo doGetAuthenticationInfo(final AuthenticationToken token) { checkNotNull(token); final PrincipalCollection principals = keyStore.getPrincipals(format, (char[]) token.getCredentials()); if (null != principals) { try { if (anonymousAndSupported(principals) || principalsHelper.getUserStatus(principals).isActive()) { ((NexusApiKeyAuthenticationToken) token).setPrincipal(principals.getPrimaryPrincipal()); if (requestProvider != null) { requestProvider.get().setAttribute(IS_TOKEN_AUTH_KEY, Boolean.TRUE); } return new SimpleAuthenticationInfo(principals, token.getCredentials()); } } catch (final UserNotFoundException e) { log.debug("Realm did not find user", e); keyStore.deleteApiKeys(principals); } } return null; } BearerTokenRealm(final ApiKeyStore keyStore,
                          final UserPrincipalsHelper principalsHelper,
                          final String format); @Override boolean supports(final AuthenticationToken token); }
BearerTokenRealm extends AuthenticatingRealm { @Override protected AuthenticationInfo doGetAuthenticationInfo(final AuthenticationToken token) { checkNotNull(token); final PrincipalCollection principals = keyStore.getPrincipals(format, (char[]) token.getCredentials()); if (null != principals) { try { if (anonymousAndSupported(principals) || principalsHelper.getUserStatus(principals).isActive()) { ((NexusApiKeyAuthenticationToken) token).setPrincipal(principals.getPrimaryPrincipal()); if (requestProvider != null) { requestProvider.get().setAttribute(IS_TOKEN_AUTH_KEY, Boolean.TRUE); } return new SimpleAuthenticationInfo(principals, token.getCredentials()); } } catch (final UserNotFoundException e) { log.debug("Realm did not find user", e); keyStore.deleteApiKeys(principals); } } return null; } BearerTokenRealm(final ApiKeyStore keyStore,
                          final UserPrincipalsHelper principalsHelper,
                          final String format); @Override boolean supports(final AuthenticationToken token); static final String IS_TOKEN_AUTH_KEY; }