Search in sources :

Example 1 with SessionService

use of com.iplanet.dpro.session.service.SessionService in project OpenAM by OpenRock.

the class SessionCookies method getLBCookie.

/**
     * Returns load balancer cookie value for the Session.
     * @param  sid Session ID for load balancer cookie.
     * @return load balancer cookie value.
     * @throws SessionException if session is invalid.
     */
public String getLBCookie(SessionID sid) throws SessionException {
    String cookieValue = null;
    lbCookieName = SystemProperties.get(Constants.AM_LB_COOKIE_NAME, "amlbcookie");
    if (sessionDebug.messageEnabled()) {
        sessionDebug.message("Session.getLBCookie()" + "lbCookieName is:" + lbCookieName);
    }
    if (sid == null || StringUtils.isBlank(sid.toString())) {
        throw new SessionException(SessionBundle.rbName, "invalidSessionID", null);
    }
    if (SystemProperties.isServerMode()) {
        SessionService sessionService = InjectorHolder.getInstance(SessionService.class);
        if (!sessionService.isSiteEnabled()) {
            cookieValue = WebtopNaming.getLBCookieValue(sid.getSessionServerID());
            return lbCookieName + "=" + cookieValue;
        }
    }
    if (RESET_LB_COOKIE_NAME) {
        if (SystemProperties.isServerMode()) {
            SessionService sessionService = InjectorHolder.getInstance(SessionService.class);
            if (sessionService.isSessionFailoverEnabled() && sessionService.isLocalSite(sid)) {
                cookieValue = WebtopNaming.getLBCookieValue(sessionService.getCurrentHostServer(sid));
            }
        } else {
            Session sess = sessionCache.readSession(sid);
            if (sess != null) {
                cookieValue = sess.getProperty(lbCookieName);
            }
        }
    }
    if (StringUtils.isBlank(cookieValue)) {
        cookieValue = WebtopNaming.getLBCookieValue(sid.getExtension().getPrimaryID());
    }
    return lbCookieName + "=" + cookieValue;
}
Also used : SessionService(com.iplanet.dpro.session.service.SessionService) SessionException(com.iplanet.dpro.session.SessionException) Session(com.iplanet.dpro.session.Session)

Example 2 with SessionService

use of com.iplanet.dpro.session.service.SessionService in project OpenAM by OpenRock.

the class CDCServlet method init.

/**
     * Initiates the servlet.
     *
     * @param config Servlet Configuration object that contains configutation
     *        information for this servlet.
     * @throws ServletException if servlet failed to initialize.
     */
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    debug.message("CDCServlet Initializing...");
    try {
        tokenManager = SSOTokenManager.getInstance();
        sessionService = InjectorHolder.getInstance(SessionService.class);
        spValidator = new LdapSPValidator();
        DNSAddress = SystemConfigurationUtil.getProperty(Constants.AM_SERVER_HOST);
        IPAddress = InetAddress.getByName(DNSAddress).getHostAddress();
        authURLCookieName = SystemConfigurationUtil.getProperty(Constants.AUTH_UNIQUE_COOKIE_NAME, UNIQUE_COOKIE_NAME);
        authURLCookieDomain = SystemConfigurationUtil.getProperty(Constants.AUTH_UNIQUE_COOKIE_DOMAIN, "");
        deployDescriptor = SystemConfigurationUtil.getProperty(Constants.AM_SERVICES_DEPLOYMENT_DESCRIPTOR, DEFAULT_DEPLOY_URI);
        // Check if CDC needs to generate restricted SSO Tokens
        uniqueCookieEnabled = Boolean.valueOf(SystemConfigurationUtil.getProperty(Constants.IS_ENABLE_UNIQUE_COOKIE, "false")).booleanValue();
        if (debug.messageEnabled()) {
            debug.message("CDCServlet init params:" + " Restricted Token Enabled = " + uniqueCookieEnabled + " Auth URL Cookie Name = " + authURLCookieName + " Auth URL Cookie Domain = " + authURLCookieDomain + " Deployment Descriptor: " + deployDescriptor);
        }
    } catch (SSOException e) {
        debug.error("CDCServlet.init: Unable to get SSOTokenManager", e);
        throw new ServletException(e.getMessage());
    } catch (UnknownHostException e) {
        debug.error("CDCServlet.init", e);
        throw new ServletException(e.getMessage());
    }
}
Also used : ServletException(javax.servlet.ServletException) SessionService(com.iplanet.dpro.session.service.SessionService) UnknownHostException(java.net.UnknownHostException) SSOException(com.iplanet.sso.SSOException)

