Search in sources :

Example 1 with Settings

use of com.artezio.arttime.config.Settings in project ART-TIME by Artezio.

the class AdminRealm method doGetAuthenticationInfo.

@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    String username = ((UsernamePasswordToken) token).getUsername();
    Settings settings = getSettings();
    return getAccount(username, settings);
}
Also used : Settings(com.artezio.arttime.config.Settings)

Example 2 with Settings

use of com.artezio.arttime.config.Settings in project ART-TIME by Artezio.

the class IniWebEnvironment method addLdapProperties.

protected void addLdapProperties(Ini ini) {
    Settings settings = getSettingsService().getSettings();
    if (settings != null) {
        String ldapUrl = String.format("ldap://%s:%s", settings.getLdapServerHost(), settings.getLdapServerPort());
        ini.setSectionProperty(IniSecurityManagerFactory.MAIN_SECTION_NAME, ActiveDirectoryRealm.REALM_NAME, "com.artezio.arttime.security.auth.ActiveDirectoryRealm");
        ini.setSectionProperty(IniSecurityManagerFactory.MAIN_SECTION_NAME, ActiveDirectoryRealm.REALM_NAME + ".url", ldapUrl);
        ini.setSectionProperty(IniSecurityManagerFactory.MAIN_SECTION_NAME, ActiveDirectoryRealm.REALM_NAME + ".systemUsername", settings.getLdapPrincipalUsername());
        ini.setSectionProperty(IniSecurityManagerFactory.MAIN_SECTION_NAME, ActiveDirectoryRealm.REALM_NAME + ".systemPassword", settings.getLdapBindCredentials());
        ini.setSectionProperty(IniSecurityManagerFactory.MAIN_SECTION_NAME, ActiveDirectoryRealm.REALM_NAME + ".searchBase", settings.getLdapUserContextDN());
        ini.setSectionProperty(IniSecurityManagerFactory.MAIN_SECTION_NAME, ActiveDirectoryRealm.REALM_NAME + ".principalSuffix", settings.getLdapPrincipalSuffix());
        ini.setSectionProperty(IniSecurityManagerFactory.MAIN_SECTION_NAME, ActiveDirectoryRealm.REALM_NAME + ".groupRolesMap", getGroupRolesMapProperty(settings));
    }
}
Also used : Settings(com.artezio.arttime.config.Settings)

Example 3 with Settings

use of com.artezio.arttime.config.Settings in project ART-TIME by Artezio.

the class AdminRealmTest method testdoGetAuthenticationInfo.

@Test
public void testdoGetAuthenticationInfo() {
    Settings settings = new Settings(new EnumMap<>(Setting.Name.class));
    settings.setAdminUsername("admin");
    AuthenticationToken token = new UsernamePasswordToken("admin", new char[] {});
    PowerMock.mockStatic(CDIUtils.class);
    expect(CDIUtils.getBean(SettingsService.class)).andReturn(settingsService);
    expect(settingsService.getSettings()).andReturn(settings);
    PowerMock.replayAll(CDIUtils.class, settingsService);
    AuthenticationInfo actual = adminRealm.doGetAuthenticationInfo(token);
    PowerMock.verifyAll();
    assertNotNull(actual);
    assertTrue(actual instanceof SimpleAccount);
}
Also used : SimpleAccount(org.apache.shiro.authc.SimpleAccount) AuthenticationToken(org.apache.shiro.authc.AuthenticationToken) Settings(com.artezio.arttime.config.Settings) AuthenticationInfo(org.apache.shiro.authc.AuthenticationInfo) UsernamePasswordToken(org.apache.shiro.authc.UsernamePasswordToken) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with Settings

use of com.artezio.arttime.config.Settings in project ART-TIME by Artezio.

the class AdminRealmTest method testDoGetAuthorizationInfo.

@Test
public void testDoGetAuthorizationInfo() {
    Settings settings = new Settings(new EnumMap<>(Setting.Name.class));
    settings.setAdminUsername("admin");
    PrincipalCollection principalCollection = new SimplePrincipalCollection("admin", "realm");
    PowerMock.mockStatic(CDIUtils.class);
    expect(CDIUtils.getBean(SettingsService.class)).andReturn(settingsService);
    expect(settingsService.getSettings()).andReturn(settings);
    PowerMock.replayAll(CDIUtils.class, settingsService);
    AuthorizationInfo actual = adminRealm.doGetAuthorizationInfo(principalCollection);
    PowerMock.verifyAll();
    assertNotNull(actual);
    assertTrue(actual instanceof SimpleAccount);
}
Also used : SimpleAccount(org.apache.shiro.authc.SimpleAccount) PrincipalCollection(org.apache.shiro.subject.PrincipalCollection) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) AuthorizationInfo(org.apache.shiro.authz.AuthorizationInfo) Settings(com.artezio.arttime.config.Settings) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with Settings

use of com.artezio.arttime.config.Settings in project ART-TIME by Artezio.

the class AdminRealmTest method testGetAccount_ifLoggedUserIsAdmin.

@Test
public void testGetAccount_ifLoggedUserIsAdmin() {
    Settings settings = new Settings(new EnumMap<>(Setting.Name.class));
    settings.setAdminUsername("admin");
    SimpleAccount actual = adminRealm.getAccount("admin", settings);
    assertNotNull(actual);
}
Also used : SimpleAccount(org.apache.shiro.authc.SimpleAccount) Settings(com.artezio.arttime.config.Settings) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Settings (com.artezio.arttime.config.Settings)40 Test (org.junit.Test)31 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)21 Setting (com.artezio.arttime.config.Setting)9 EnumMap (java.util.EnumMap)5 Before (org.junit.Before)5 SimpleAccount (org.apache.shiro.authc.SimpleAccount)4 Instance (javax.enterprise.inject.Instance)3 Properties (java.util.Properties)2 URLName (javax.mail.URLName)2 ApplicationSettings (com.artezio.arttime.config.ApplicationSettings)1 Employee (com.artezio.arttime.datamodel.Employee)1 ProjectService (com.artezio.arttime.services.ProjectService)1 SettingsService (com.artezio.arttime.services.SettingsService)1 UserInfo (com.artezio.arttime.services.integration.spi.UserInfo)1 Duration (java.time.Duration)1 java.util (java.util)1 HashMap (java.util.HashMap)1 Timer (javax.ejb.Timer)1 TimerConfig (javax.ejb.TimerConfig)1