use of org.apache.shiro.realm.Realm in project geode by apache.
the class IntegratedSecurityService method setSecurityManager.
public void setSecurityManager(SecurityManager securityManager) {
if (securityManager == null) {
return;
}
this.securityManager = securityManager;
Realm realm = new CustomAuthRealm(securityManager);
DefaultSecurityManager shiroManager = new DefaultSecurityManager(realm);
SecurityUtils.setSecurityManager(shiroManager);
increaseShiroGlobalSessionTimeout(shiroManager);
isIntegratedSecurity = true;
isClientAuthenticator = false;
isPeerAuthenticator = false;
}
use of org.apache.shiro.realm.Realm in project ddf by codice.
the class SecurityManagerImplTest method testAuthToken.
/**
* Creates mock objects and uses those to pass through the system when an authentication token
* is used.
*
* @throws SecurityServiceException
*/
@Test
public void testAuthToken() throws SecurityServiceException {
// mock setup
SimplePrincipalCollection principals = new SimplePrincipalCollection();
SecurityToken secToken = new SecurityToken();
principals.add(secToken, REALM_NAME);
AuthenticationToken authToken = mock(AuthenticationToken.class);
when(authToken.getCredentials()).thenReturn("testUser");
AuthenticationInfo info = mock(AuthenticationInfo.class);
when(info.getPrincipals()).thenReturn(principals);
// realm
Realm realm = mock(Realm.class);
when(realm.getAuthenticationInfo(authToken)).thenReturn(info);
when(realm.supports(authToken)).thenReturn(Boolean.TRUE);
when(realm.getName()).thenReturn(REALM_NAME);
SecurityManagerImpl manager = new SecurityManagerImpl();
manager.setRealms(Arrays.asList(new Realm[] { realm }));
Subject subject = manager.getSubject(authToken);
assertNotNull(subject);
}
use of org.apache.shiro.realm.Realm in project ddf by codice.
the class OperationPluginTest method setup.
@Before
public void setup() {
plugin = new OperationPlugin();
AuthorizingRealm realm = mock(AuthorizingRealm.class);
when(realm.getName()).thenReturn("mockRealm");
when(realm.isPermitted(any(PrincipalCollection.class), any(Permission.class))).then(makeDecision());
Collection<Realm> realms = new ArrayList<Realm>();
realms.add(realm);
DefaultSecurityManager manager = new DefaultSecurityManager();
manager.setRealms(realms);
SimplePrincipalCollection principalCollection = new SimplePrincipalCollection(new Principal() {
@Override
public String getName() {
return "testuser";
}
}, realm.getName());
subject = new MockSubject(manager, principalCollection);
}
use of org.apache.shiro.realm.Realm in project ddf by codice.
the class TestResourceUsagePlugin method setSubject.
private void setSubject(String expectedUsername) {
AuthorizingRealm realm = mock(AuthorizingRealm.class);
when(realm.getName()).thenReturn("mockRealm");
when(realm.isPermitted(any(PrincipalCollection.class), any(Permission.class))).thenReturn(true);
Collection<Realm> realms = new ArrayList<>();
realms.add(realm);
DefaultSecurityManager manager = new DefaultSecurityManager();
manager.setRealms(realms);
SimplePrincipalCollection principalCollection = new SimplePrincipalCollection(new Principal() {
@Override
public String getName() {
return expectedUsername;
}
@Override
public String toString() {
return expectedUsername;
}
}, realm.getName());
subject = new MockSubject(manager, principalCollection);
}
use of org.apache.shiro.realm.Realm in project zeppelin by apache.
the class SecurityUtils method getRealmsList.
public static Collection getRealmsList() {
if (!isEnabled) {
return Collections.emptyList();
}
DefaultWebSecurityManager defaultWebSecurityManager;
String key = ThreadContext.SECURITY_MANAGER_KEY;
defaultWebSecurityManager = (DefaultWebSecurityManager) ThreadContext.get(key);
Collection<Realm> realms = defaultWebSecurityManager.getRealms();
return realms;
}
Aggregations