Example 3 with SessionService

use of com.iplanet.dpro.session.service.SessionService in project OpenAM by OpenRock.

the class SessionServiceURLService method getSessionServiceURL.

/**
     * Returns Session Service URL for a Session ID.
     *
     * @param sid Session ID
     * @return Session Service URL.
     * @exception SessionException
     */
public URL getSessionServiceURL(SessionID sid) throws SessionException {
    String primaryId;
    if (SystemProperties.isServerMode()) {
        /**
             * Validate that the SessionID contains valid Server and Site references.
             * This check is not appropriate for client side code as only the Site
             * reference is exposed to client code.
             */
        sid.validate();
        SessionService ss = InjectorHolder.getInstance(SessionService.class);
        if (ss.isSiteEnabled() && ss.isLocalSite(sid)) {
            if (ss.isSessionFailoverEnabled()) {
                return getSessionServiceURL(ss.getCurrentHostServer(sid));
            } else {
                primaryId = sid.getExtension().getPrimaryID();
                return getSessionServiceURL(primaryId);
            }
        }
    } else {
        primaryId = sid.getExtension().getPrimaryID();
        if (primaryId != null) {
            String secondarysites = WebtopNaming.getSecondarySites(primaryId);
            String serverID = SessionService.getAMServerID();
            if ((secondarysites != null) && (serverID != null)) {
                if (secondarysites.indexOf(serverID) != -1) {
                    return getSessionServiceURL(serverID);
                }
            }
        }
    }
    return getSessionServiceURL(sid.getSessionServerProtocol(), sid.getSessionServer(), sid.getSessionServerPort(), sid.getSessionServerURI());
}
Also used : SessionService(com.iplanet.dpro.session.service.SessionService)

Example 4 with SessionService

use of com.iplanet.dpro.session.service.SessionService in project OpenAM by OpenRock.

the class ConfigMonitoring method configureMonitoring.

/*
     *  This method is called by AMSetupServlet, when it's done
     *  configuring the OpenAM server after deployment.  It is also
     *  called by the MonitoringConfiguration load-on-startup servlet
     *  when the OpenAM server is restarted any time after being
     *  configured.  It completes the configuring of the monitoring
     *  agent with the config information that requires an SSOToken
     *  to retrieve.  There is another part of the configuration supplied
     *  to the agent by WebtopNaming.
     */
public void configureMonitoring() {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date date1 = new Date();
    String startDate = sdf.format(date1);
    debug = Debug.getInstance("amMonitoring");
    String classMethod = "ConfigMonitoring.configureMonitoring: ";
    try {
        ssoToken = getSSOToken();
    } catch (SSOException ssoe) {
        debug.error(classMethod + "Could not get proper SSOToken", ssoe);
        return;
    }
    boolean isSessFOEnabled = false;
    try {
        SessionService ssvc = InjectorHolder.getInstance(SessionService.class);
        if (ssvc != null) {
            isSessFOEnabled = ssvc.isSessionFailoverEnabled();
        } else {
            debug.error(classMethod + "unable to get session service");
        }
    } catch (Exception ex) {
        debug.error(classMethod + "exception getting session service; " + ex.getMessage());
    }
    Agent.setSFOStatus(isSessFOEnabled);
    /*
         * if monitoring disabled, go no further.  any error
         * from getMonServiceAttrs() or Agent.startAgent()
         * will result in monitoring getting disabled.
         */
    int i = getMonServiceAttrs();
    if (i != 0) {
        debug.error(classMethod + "getMonServiceAttrs returns " + i + ", monitoring disabled");
        Agent.setMonitoringDisabled();
        return;
    }
    // sitename -> primary URL
    HashMap<String, String> puMap = new HashMap<String, String>();
    // primary URL -> sitename
    HashMap<String, String> siteMap = new HashMap<String, String>();
    try {
        Set<String> siteNames = SiteConfiguration.getSites(ssoToken);
        // get primary url for each site
        if (siteNames.size() > 0) {
            for (Iterator<String> it = siteNames.iterator(); it.hasNext(); ) {
                String site = it.next();
                String purl = SiteConfiguration.getSitePrimaryURL(ssoToken, site);
                puMap.put(site, purl);
                siteMap.put(purl, site);
            }
        }
    } catch (SMSException smex) {
        debug.error(classMethod + "SMS exception: " + smex.getMessage());
        Agent.stopRMI();
        Agent.setMonitoringDisabled();
        return;
    } catch (SSOException ssoex) {
        debug.error(classMethod + "SSO exception: " + ssoex.getMessage());
        Agent.stopRMI();
        Agent.setMonitoringDisabled();
        return;
    }
    Agent.siteNames(puMap, siteMap);
    getRealmsList("/");
    if (Agent.realmsConfig(realmList) != 0) {
        debug.error(classMethod + "no realm mbeans; monitoring disabled.");
        Agent.stopRMI();
        Agent.setMonitoringDisabled();
        return;
    }
    /*
         *  probably could combine getAllRealms() and getAllRealmsSpecific()
         *  to do auth modules, and agents and groups, when auth modules'
         *  statistics can be handled per realm.
         */
    if (!skipGettingAuthModules) {
        getAllRealms("/");
    }
    getAllRealmsSpecific("/");
    if (debug.messageEnabled()) {
        // start with the root realm ("/")
        doSubRealms("/");
    }
    date1 = new Date();
    if (debug.messageEnabled()) {
        debug.message(classMethod + "\n" + "    Start time " + startDate + "\n" + "    End time = " + sdf.format(date1));
    }
}
Also used : HashMap(java.util.HashMap) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) Date(java.util.Date) IdRepoException(com.sun.identity.idm.IdRepoException) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) AMConfigurationException(com.sun.identity.authentication.config.AMConfigurationException) SessionService(com.iplanet.dpro.session.service.SessionService) SimpleDateFormat(java.text.SimpleDateFormat)

