org.apache.shiro.UnavailableSecurityManagerException Java Examples

The following examples show how to use org.apache.shiro.UnavailableSecurityManagerException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CustomResolverTest.java    From usergrid with Apache License 2.0 6 votes vote down vote up
@AfterClass
public static void tearDownShiro() {
    doClearSubject();

    try {
        org.apache.shiro.mgt.SecurityManager securityManager = SecurityUtils.getSecurityManager();
        LifecycleUtils.destroy( securityManager );
    }
    catch ( UnavailableSecurityManagerException e ) {
        // we don't care about this when cleaning up the test environment
        // (for example, maybe the subclass is a unit test and it didn't
        // need a SecurityManager instance because it was using only
        // mock Subject instances)
    }
    SecurityUtils.setSecurityManager( null );
}
 
Example #2
Source File: SessionCacheManager.java    From NutzSite with Apache License 2.0 5 votes vote down vote up
public Session getSession(){
    Session session = null;
    try{
        Subject subject = SecurityUtils.getSubject();
        session = subject.getSession(false);
        if (session == null){
            session = subject.getSession();
        }
    }catch (InvalidSessionException e){
        logger.error("Invalid session error", e);
    }catch (UnavailableSecurityManagerException e2){
        logger.error("Unavailable SecurityManager error", e2);
    }
    return session;
}
 
Example #3
Source File: SessionCacheManager.java    From easyweb with Apache License 2.0 5 votes vote down vote up
public Session getSession(){
	Session session = null;
	try{
		Subject subject = SecurityUtils.getSubject();
		session = subject.getSession(false);
		if (session == null){
			session = subject.getSession();
		}
	}catch (InvalidSessionException e){
		logger.error("Invalid session error", e);
	}catch (UnavailableSecurityManagerException e2){
		logger.error("Unavailable SecurityManager error", e2);
	}
	return session;
}
 
Example #4
Source File: SessionCacheManager.java    From Shop-for-JavaWeb with MIT License 5 votes vote down vote up
public Session getSession(){
	Session session = null;
	try{
		Subject subject = SecurityUtils.getSubject();
		session = subject.getSession(false);
		if (session == null){
			session = subject.getSession();
		}
	}catch (InvalidSessionException e){
		logger.error("Invalid session error", e);
	}catch (UnavailableSecurityManagerException e2){
		logger.error("Unavailable SecurityManager error", e2);
	}
	return session;
}
 
Example #5
Source File: ShiroAuthenticationService.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
@Inject
public ShiroAuthenticationService(ZeppelinConfiguration conf) throws Exception {
  LOGGER.info("ShiroAuthenticationService is initialized");
  this.conf = conf;
  if (conf.getShiroPath().length() > 0) {
    try {
      Collection<Realm> realms =
          ((DefaultWebSecurityManager) org.apache.shiro.SecurityUtils.getSecurityManager())
              .getRealms();
      if (realms.size() > 1) {
        Boolean isIniRealmEnabled = false;
        for (Realm realm : realms) {
          if (realm instanceof IniRealm && ((IniRealm) realm).getIni().get("users") != null) {
            isIniRealmEnabled = true;
            break;
          }
        }
        if (isIniRealmEnabled) {
          throw new Exception(
              "IniRealm/password based auth mechanisms should be exclusive. "
                  + "Consider removing [users] block from shiro.ini");
        }
      }
    } catch (UnavailableSecurityManagerException e) {
      LOGGER.error("Failed to initialise shiro configuration", e);
    }
  }
}
 
Example #6
Source File: AbstractShiroTest.java    From seed with Mozilla Public License 2.0 5 votes vote down vote up
@AfterClass
public static void tearDownShiro() {
    doClearSubject();
    try {
        SecurityManager securityManager = getSecurityManager();
        LifecycleUtils.destroy(securityManager);
    } catch (UnavailableSecurityManagerException e) {
        // we don't care about this when cleaning up the test environment
        // (for example, maybe the subclass is a unit test and it didn't
        // need a SecurityManager instance because it was using only
        // mock Subject instances)
    }
    setSecurityManager(null);
}
 
Example #7
Source File: AbstractShiroTest.java    From gazpachoquest with GNU General Public License v3.0 5 votes vote down vote up
@AfterClass
public static void tearDownShiro() {
    doClearSubject();
    try {
        SecurityManager securityManager = getSecurityManager();
        LifecycleUtils.destroy(securityManager);
    } catch (UnavailableSecurityManagerException e) {
        // we don't care about this when cleaning up the test environment
        // (for example, maybe the subclass is a unit test and it didn't
        // need a SecurityManager instance because it was using only
        // mock Subject instances)
    }
    setSecurityManager(null);
}
 
