added DAORealmHelperFactory to simplify the creation of dao based realms

This commit is contained in:
Sebastian Sdorra
2017-01-15 12:50:29 +01:00
parent 76384de26f
commit 3536c29908
6 changed files with 102 additions and 28 deletions

View File

@@ -48,10 +48,10 @@ import org.apache.shiro.realm.AuthenticatingRealm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.group.GroupDAO;
import sonia.scm.plugin.Extension;
import sonia.scm.security.DAORealmHelper;
import sonia.scm.user.UserDAO;
import sonia.scm.security.DAORealmHelperFactory;
//~--- JDK imports ------------------------------------------------------------
@@ -92,13 +92,12 @@ public class LegacyRealm extends AuthenticatingRealm
* Constructs ...
*
*
* @param userDAO
* @param groupDAO
* @param helperFactory
*/
@Inject
public LegacyRealm(UserDAO userDAO, GroupDAO groupDAO)
public LegacyRealm(DAORealmHelperFactory helperFactory)
{
this.helper = new DAORealmHelper(REALM, userDAO, groupDAO);
this.helper = helperFactory.create(REALM);
setAuthenticationTokenClass(UsernamePasswordToken.class);
HashedCredentialsMatcher matcher = new HashedCredentialsMatcher();

View File

@@ -54,8 +54,10 @@ import sonia.scm.user.UserDAO;
import sonia.scm.user.UserTestData;
import static org.junit.Assert.*;
import org.junit.Before;
import static org.mockito.Mockito.*;
import sonia.scm.security.DAORealmHelperFactory;
/**
*
@@ -71,6 +73,14 @@ public class LegacyRealmTest
//~--- methods --------------------------------------------------------------
/**
* Prepare object under test.
*/
@Before
public void prepareObjectUnderTest() {
this.realm = new LegacyRealm(helperFactory);
}
/**
* Method description
*
@@ -134,15 +144,15 @@ public class LegacyRealmTest
//~--- fields ---------------------------------------------------------------
/** Field description */
@Mock
private UserDAO userDAO;
@Mock
private GroupDAO groupDAO;
/** Field description */
@InjectMocks
private DAORealmHelperFactory helperFactory;
private LegacyRealm realm;
/** Field description */
@Mock
private UserDAO userDAO;
}