Search in sources :

Example 1 with SimplePrincipalCollection

use of org.apache.shiro.subject.SimplePrincipalCollection in project neo4j by neo4j.

the class LdapRealmTest method shouldLogFailedAuthorizationQueries.

@Test
public void shouldLogFailedAuthorizationQueries() throws Exception {
    // Given
    when(config.get(SecuritySettings.ldap_use_starttls)).thenReturn(true);
    LdapRealm realm = new TestLdapRealm(config, securityLog, true);
    JndiLdapContextFactory jndiLdapContectFactory = mock(JndiLdapContextFactory.class);
    when(jndiLdapContectFactory.getUrl()).thenReturn("ldap://myserver.org:12345");
    // When
    assertException(() -> realm.doGetAuthorizationInfo(new SimplePrincipalCollection("olivia", "LdapRealm")), AuthProviderFailedException.class, "");
    // Then
    verify(securityLog).error(contains("{LdapRealm}: Failed to get authorization info: " + "'LDAP naming error while attempting to retrieve authorization for user [olivia].'" + " caused by 'Simulated failure'"));
}
Also used : SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) JndiLdapContextFactory(org.apache.shiro.realm.ldap.JndiLdapContextFactory) Test(org.junit.Test)

Example 2 with SimplePrincipalCollection

use of org.apache.shiro.subject.SimplePrincipalCollection in project pmph by BCSquad.

the class PmphUserRealm method clearCachedAuthenticationInfo.

/**
 * <pre>
 * 功能描述:更新身份验证信息缓存
 * 使用示范:
 *
 * @param principals
 * </pre>
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
protected void clearCachedAuthenticationInfo(PrincipalCollection principals) {
    Cache c = getAuthenticationCache();
    logger.info("清除【认证】缓存之前");
    for (Object o : c.keys()) {
        logger.info(o + " , " + c.get(o));
    }
    super.clearCachedAuthenticationInfo(principals);
    logger.info("调用父类清除【认证】缓存之后");
    for (Object o : c.keys()) {
        logger.info(o + " , " + c.get(o));
    }
    // 添加下面的代码清空【认证】的缓存
    PmphUser user = (PmphUser) principals.getPrimaryPrincipal();
    SimplePrincipalCollection spc = new SimplePrincipalCollection(user.getUsername(), getName());
    super.clearCachedAuthenticationInfo(spc);
    logger.info("添加了代码清除【认证】缓存之后");
    int cacheSize = c.keys().size();
    logger.info("【认证】缓存的大小:" + c.keys().size());
    if (cacheSize == 0) {
        logger.info("说明【认证】缓存被清空了。");
    }
}
Also used : PmphUser(com.bc.pmpheep.back.po.PmphUser) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) Cache(org.apache.shiro.cache.Cache)

Example 3 with SimplePrincipalCollection

use of org.apache.shiro.subject.SimplePrincipalCollection in project perry by ca-cwds.

the class AbstractApiSecurityTest method initShiro.

private static void initShiro() {
    Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro.ini");
    setSecurityManager(factory.getInstance());
    Subject subjectUnderTest = new Subject.Builder(getSecurityManager()).authenticated(true).principals(new SimplePrincipalCollection("user", "realm")).buildSubject();
    // 2. Bind the subject to the current thread:
    setSubject(subjectUnderTest);
}
Also used : IniSecurityManagerFactory(org.apache.shiro.config.IniSecurityManagerFactory) SecurityManager(org.apache.shiro.mgt.SecurityManager) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) Subject(org.apache.shiro.subject.Subject)

Example 4 with SimplePrincipalCollection

use of org.apache.shiro.subject.SimplePrincipalCollection in project ART-TIME by Artezio.

the class ActiveDirectoryRealmTest method testDoGetAuthorizationInfo_ifPrincipalsCollectionEmpty.

@Test
public void testDoGetAuthorizationInfo_ifPrincipalsCollectionEmpty() throws NamingException {
    activeDirectoryRealm = createMockBuilder(ActiveDirectoryRealm.class).addMockedMethod("queryForAuthorizationInfo").createMock();
    PrincipalCollection principals = new SimplePrincipalCollection();
    replay(activeDirectoryRealm);
    AuthorizationInfo actual = activeDirectoryRealm.doGetAuthorizationInfo(principals);
    verify(activeDirectoryRealm);
    assertNull(actual);
}
Also used : PrincipalCollection(org.apache.shiro.subject.PrincipalCollection) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) AuthorizationInfo(org.apache.shiro.authz.AuthorizationInfo) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with SimplePrincipalCollection

use of org.apache.shiro.subject.SimplePrincipalCollection 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)

Aggregations

SimplePrincipalCollection (org.apache.shiro.subject.SimplePrincipalCollection)87 Test (org.junit.Test)38 PrincipalCollection (org.apache.shiro.subject.PrincipalCollection)34 SimpleAuthenticationInfo (org.apache.shiro.authc.SimpleAuthenticationInfo)12 Element (org.w3c.dom.Element)12 SecurityAssertion (ddf.security.assertion.SecurityAssertion)11 AuthorizationInfo (org.apache.shiro.authz.AuthorizationInfo)11 DefaultSecurityManager (org.apache.shiro.mgt.DefaultSecurityManager)11 SecurityAssertionSaml (ddf.security.assertion.saml.impl.SecurityAssertionSaml)10 Principal (java.security.Principal)10 SAMLAuthenticationToken (org.codice.ddf.security.handler.SAMLAuthenticationToken)10 ArrayList (java.util.ArrayList)9 Subject (org.apache.shiro.subject.Subject)9 AuthenticationInfo (org.apache.shiro.authc.AuthenticationInfo)8 Subject (ddf.security.Subject)7 AuthenticationException (org.apache.shiro.authc.AuthenticationException)7 Realm (org.apache.shiro.realm.Realm)7 SimpleSession (org.apache.shiro.session.mgt.SimpleSession)7 UsernamePasswordToken (org.apache.shiro.authc.UsernamePasswordToken)6 Assertion (org.opensaml.saml.saml2.core.Assertion)6