Example #8
Source File: ShiroLogin.java    From gazpachoquest with GNU General Public License v3.0 5 votes vote down vote up
public static void tearDownShiro() {
    doClearSubject();
    try {
        SecurityManager securityManager = getSecurityManager();
        LifecycleUtils.destroy(securityManager);
    } catch (UnavailableSecurityManagerException e) {
        // we don't care about this when cleaning up the test environment
        // (for example, maybe the subclass is a unit test and it didn't
        // need a SecurityManager instance because it was using only
        // mock Subject instances)
    }
    setSecurityManager(null);
}
 
Example #9
Source File: SubjectUtils.java    From usergrid with Apache License 2.0 5 votes vote down vote up
public static Subject getSubject() {
    Subject currentUser = null;
    try {
        currentUser = SecurityUtils.getSubject();
    }
    catch ( UnavailableSecurityManagerException e ) {
        logger.error( "getSubject(): Attempt to use Shiro prior to initialization" );
    }
    return currentUser;
}
 
Example #10
Source File: ManagementServiceImpl.java    From usergrid with Apache License 2.0 4 votes vote down vote up
@Override
public ApplicationInfo createApplication(UUID organizationId, String applicationName, UUID applicationId,
                                         Map<String, Object> properties, boolean forMigration) throws Exception {

    if ( ( organizationId == null ) || ( applicationName == null ) ) {
        return null;
    }

    if ( properties == null ) {
        properties = new HashMap<>();
    }

    OrganizationInfo organizationInfo = getOrganizationByUuid( organizationId );
    Entity appInfo = emf.createApplicationV2(
        organizationInfo.getName(), applicationName, applicationId ,properties, forMigration);

    // only generate a client secret on app creation when the app is not being created during appinfo migration
    if( !forMigration ){

        writeUserToken( smf.getManagementAppId(), appInfo,
            encryptionService.plainTextCredentials(
                generateOAuthSecretKey( AuthPrincipalType.APPLICATION ),
                null,
                smf.getManagementAppId() ) );
    }


    applicationId = addApplicationToOrganization( organizationId, appInfo );

    UserInfo user = null;
    try {
        user = SubjectUtils.getUser();
    }
    catch ( UnavailableSecurityManagerException e ) {
        // occurs in the rare case that this is called before the full stack is initialized
        logger.warn("Error getting user, application created activity will not be created", e);
    }
    if ( ( user != null ) && user.isAdminUser() ) {
        postOrganizationActivity( organizationId, user, "create", appInfo, "Application", applicationName,
            "<a href=\"mailto:" + user.getEmail() + "\">" + user.getName() + " (" + user.getEmail()
                + ")</a> created a new application named " + applicationName, null );
    }

    invalidateManagementAppAuthCache();

    return new ApplicationInfo( applicationId, appInfo.getName() );
}
 
Example #11
Source File: ManagementServiceImpl.java    From usergrid with Apache License 2.0 4 votes vote down vote up
@Override
public ApplicationInfo restoreApplication(UUID applicationId) throws Exception {

    ApplicationInfo app = getDeletedApplicationInfo( applicationId );
    if ( app == null ) {
        throw new EntityNotFoundException("Deleted application ID " + applicationId + " not found");
    }

    if ( emf.lookupApplication( app.getName() ) != null ) {
        throw new ConflictException("Cannot restore application, one with that name already exists.");
    }

    // restore application_info entity

    EntityManager em = emf.getEntityManager( emf.getManagementAppId() );
    Entity appInfo = emf.restoreApplication(applicationId);

    // restore token

    writeUserToken( smf.getManagementAppId(), appInfo,
        encryptionService.plainTextCredentials(
            generateOAuthSecretKey( AuthPrincipalType.APPLICATION ),
            null,
            smf.getManagementAppId() ) );

    String orgName = appInfo.getName().split("/")[0];
    EntityRef alias = em.getAlias( Group.ENTITY_TYPE, orgName );
    Entity orgEntity = em.get( alias );

    addApplicationToOrganization( orgEntity.getUuid(), appInfo );

    // create activity

    UserInfo user = null;
    try {
        user = SubjectUtils.getUser();
    }
    catch ( UnavailableSecurityManagerException e ) {
        // occurs in the rare case that this is called before the full stack is initialized
        logger.warn("Error getting user, application restored created activity will not be created", e);
    }
    if ( ( user != null ) && user.isAdminUser() ) {
        postOrganizationActivity( orgEntity.getUuid(), user, "restore", appInfo, "Application", appInfo.getName(),
            "<a href=\"mailto:" + user.getEmail() + "\">" + user.getName() + " (" + user.getEmail()
                + ")</a> restored an application named " + appInfo.getName(), null );
    }

    invalidateManagementAppAuthCache();

    return new ApplicationInfo( applicationId, appInfo.getName() );
}