diff --git a/src/main/java/de/thm/arsnova/controller/LoginController.java b/src/main/java/de/thm/arsnova/controller/LoginController.java index 5d422f5153b9fe55197ee566a904b9dab4dcd917..4affba491ff90aa446c5c8ff8ced62eb30f8aa9e 100644 --- a/src/main/java/de/thm/arsnova/controller/LoginController.java +++ b/src/main/java/de/thm/arsnova/controller/LoginController.java @@ -19,12 +19,13 @@ package de.thm.arsnova.controller; import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; import java.util.ArrayList; import java.util.Collection; import java.util.List; import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -35,6 +36,7 @@ import org.scribe.up.session.HttpUserSession; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.cas.authentication.CasAuthenticationToken; @@ -54,10 +56,10 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.servlet.View; import org.springframework.web.servlet.view.RedirectView; +import de.thm.arsnova.entities.ServiceDescription; import de.thm.arsnova.entities.Session; import de.thm.arsnova.entities.User; import de.thm.arsnova.exceptions.UnauthorizedException; @@ -70,6 +72,21 @@ public class LoginController extends AbstractController { private static final int MAX_USERNAME_LENGTH = 15; private static final int MAX_GUESTHASH_LENGTH = 10; + @Value("${security.guest.enabled}") + private String guestEnabled; + @Value("${security.guest.lecturer.enabled}") + private String guestLecturerEnabled; + @Value("${security.cas.enabled}") + private String casEnabled; + @Value("${security.ldap.enabled}") + private String ldapEnabled; + @Value("${security.facebook.enabled}") + private String facebookEnabled; + @Value("${security.google.enabled}") + private String googleEnabled; + @Value("${security.twitter.enabled}") + private String twitterEnabled; + @Autowired private TwitterProvider twitterProvider; @@ -170,13 +187,6 @@ public class LoginController extends AbstractController { final HttpServletResponse response ) { if ("ldap".equals(type) && !"".equals(userName) && !"".equals(password)) { -// String referer = request.getHeader("referer"); -// if (null != forcedReferer && null != referer && !UrlUtils.isAbsoluteUrl(referer)) { -// referer = forcedReferer; -// } -// if (null == referer) { -// referer = "/"; -// } org.springframework.security.core.userdetails.User user = new org.springframework.security.core.userdetails.User( userName, password, true, true, true, true, this.getAuthorities() @@ -223,6 +233,60 @@ public class LoginController extends AbstractController { return new RedirectView(request.getHeader("referer") != null ? request.getHeader("referer") : "/"); } + @RequestMapping(value = { "/auth/services" }, method = RequestMethod.GET) + @ResponseBody + public final List<ServiceDescription> getServices(final HttpServletRequest request) { + List<ServiceDescription> services = new ArrayList<ServiceDescription>(); + + if ("true".equals(guestEnabled)) { + ServiceDescription sdesc = new ServiceDescription( + "Guest", + null + ); + if (!"true".equals(guestLecturerEnabled)) { + sdesc.setAllowLecturer(false); + } + services.add(sdesc); + } + + if ("true".equals(casEnabled)) { + try { + services.add(new ServiceDescription( + "CAS", + casEntryPoint.getLoginUrl() + + "?" + casEntryPoint.getServiceProperties().getServiceParameter() + + "=" + URLEncoder.encode(casEntryPoint.getServiceProperties().getService(), "UTF-8") + )); + } catch (UnsupportedEncodingException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + if ("true".equals(facebookEnabled)) { + services.add(new ServiceDescription( + "Facebook", + facebookProvider.getAuthorizationUrl(new HttpUserSession(request)) + )); + } + + if ("true".equals(googleEnabled)) { + services.add(new ServiceDescription( + "Google", + googleProvider.getAuthorizationUrl(new HttpUserSession(request)) + )); + } + + if ("true".equals(twitterEnabled)) { + services.add(new ServiceDescription( + "Twitter", + twitterProvider.getAuthorizationUrl(new HttpUserSession(request)) + )); + } + + return services; + } + private Collection<GrantedAuthority> getAuthorities() { List<GrantedAuthority> authList = new ArrayList<GrantedAuthority>(); authList.add(new GrantedAuthorityImpl("ROLE_USER")); diff --git a/src/main/java/de/thm/arsnova/entities/ServiceDescription.java b/src/main/java/de/thm/arsnova/entities/ServiceDescription.java new file mode 100644 index 0000000000000000000000000000000000000000..2cc6bfabdf7fcc6b5caaa9fb9f7bb67e7d31a43c --- /dev/null +++ b/src/main/java/de/thm/arsnova/entities/ServiceDescription.java @@ -0,0 +1,44 @@ +package de.thm.arsnova.entities; + +public class ServiceDescription { + + private String name; + private String dialogUrl; + private boolean allowLecturer = true; + + public ServiceDescription(String name, String dialogUrl) { + this.name = name; + this.dialogUrl = dialogUrl; + } + + public ServiceDescription(String name, String dialogUrl, boolean allowLecturer) { + this.name = name; + this.dialogUrl = dialogUrl; + this.allowLecturer = allowLecturer; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDialogUrl() { + return dialogUrl; + } + + public void setDialogUrl(String dialogUrl) { + this.dialogUrl = dialogUrl; + } + + public boolean isAllowLecturer() { + return allowLecturer; + } + + public void setAllowLecturer(boolean allowLecturer) { + this.allowLecturer = allowLecturer; + } + +} diff --git a/src/main/webapp/WEB-INF/spring/arsnova-servlet.xml b/src/main/webapp/WEB-INF/spring/arsnova-servlet.xml index e0e455c07fa09db1ab3df50a02006185dea988e1..45726d3c264a5bcbfe40632a1bbaf87dcc0f225e 100644 --- a/src/main/webapp/WEB-INF/spring/arsnova-servlet.xml +++ b/src/main/webapp/WEB-INF/spring/arsnova-servlet.xml @@ -4,6 +4,7 @@ xmlns:aop="http://www.springframework.org/schema/aop" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" + xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd @@ -12,6 +13,7 @@ <!-- ARSnova Servlet Context --> <context:component-scan base-package="de.thm.arsnova.controller" /> + <context:property-placeholder location="file:///etc/arsnova/arsnova.properties" /> <mvc:annotation-driven content-negotiation-manager="contentNegotiationManager" /> <bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean"> diff --git a/src/main/webapp/arsnova.properties.example b/src/main/webapp/arsnova.properties.example index 0db2d28970d6ebec47466294b361b4c7443f9ea3..ab44df3147f58e0427cdcbd71f60b983bfcfaea4 100644 --- a/src/main/webapp/arsnova.properties.example +++ b/src/main/webapp/arsnova.properties.example @@ -1,19 +1,27 @@ security.arsnova-url=http://localhost:8080 -security.cas-server-url=https://cas.thm.de/cas - -security.facebook.key=318531508227494 -security.facebook.secret=e3f38cfc72bb63e35641b637081a6177 -security.twitter.key=PEVtidSG0HzSrxVRPpsCXw -security.twitter.secret=mC0HOvxiEgqwdDWCcDoy3q75nUQPu1bYRp1ncHWGd0 - -security.google.key=110959746118.apps.googleusercontent.com -security.google.secret=CkzUJZswY8rjWCCYnHVovyGA +security.guest.enabled=true +security.guest.lecturer.enabled=true +security.ldap.enabled=true security.ldap.url=ldap://example.com:33389/dc=example,dc=com security.ldap.user-search-filter=(uid={0}) security.ldap.user-search-base="ou=people" +security.cas.enabled=true +security.cas-server-url=https://cas.thm.de/cas + +security.facebook.enabled=true +security.facebook.key= +security.facebook.secret= + +security.twitter.enabled=true +security.twitter.key= +security.twitter.secret= + +security.google.enabled=true +security.google.key= +security.google.secret= security.ssl=false security.keystore=/etc/arsnova.thm.de.jks