当前位置: 首页>>代码示例>>Java>>正文


Java SimpleAccountRealm类代码示例

本文整理汇总了Java中org.apache.shiro.realm.SimpleAccountRealm的典型用法代码示例。如果您正苦于以下问题:Java SimpleAccountRealm类的具体用法?Java SimpleAccountRealm怎么用?Java SimpleAccountRealm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SimpleAccountRealm类属于org.apache.shiro.realm包,在下文中一共展示了SimpleAccountRealm类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: start

import org.apache.shiro.realm.SimpleAccountRealm; //导入依赖的package包/类
@BeforeClass
public static void start() throws Exception {
    securityManager = new DefaultSecurityManager();
    SecurityUtils.setSecurityManager(securityManager);


    realm = new SimpleAccountRealm("test-realm");
    realm.addRole("role");
    realm.addAccount("foo", "bar", "role");
    realm.addAccount("bilbo", "precious", "hobbit");
    realm.setRolePermissionResolver(new RolePermissionResolver() {
        public Collection<Permission> resolvePermissionsInRole(String roleString) {
            if ("role".equals(roleString)) {
                final Permission dp = new WildcardPermission("permission");
                return Arrays.asList(dp);
            }
            return Collections.emptyList();
        }
    });
    securityManager.setRealm(realm);
}
 
开发者ID:ops4j,项目名称:org.ops4j.pax.shiro,代码行数:22,代码来源:AbstractCdiTest.java

示例2: synchronizeRealms

import org.apache.shiro.realm.SimpleAccountRealm; //导入依赖的package包/类
/**
 * Synchronizes the realm's map with the security manager.
 */
protected final void synchronizeRealms() {
    RealmSecurityManager securityManager = (RealmSecurityManager)
            getSecurityManager();

    if (securityManager != null) {
        if (!realms.isEmpty()) {
            securityManager.setRealms(realms.values());
        } else {
            // bind simple realm because it should be at least one realm
            securityManager.setRealm(new SimpleAccountRealm());
        }
    } else {
        log.warn("Realm security manager is not available. Realms is not updated");
    }
}
 
开发者ID:panifex,项目名称:panifex-platform,代码行数:19,代码来源:ModularWebEnvironment.java

示例3: testUnbindRegisteredAuthenticationService

import org.apache.shiro.realm.SimpleAccountRealm; //导入依赖的package包/类
@Test
public void testUnbindRegisteredAuthenticationService() throws Exception {
    String authcServiceName = "serviceName";

    AuthenticationService authcServiceMock = createMock(AuthenticationService.class);
    expect(authcServiceMock.getName()).andReturn(authcServiceName);

    // realm map already contains authentication service
    Map<String, Realm> realmMap = Whitebox.getInternalState(environment, "realms");
    realmMap.put(authcServiceName, authcServiceMock);

    // expect binding SimpleAccountRealm to security manager
    SimpleAccountRealm simpleAccountRealmMock = createMockAndExpectNew(SimpleAccountRealm.class);
    securityManagerMock.setRealm(simpleAccountRealmMock);

    unbindAuthenticationServiceAndVerify(authcServiceMock);
}
 
开发者ID:panifex,项目名称:panifex-platform,代码行数:18,代码来源:ModularWebEnvironmentTest.java

示例4: testUnbindRegisteredAuthorizationService

import org.apache.shiro.realm.SimpleAccountRealm; //导入依赖的package包/类
@Test
public void testUnbindRegisteredAuthorizationService() throws Exception {
    String authcServiceName = "serviceName";

    AuthorizationService authzServiceMock = createMock(AuthorizationService.class);
    expect(authzServiceMock.getName()).andReturn(authcServiceName);

    AuthzAwareRealm authzAwareRealmMock = createMock(AuthzAwareRealm.class);
    expect(authzAwareRealmMock.getAuthorizationService()).andReturn(authzServiceMock);

    // realm map already contains authentication service
    Map<String, Realm> realmMap = Whitebox.getInternalState(environment, "realms");
    realmMap.put(authcServiceName, authzAwareRealmMock);

    // expect binding SimpleAccountRealm to security manager
    SimpleAccountRealm simpleAccountRealmMock = createMockAndExpectNew(SimpleAccountRealm.class);
    securityManagerMock.setRealm(simpleAccountRealmMock);

    unbindAuthorizationServiceAndVerify(authzServiceMock);
}
 
开发者ID:panifex,项目名称:panifex-platform,代码行数:21,代码来源:ModularWebEnvironmentTest.java

示例5: testUnauthorizedUserGetsPermissionDenied

import org.apache.shiro.realm.SimpleAccountRealm; //导入依赖的package包/类
/**
 * Set security manager such that every data request is turned down.
 */
@Test
public void testUnauthorizedUserGetsPermissionDenied() {
  // By default this will deny any authorization request
  ThreadContext.bind(new DefaultSecurityManager(new SimpleAccountRealm()));

  LDListener client = mock(LDListener.class);

  String[] tickers = {"T1", "T2", "T3"};
  _manager.subscribe(client, createIdBundles(tickers));

  Set<LiveDataSubscriptionResponse> responses = new HashSet<>();
  responses.add(buildSuccessResponse("T1"));
  responses.add(buildSuccessResponse("T2"));
  responses.add(buildSuccessResponse("T3"));

  _manager.subscriptionResultsReceived(responses);

  // Now send the value updates for all
  MutableFudgeMsg msg = buildPermissionedMsg("somePerm");
  _manager.valueUpdate(new LiveDataValueUpdateBean(1, createLiveDataSpec("T1"), msg));
  _manager.valueUpdate(new LiveDataValueUpdateBean(2, createLiveDataSpec("T2"), msg));
  _manager.valueUpdate(new LiveDataValueUpdateBean(3, createLiveDataSpec("T3"), msg));

  LiveDataResults snapshot = _manager.snapshot(client);

  assertThat(snapshot.size(), is(3));

  // Data is available but not sent so still pending
  checkSnapshotEntry(snapshot, "T1", PERMISSION_DENIED);
  checkSnapshotEntry(snapshot, "T2", PERMISSION_DENIED);
  checkSnapshotEntry(snapshot, "T3", PERMISSION_DENIED);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:36,代码来源:DefaultLiveDataManagerTest.java

示例6: createSimpleRealm

import org.apache.shiro.realm.SimpleAccountRealm; //导入依赖的package包/类
private SimpleAccountRealm createSimpleRealm() {
    SimpleAccountRealm realm = new SimpleAccountRealm();
    
    realm.addRole("admin");
    realm.addAccount("henning", "henning", "admin");
    
    return realm;
}
 
开发者ID:MTDdk,项目名称:jawn,代码行数:9,代码来源:JawnSecurityManagerFactory.java

示例7: testSynchronizeEmptyRealmCollection

import org.apache.shiro.realm.SimpleAccountRealm; //导入依赖的package包/类
/**
 * Synchronizes the empty collection of realms to the security manager.
 * <p>
 * The {@link SimpleAccountRealm} should be binded to the security manager because
 * at least one realm can be binded.
 */
@Test
public void testSynchronizeEmptyRealmCollection() throws Exception {
    // expect binding SimpleAccountRealm to security manager
    SimpleAccountRealm simpleAccountRealmMock = createMockAndExpectNew(SimpleAccountRealm.class);
    securityManagerMock.setRealm(simpleAccountRealmMock);

    replayAll();
    environment.synchronizeRealms();
    verifyAll();

    assertTrue(environment.getRealms().isEmpty());
}
 
开发者ID:panifex,项目名称:panifex-platform,代码行数:19,代码来源:ModularWebEnvironmentTest.java

示例8: login

import org.apache.shiro.realm.SimpleAccountRealm; //导入依赖的package包/类
@Test(enabled = false)
    public void login() {
        String username = "abc";
        //init SecurityManager
        SimpleAccountRealm realm = new SimpleAccountRealm("simple-realm");
        realm.addAccount(username, "abc", "USER");

        SimpleAccountRealm realm2 = new SimpleAccountRealm("simple-realm2");
        realm2.addAccount(username, "abc", "USER", "ADMIN");

        List<Realm> realmList = new ArrayList<>();
        realmList.add(realm);
        realmList.add(realm2);

        SecurityManager securityManager = new DefaultSecurityManager(realmList);
        SecurityUtils.setSecurityManager(securityManager);

        UsernamePasswordToken token = new UsernamePasswordToken(username, "abcdd");

        final Subject subject = SecurityUtils.getSubject();
        subject.login(token);


        final Subject subject1 = SecurityUtils.getSubject();
        assertTrue(subject1.isAuthenticated());

        assertFalse(subject1.isPermitted("OK"));
        assertTrue(subject1.hasRole("USER"));

//        assertTrue(subject1.isPermitted("USER:c,u"));


    }
 
开发者ID:monkeyk,项目名称:oauth2-shiro,代码行数:34,代码来源:ShiroTest.java

示例9: login

import org.apache.shiro.realm.SimpleAccountRealm; //导入依赖的package包/类
@Test
    public void login() {
        String username = "abc";
        //init SecurityManager
        SimpleAccountRealm realm = new SimpleAccountRealm("simple-realm");
        realm.addAccount(username, "abc", "USER");

        SimpleAccountRealm realm2 = new SimpleAccountRealm("simple-realm2");
        realm2.addAccount(username, "abc", "USER", "ADMIN");

        List<Realm> realmList = new ArrayList<>();
        realmList.add(realm);
        realmList.add(realm2);

        SecurityManager securityManager = new DefaultSecurityManager(realmList);
        SecurityUtils.setSecurityManager(securityManager);

        UsernamePasswordToken token = new UsernamePasswordToken(username, "abcdd");

        final Subject subject = SecurityUtils.getSubject();
        subject.login(token);


        final Subject subject1 = SecurityUtils.getSubject();
        assertTrue(subject1.isAuthenticated());

        assertFalse(subject1.isPermitted("OK"));
        assertTrue(subject1.hasRole("USER"));

//        assertTrue(subject1.isPermitted("USER:c,u"));


    }
 
开发者ID:monkeyk,项目名称:oauth2-shiro-redis,代码行数:34,代码来源:ShiroTest.java


注:本文中的org.apache.shiro.realm.SimpleAccountRealm类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。