...
- Using Spring to get the service for your class (e.g. YourAppClass) (recommended)
- Add the SessionManager bean to the bean for YourAppClass
Code Block xml xml <bean id="org.sakaiproject.yourapp.logic.YourAppClass" class="org.sakaiproject.yourapp.logic.impl.YourAppClassImpl"> <property name="sessionManager" ref="org.sakaiproject.tool.api.SessionManager" /> </bean>
- Add a variable and setter to YourAppClass to use the service in like so:
Code Block java java private SessionManager sessionManager; public void setSessionManager(SessionManager sessionManager) { this.sessionManager = sessionManager; }
- Add the SessionManager bean to the bean for YourAppClass
- Using the cover Component Manager to get the service
- Note: This is not the recommended method, you should be using Spring to inject the service
- Setup a variable to hold the instance from the cover
Code Block java java Get access to the service using the cover Use the CM cover to get the serviceprivate SessionManager sessionManager;
Code Block java java sessionManager = import org.sakaiproject.component.cover.ComponentManager; import org.sakaiproject.tool.coverapi.SessionManager.getInstance();
Code Block xml xml <dependency> <groupId>sakaiproject</groupId> <artifactId>sakai-tool-api</artifactId> <version>${sakai.version}</version> </dependency>; ... private SessionManager sessionManager; ... sessionManager = (SessionManager) ComponentManager.get(SessionManager.class);
Getting the current user Session
...