Package org.apache.shiro.mgt

Examples of org.apache.shiro.mgt.RealmSecurityManager


            securityManager = getInstance();

            if ( realmsRefs != null && Iterables.count( realmsRefs ) > 0 ) {

                // Register Realms Services
                RealmSecurityManager realmSecurityManager = ( RealmSecurityManager ) securityManager;
                Collection<Realm> iniRealms = new ArrayList<Realm>( realmSecurityManager.getRealms() );
                for ( ServiceReference<Realm> realmRef : realmsRefs ) {
                    iniRealms.add( realmRef.get() );
                    LOG.debug( "Realm Service '{}' registered!", realmRef.identity() );
                }
                realmSecurityManager.setRealms( iniRealms );

            }

            ThreadContext.bind( securityManager );
        }
View Full Code Here


            WebEnvironment env = initEnvironment( sce.getServletContext() );

            if ( realmsRefs != null && Iterables.count( realmsRefs ) > 0 ) {

                // Register Realms Services
                RealmSecurityManager realmSecurityManager = ( RealmSecurityManager ) env.getSecurityManager();
                Collection<Realm> iniRealms = new ArrayList<Realm>( realmSecurityManager.getRealms() );
                for ( ServiceReference<Realm> realmRef : realmsRefs ) {
                    iniRealms.add( realmRef.get() );
                    LOG.debug( "Realm Service '{}' registered!", realmRef.identity() );
                }
                realmSecurityManager.setRealms( iniRealms );

            }

        }
View Full Code Here

  public void testInjectionIsSetupCorrectly() {
    SecuritySystem securitySystem = injector.getInstance(SecuritySystem.class);

    SecurityManager securityManager = injector.getInstance(SecurityManager.class);

    RealmSecurityManager realmSecurityManager =
        (RealmSecurityManager) injector.getInstance(WebSecurityManager.class);

    assertThat(securitySystem.getSecurityManager(), sameInstance(securityManager));
    assertThat(securitySystem.getSecurityManager(), sameInstance(realmSecurityManager));
View Full Code Here

    // TODO: this should be done with Guice binding?
    securitySystem.start();

    SecurityManager securityManager = injector.getInstance(SecurityManager.class);

    RealmSecurityManager realmSecurityManager = injector.getInstance(RealmSecurityManager.class);

    assertThat(securitySystem.getSecurityManager(), sameInstance(securityManager));
    assertThat(securitySystem.getSecurityManager(), sameInstance(realmSecurityManager));

    assertThat(securityManager, instanceOf(DefaultSecurityManager.class));
View Full Code Here

  public void testCacheManagerInit()
      throws Exception
  {
    // Start up security
    SecuritySystem securitySystem = this.lookup(SecuritySystem.class);
    RealmSecurityManager plexusSecurityManager = this.lookup(RealmSecurityManager.class, "default");

    List<String> realms = securitySystem.getRealms();
    realms.clear();
    realms.add(SimpleAccountRealm.class.getName());
    securitySystem.setRealms(realms);

    // now if we grab one of the realms from the Realm locator, it should have its cache set
    CachingRealm cRealm1 = (CachingRealm) plexusSecurityManager.getRealms().iterator().next();
    Assert.assertNotNull("Realm has null cacheManager", cRealm1.getCacheManager());

    // // so far so good, the cacheManager should be set on all the child realms, but what if we add one after the
    // init method?
    realms.add(SimpleAccountRealm.class.getName());
    securitySystem.setRealms(realms);

    // this list should have exactly 2 elements
    Assert.assertEquals(2, plexusSecurityManager.getRealms().size());

    for (Realm realm : plexusSecurityManager.getRealms()) {
      Assert.assertNotNull("Realm has null cacheManager", ((CachingRealm) realm).getCacheManager());
    }
  }
View Full Code Here

    if (!subject.getPrincipal().toString().equals(username)) {
      throw new WebApplicationException("Username mismatch", Status.BAD_REQUEST);
    }

    // Ask the sec-manager to authenticate, this won't alter the current subject
    RealmSecurityManager sm = security.getSecurityManager();
    try {
      sm.authenticate(new UsernamePasswordToken(username, password));
    }
    catch (AuthenticationException e) {
      log.trace("Authentication failed", e);
      throw new WebApplicationException("Authentication failed", Status.FORBIDDEN);
    }
View Full Code Here

    protected boolean isAutoApplyRealms(SecurityManager securityManager) {
        boolean autoApply = true;
        if (securityManager instanceof RealmSecurityManager) {
            //only apply realms if they haven't been explicitly set by the user:
            RealmSecurityManager realmSecurityManager = (RealmSecurityManager) securityManager;
            Collection<Realm> realms = realmSecurityManager.getRealms();
            if (!CollectionUtils.isEmpty(realms)) {
                log.info("Realms have been explicitly set on the SecurityManager instance - auto-setting of " +
                        "realms will not occur.");
                autoApply = false;
            }
View Full Code Here

        return AuthenticationRequestPassword.class.isAssignableFrom(authenticationRequestClass);
    }

    @Override
    public AuthenticationSession authenticate(final AuthenticationRequest request, final String code) {
        RealmSecurityManager securityManager = getSecurityManager();
        if(securityManager == null) {
            return null;
        }
        final AuthenticationToken token = asAuthenticationToken(request);
       
View Full Code Here

     * somewhere other than Shiro's {@link RealmSecurityManager}.
     */
    protected List<String> getRoles(final Subject subject, final AuthenticationToken token) {
        final List<String> roles = Lists.newArrayList();

        RealmSecurityManager securityManager = getSecurityManager();
        if(securityManager == null) {
            return roles;
        }
       
        final Set<String> realmNames = realmNamesOf(subject);
        final Collection<Realm> realms = securityManager.getRealms();
        for (final Realm realm : realms) {
            // only obtain roles from those realm(s) that authenticated this subject
            if(!realmNames.contains(realm.getName())) {
                continue;
            }
View Full Code Here

    public boolean isUsableInAnyRole(Identifier identifier) {
        return isPermitted(identifier, "w");
    }

    private boolean isPermitted(Identifier identifier, String qualifier) {
        RealmSecurityManager securityManager = getSecurityManager();
        if(securityManager == null) {
            // cannot do permission checking if no security manager
            return false;
        }
View Full Code Here

TOP

Related Classes of org.apache.shiro.mgt.RealmSecurityManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.