Readded connector client implementation

parent 841685d8
......@@ -313,6 +313,11 @@
<artifactId>httpclient</artifactId>
<version>4.2.2</version>
</dependency>
<dependency>
<groupId>de.thm.arsnova.connector</groupId>
<artifactId>connector-client</artifactId>
<version>0.12.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
......
......@@ -1246,4 +1246,15 @@ public class CouchDBDao implements IDatabaseDao {
return null;
}
}
@Override
public String getCourseId(String keyword) {
return this.getSession(keyword).getCourseId();
}
@Override
public boolean isCourseSession(String keyword) {
return (this.getSession(keyword).getCourseId() != null) &&
(this.getSession(keyword).getCourseType() != null);
}
}
......@@ -114,4 +114,8 @@ public interface IDatabaseDao {
void markInterposedQuestionAsRead(InterposedQuestion question) throws IOException;
List<Session> getMyVisitedSessions(User user);
String getCourseId(String keyword);
boolean isCourseSession(String keyword);
}
......@@ -27,6 +27,9 @@ public class Session {
private String creator;
private boolean active;
private long lastOwnerActivity;
private String courseType;
private String courseId;
private String _id;
private String _rev;
......@@ -105,4 +108,20 @@ public class Session {
public boolean isCreator(User user) {
return user.getUsername().equals(this.creator);
}
public String getCourseType() {
return courseType;
}
public void setCourseType(String courseType) {
this.courseType = courseType;
}
public String getCourseId() {
return courseId;
}
public void setCourseId(String courseId) {
this.courseId = courseId;
}
}
......@@ -25,10 +25,12 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import de.thm.arsnova.annotation.Authenticated;
import de.thm.arsnova.connector.client.ConnectorClient;
import de.thm.arsnova.dao.IDatabaseDao;
import de.thm.arsnova.entities.LoggedIn;
import de.thm.arsnova.entities.Session;
import de.thm.arsnova.entities.User;
import de.thm.arsnova.exceptions.ForbiddenException;
@Service
public class SessionService implements ISessionService {
......@@ -40,6 +42,9 @@ public class SessionService implements ISessionService {
@Autowired
private IUserService userService;
@Autowired(required=false)
private ConnectorClient connectorClient;
public void setDatabaseDao(final IDatabaseDao newDatabaseDao) {
this.databaseDao = newDatabaseDao;
......@@ -48,8 +53,16 @@ public class SessionService implements ISessionService {
@Override
@Authenticated
public final Session joinSession(final String keyword) {
userService.addCurrentUserToSessionMap(keyword);
return databaseDao.getSession(keyword);
Session session = databaseDao.getSession(keyword);
if (connectorClient != null && databaseDao.isCourseSession(keyword)) {
String courseid = databaseDao.getCourseId(keyword);
if (! connectorClient.getMembership(userService.getCurrentUser().getUsername(), courseid).isMember()) {
throw new ForbiddenException();
}
}
return session;
}
@Override
......
......@@ -43,4 +43,13 @@
<bean id="userService" scope="singleton" class="de.thm.arsnova.services.UserService" />
<!-- Example of connector client configuration -->
<!-- Uncomment bean definition to activate connector -->
<!-- -->
<bean id="moodleClient" scope="singleton" class="de.thm.arsnova.connector.client.ConnectorClientImpl">
<property name="serviceLocation" value="${connector.uri}"></property>
<property name="username" value="${connector.username}"></property>
<property name="password" value="${connector.password}"></property>
</bean>
<!-- -->
</beans>
......@@ -22,4 +22,8 @@ couchdb.port=5984
couchdb.name=arsnova
socketio.ip=0.0.0.0
socketio.port=10443
\ No newline at end of file
socketio.port=10443
connector.uri=http://localhost:8080/connector-service
connector.username=test
connector.password=test
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment