@Test public void testDefaultConfig() { AuthenticationInfo info = realm.getAuthenticationInfo(new UsernamePasswordToken(USERNAME, PASSWORD, localhost)); assertNotNull(info); assertTrue(realm.hasRole(info.getPrincipals(), ROLE)); Object principal = info.getPrincipals().getPrimaryPrincipal(); assertTrue(principal instanceof UserIdPrincipal); UsernamePrincipal usernamePrincipal = info.getPrincipals().oneByType(UsernamePrincipal.class); assertTrue(usernamePrincipal.getUsername().equals(USERNAME)); UserIdPrincipal userIdPrincipal = info.getPrincipals().oneByType(UserIdPrincipal.class); assertTrue(userIdPrincipal.getUserId() == USER_ID); String stringPrincipal = info.getPrincipals().oneByType(String.class); assertTrue(stringPrincipal.equals(USER_ID + USERNAME)); }
@Test public void testCreateAccountOverride() { AuthorizingRealm realm = new AllowAllRealm() { @Override protected AuthenticationInfo buildAuthenticationInfo(Object principal, Object credentials) { String username = (String) principal; UsernamePrincipal customPrincipal = new UsernamePrincipal(username); return new SimpleAccount(customPrincipal, credentials, getName()); } }; AuthenticationInfo info = realm.getAuthenticationInfo(new UsernamePasswordToken(USERNAME, PASSWORD, localhost)); assertNotNull(info); assertTrue(realm.hasRole(info.getPrincipals(), ROLE)); Object principal = info.getPrincipals().getPrimaryPrincipal(); assertTrue(principal instanceof UsernamePrincipal); assertEquals(USERNAME, ((UsernamePrincipal) principal).getUsername()); }
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { return realm.getAuthenticationInfo(token); }
final AuthenticationInfo authenticationInfo; try { authenticationInfo = realm.getAuthenticationInfo(new UsernamePasswordToken(username, passwd)); } catch (AuthenticationException ae) { if (logger.isDebugEnabled()) {
final AuthenticationInfo authenticationInfo; try { authenticationInfo = realm.getAuthenticationInfo(new UsernamePasswordToken(username, passwd)); } catch (AuthenticationException ae) { if (logger.isDebugEnabled()) {