Example 5 with SessionService

use of com.iplanet.dpro.session.service.SessionService in project OpenAM by OpenRock.

the class CoreGuiceModule method configure.

@Override
protected void configure() {
    bind(new AdminTokenType()).toProvider(new AdminTokenProvider()).in(Singleton.class);
    bind(ServiceManagementDAO.class).to(ServiceManagementDAOWrapper.class).in(Singleton.class);
    bind(DNWrapper.class).in(Singleton.class);
    bind(URLValidator.class).toInstance(URLValidator.getInstance());
    bind(new TypeLiteral<TokenAdapter<JsonValue>>() {
    }).annotatedWith(Names.named(OAuth2Constants.CoreTokenParams.OAUTH_TOKEN_ADAPTER)).to(OAuthAdapter.class);
    bind(DSConfigMgr.class).toProvider(new Provider<DSConfigMgr>() {

        public DSConfigMgr get() {
            try {
                return DSConfigMgr.getDSConfigMgr();
            } catch (LDAPServiceException e) {
                throw new IllegalStateException(e);
            }
        }
    }).in(Singleton.class);
    bind(SSOTokenManager.class).toProvider(new Provider<SSOTokenManager>() {

        public SSOTokenManager get() {
            try {
                return SSOTokenManager.getInstance();
            } catch (SSOException e) {
                throw new IllegalStateException(e);
            }
        }
    }).in(Singleton.class);
    /**
         * Core Token Service bindings are divided into a number of logical groups.
         */
    // CTS General
    bind(CTSPersistentStore.class).to(CTSPersistentStoreImpl.class);
    bind(Debug.class).annotatedWith(Names.named(CoreTokenConstants.CTS_DEBUG)).toInstance(Debug.getInstance(CoreTokenConstants.CTS_DEBUG));
    bind(Debug.class).annotatedWith(Names.named(CoreTokenConstants.CTS_REAPER_DEBUG)).toInstance(Debug.getInstance(CoreTokenConstants.CTS_REAPER_DEBUG));
    bind(Debug.class).annotatedWith(Names.named(CoreTokenConstants.CTS_ASYNC_DEBUG)).toInstance(Debug.getInstance(CoreTokenConstants.CTS_ASYNC_DEBUG));
    bind(Debug.class).annotatedWith(Names.named(CoreTokenConstants.CTS_MONITOR_DEBUG)).toInstance(Debug.getInstance(CoreTokenConstants.CTS_MONITOR_DEBUG));
    bind(Debug.class).annotatedWith(Names.named(DataLayerConstants.DATA_LAYER_DEBUG)).toInstance(Debug.getInstance(DataLayerConstants.DATA_LAYER_DEBUG));
    bind(Debug.class).annotatedWith(Names.named("amSMS")).toInstance(Debug.getInstance("amSMS"));
    bind(Debug.class).annotatedWith(Names.named(PolicyMonitor.POLICY_MONITOR_DEBUG)).toInstance(Debug.getInstance(PolicyMonitor.POLICY_MONITOR_DEBUG));
    bind(Debug.class).annotatedWith(Names.named(OAuth2Constants.DEBUG_LOG_NAME)).toInstance(Debug.getInstance(OAuth2Constants.DEBUG_LOG_NAME));
    bind(CoreTokenConstants.class).in(Singleton.class);
    bind(CoreTokenConfig.class).in(Singleton.class);
    // CTS Connection Management
    bind(String.class).annotatedWith(Names.named(DataLayerConstants.ROOT_DN_SUFFIX)).toProvider(new Provider<String>() {

        public String get() {
            return SMSEntry.getRootSuffix();
        }
    }).in(Singleton.class);
    bind(ConfigurationObserver.class).toProvider(new Provider<ConfigurationObserver>() {

        public ConfigurationObserver get() {
            return ConfigurationObserver.getInstance();
        }
    }).in(Singleton.class);
    // CTS Monitoring
    bind(CTSOperationsMonitoringStore.class).to(CTSMonitoringStoreImpl.class);
    bind(CTSReaperMonitoringStore.class).to(CTSMonitoringStoreImpl.class);
    bind(CTSConnectionMonitoringStore.class).to(CTSMonitoringStoreImpl.class);
    // Enable monitoring of all CTS operations
    bind(ResultHandlerFactory.class).to(MonitoredResultHandlerFactory.class);
    // CTS Reaper configuration
    bind(ReaperQuery.class).to(ReaperConnection.class);
    // Policy Monitoring
    bind(PolicyMonitor.class).to(PolicyMonitorImpl.class);
    // SAML2 token repository dependencies
    bind(new TypeLiteral<TokenAdapter<SAMLToken>>() {
    }).to(SAMLAdapter.class);
    /**
         * Session related dependencies.
         */
    bind(SessionOperationStrategy.class).to(ServerSessionOperationStrategy.class);
    // TODO: Investigate whether or not this lazy-loading "Config<SessionService>" wrapper is still needed
    bind(new TypeLiteral<Config<SessionService>>() {
    }).toInstance(new Config<SessionService>() {

        @Override
        public boolean isReady() {
            return true;
        }

        @Override
        public SessionService get() {
            return InjectorHolder.getInstance(SessionService.class);
        }
    });
    bind(Debug.class).annotatedWith(Names.named(SessionConstants.SESSION_DEBUG)).toInstance(Debug.getInstance(SessionConstants.SESSION_DEBUG));
    bind(new TypeLiteral<Function<String, String, NeverThrowsException>>() {
    }).annotatedWith(Names.named("tagSwapFunc")).toInstance(new Function<String, String, NeverThrowsException>() {

        @Override
        public String apply(String text) {
            return ServicesDefaultValues.tagSwap(text, true);
        }
    });
    install(new FactoryModuleBuilder().implement(AMIdentityRepository.class, AMIdentityRepository.class).build(AMIdentityRepositoryFactory.class));
    install(new FactoryModuleBuilder().implement(SMSAuditor.class, SMSAuditor.class).build(ConfigAuditorFactory.class));
    Multibinder.newSetBinder(binder(), SMSAuditFilter.class);
    Multibinder.newSetBinder(binder(), IdRepoCreationListener.class);
    bind(Stats.class).annotatedWith(Names.named(SessionConstants.STATS_MASTER_TABLE)).toInstance(Stats.getInstance(SessionConstants.STATS_MASTER_TABLE));
    bind(SessionCache.class).toInstance(SessionCache.getInstance());
    bind(SessionPollerPool.class).toInstance(SessionPollerPool.getInstance());
    /*
         * Must use a provider to ensure initialisation happens after SystemProperties have been set.
         */
    bind(SessionCookies.class).toProvider(new Provider<SessionCookies>() {

        @Override
        public SessionCookies get() {
            return SessionCookies.getInstance();
        }
    });
    /*
         * Must use a provider to ensure initialisation happens after SystemProperties have been set.
         */
    bind(SessionURL.class).toProvider(new Provider<SessionURL>() {

        @Override
        public SessionURL get() {
            return SessionURL.getInstance();
        }
    });
    bind(SessionServiceURLService.class).toInstance(SessionServiceURLService.getInstance());
    bind(ConsoleConfigHandler.class).to(ConsoleConfigHandlerImpl.class);
}
Also used : ServiceManagementDAOWrapper(com.sun.identity.sm.ServiceManagementDAOWrapper) FactoryModuleBuilder(com.google.inject.assistedinject.FactoryModuleBuilder) SessionURL(org.forgerock.openam.session.SessionURL) SSOException(com.iplanet.sso.SSOException) PolicyMonitor(org.forgerock.openam.entitlement.monitoring.PolicyMonitor) CTSOperationsMonitoringStore(org.forgerock.openam.cts.monitoring.CTSOperationsMonitoringStore) CTSPersistentStore(org.forgerock.openam.cts.CTSPersistentStore) Function(org.forgerock.util.Function) SessionCookies(org.forgerock.openam.session.SessionCookies) TypeLiteral(com.google.inject.TypeLiteral) URLValidator(com.sun.identity.shared.validation.URLValidator) ConfigAuditorFactory(com.sun.identity.sm.ldap.ConfigAuditorFactory) LDAPServiceException(com.iplanet.services.ldap.LDAPServiceException) CTSConnectionMonitoringStore(org.forgerock.openam.cts.monitoring.CTSConnectionMonitoringStore) ServerSessionOperationStrategy(com.iplanet.dpro.session.operations.ServerSessionOperationStrategy) SessionOperationStrategy(com.iplanet.dpro.session.operations.SessionOperationStrategy) SessionPollerPool(org.forgerock.openam.session.SessionPollerPool) CTSReaperMonitoringStore(org.forgerock.openam.cts.monitoring.CTSReaperMonitoringStore) ConsoleConfigHandler(org.forgerock.openam.sm.config.ConsoleConfigHandler) AMIdentityRepositoryFactory(org.forgerock.openam.identity.idm.AMIdentityRepositoryFactory) SAMLToken(org.forgerock.openam.cts.api.tokens.SAMLToken) SessionServiceURLService(org.forgerock.openam.session.SessionServiceURLService) Provider(com.google.inject.Provider) ReaperQuery(org.forgerock.openam.cts.impl.query.reaper.ReaperQuery) CoreTokenConfig(org.forgerock.openam.cts.CoreTokenConfig) NeverThrowsException(org.forgerock.util.promise.NeverThrowsException) SessionService(com.iplanet.dpro.session.service.SessionService) CoreTokenConstants(org.forgerock.openam.cts.api.CoreTokenConstants) TokenAdapter(org.forgerock.openam.cts.adapters.TokenAdapter) MonitoredResultHandlerFactory(org.forgerock.openam.cts.monitoring.impl.queue.MonitoredResultHandlerFactory) ResultHandlerFactory(org.forgerock.openam.cts.impl.queue.ResultHandlerFactory) SessionCache(org.forgerock.openam.session.SessionCache)

