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'"));
}
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("说明【认证】缓存被清空了。");
}
}
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);
}
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);
}
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);
}
Aggregations