Aggregations

SessionService (com.iplanet.dpro.session.service.SessionService)5 SSOException (com.iplanet.sso.SSOException)3 Provider (com.google.inject.Provider)1 TypeLiteral (com.google.inject.TypeLiteral)1 FactoryModuleBuilder (com.google.inject.assistedinject.FactoryModuleBuilder)1 Session (com.iplanet.dpro.session.Session)1 SessionException (com.iplanet.dpro.session.SessionException)1 ServerSessionOperationStrategy (com.iplanet.dpro.session.operations.ServerSessionOperationStrategy)1 SessionOperationStrategy (com.iplanet.dpro.session.operations.SessionOperationStrategy)1 LDAPServiceException (com.iplanet.services.ldap.LDAPServiceException)1 AMConfigurationException (com.sun.identity.authentication.config.AMConfigurationException)1 IdRepoException (com.sun.identity.idm.IdRepoException)1 URLValidator (com.sun.identity.shared.validation.URLValidator)1 SMSException (com.sun.identity.sm.SMSException)1 ServiceManagementDAOWrapper (com.sun.identity.sm.ServiceManagementDAOWrapper)1 ConfigAuditorFactory (com.sun.identity.sm.ldap.ConfigAuditorFactory)1 UnknownHostException (java.net.UnknownHostException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1