Skip to content
Snippets Groups Projects
Commit 71bc6a42 authored by uhensler's avatar uhensler
Browse files

OO-2891: Proper object initialisation with Spring

parent f4312487
No related branches found
No related tags found
No related merge requests found
...@@ -41,6 +41,7 @@ import org.olat.admin.user.delete.service.UserDeletionManager; ...@@ -41,6 +41,7 @@ import org.olat.admin.user.delete.service.UserDeletionManager;
import org.olat.basesecurity.AuthHelper; import org.olat.basesecurity.AuthHelper;
import org.olat.basesecurity.Authentication; import org.olat.basesecurity.Authentication;
import org.olat.basesecurity.BaseSecurity; import org.olat.basesecurity.BaseSecurity;
import org.olat.core.CoreSpringFactory;
import org.olat.core.dispatcher.Dispatcher; import org.olat.core.dispatcher.Dispatcher;
import org.olat.core.dispatcher.DispatcherModule; import org.olat.core.dispatcher.DispatcherModule;
import org.olat.core.gui.UserRequest; import org.olat.core.gui.UserRequest;
...@@ -207,7 +208,8 @@ public class ShibbolethDispatcher implements Dispatcher{ ...@@ -207,7 +208,8 @@ public class ShibbolethDispatcher implements Dispatcher{
// Successful login // Successful login
Identity authenticationedIdentity = ureq.getIdentity(); Identity authenticationedIdentity = ureq.getIdentity();
userDeletionManager.setIdentityAsActiv(authenticationedIdentity); userDeletionManager.setIdentityAsActiv(authenticationedIdentity);
ShibbolethAttributes shibbolethAttriutes = new ShibbolethAttributes(attributesMap); ShibbolethAttributes shibbolethAttriutes = CoreSpringFactory.getImpl(ShibbolethAttributes.class);
shibbolethAttriutes.setAttributesMap(attributesMap);
shibbolethManager.syncUser(authenticationedIdentity, shibbolethAttriutes); shibbolethManager.syncUser(authenticationedIdentity, shibbolethAttriutes);
ureq.getUserSession().getIdentityEnvironment().addAttributes( ureq.getUserSession().getIdentityEnvironment().addAttributes(
shibbolethModule.getAttributeTranslator().translateAttributesMap(attributesMap)); shibbolethModule.getAttributeTranslator().translateAttributesMap(attributesMap));
......
...@@ -330,7 +330,8 @@ public class ShibbolethRegistrationController extends DefaultController implemen ...@@ -330,7 +330,8 @@ public class ShibbolethRegistrationController extends DefaultController implemen
if(!hasEmailInShibAttr){ if(!hasEmailInShibAttr){
shibbolethAttributesMap.put(shibbolethModule.getShibbolethAttributeName(UserConstants.EMAIL), regWithEmailForm.getEmail()); shibbolethAttributesMap.put(shibbolethModule.getShibbolethAttributeName(UserConstants.EMAIL), regWithEmailForm.getEmail());
} }
ShibbolethAttributes shibbolethAttributes = new ShibbolethAttributes(shibbolethAttributesMap); ShibbolethAttributes shibbolethAttributes = CoreSpringFactory.getImpl(ShibbolethAttributes.class);
shibbolethAttributes.setAttributesMap(shibbolethAttributesMap);
String email = shibbolethAttributes.getValueForUserPropertyName(UserConstants.EMAIL); String email = shibbolethAttributes.getValueForUserPropertyName(UserConstants.EMAIL);
User user = null; User user = null;
...@@ -362,7 +363,8 @@ public class ShibbolethRegistrationController extends DefaultController implemen ...@@ -362,7 +363,8 @@ public class ShibbolethRegistrationController extends DefaultController implemen
secMgr.createAndPersistAuthentication(authenticationedIdentity, ShibbolethDispatcher.PROVIDER_SHIB, shibbolethUniqueID, null, null); secMgr.createAndPersistAuthentication(authenticationedIdentity, ShibbolethDispatcher.PROVIDER_SHIB, shibbolethUniqueID, null, null);
// update user profile // update user profile
ShibbolethAttributes shibbolethAttributes = new ShibbolethAttributes(shibbolethAttributesMap); ShibbolethAttributes shibbolethAttributes = CoreSpringFactory.getImpl(ShibbolethAttributes.class);
shibbolethAttributes.setAttributesMap(shibbolethAttributesMap);
shibbolethManager.syncUser(authenticationedIdentity, shibbolethAttributes); shibbolethManager.syncUser(authenticationedIdentity, shibbolethAttributes);
doLogin(authenticationedIdentity, ureq); doLogin(authenticationedIdentity, ureq);
......
...@@ -22,6 +22,7 @@ package org.olat.shibboleth.handler; ...@@ -22,6 +22,7 @@ package org.olat.shibboleth.handler;
import org.olat.core.CoreSpringFactory; import org.olat.core.CoreSpringFactory;
import org.olat.core.logging.OLog; import org.olat.core.logging.OLog;
import org.olat.core.logging.Tracing; import org.olat.core.logging.Tracing;
import org.olat.core.util.StringHelper;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**
...@@ -43,7 +44,7 @@ public class SpringShibbolethAttributeHandlerFactory implements ShibbolethAttrib ...@@ -43,7 +44,7 @@ public class SpringShibbolethAttributeHandlerFactory implements ShibbolethAttrib
try { try {
shibbolethAttributeHandler = getHandlerByName(handlerName); shibbolethAttributeHandler = getHandlerByName(handlerName);
} catch (Exception e) { } catch (Exception e) {
if (handlerName != null) { if (StringHelper.containsNonWhitespace(handlerName)) {
log.warn("ShibbolethAttributeHandler '" + handlerName log.warn("ShibbolethAttributeHandler '" + handlerName
+ "' does not exist. Using the Default ShibbolethAttributeHandler '" + DEFAULT_HANDLER_NAME + "' does not exist. Using the Default ShibbolethAttributeHandler '" + DEFAULT_HANDLER_NAME
+ "'."); + "'.");
......
...@@ -28,6 +28,8 @@ import org.olat.shibboleth.ShibbolethModule; ...@@ -28,6 +28,8 @@ import org.olat.shibboleth.ShibbolethModule;
import org.olat.shibboleth.handler.ShibbolethAttributeHandler; import org.olat.shibboleth.handler.ShibbolethAttributeHandler;
import org.olat.shibboleth.handler.ShibbolethAttributeHandlerFactory; import org.olat.shibboleth.handler.ShibbolethAttributeHandlerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
/** /**
* *
...@@ -35,6 +37,8 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -35,6 +37,8 @@ import org.springframework.beans.factory.annotation.Autowired;
* @author uhensler, urs.hensler@frentix.com, http://www.frentix.com * @author uhensler, urs.hensler@frentix.com, http://www.frentix.com
* *
*/ */
@Component
@Scope("prototype")
public class ShibbolethAttributes { public class ShibbolethAttributes {
private Map<String, String> shibbolethMap; private Map<String, String> shibbolethMap;
...@@ -44,8 +48,8 @@ public class ShibbolethAttributes { ...@@ -44,8 +48,8 @@ public class ShibbolethAttributes {
@Autowired @Autowired
private ShibbolethAttributeHandlerFactory shibbolethAttributeHandlerFactory; private ShibbolethAttributeHandlerFactory shibbolethAttributeHandlerFactory;
public ShibbolethAttributes(Map<String, String> shibbolethMap) { public void setAttributesMap(Map<String, String> attributesMap) {
this.shibbolethMap = shibbolethMap; this.shibbolethMap = attributesMap;
} }
public String getValueForAttributeName(String attributeName) { public String getValueForAttributeName(String attributeName) {
...@@ -105,4 +109,5 @@ public class ShibbolethAttributes { ...@@ -105,4 +109,5 @@ public class ShibbolethAttributes {
private Set<Entry<String, String>> getUserMappingEntrySet() { private Set<Entry<String, String>> getUserMappingEntrySet() {
return shibbolethModule.getUserMapping().entrySet(); return shibbolethModule.getUserMapping().entrySet();
} }
} }
...@@ -81,7 +81,8 @@ public class ShibbolethAttributesTest { ...@@ -81,7 +81,8 @@ public class ShibbolethAttributesTest {
when(shibbolethModuleMock.getUserMapping()).thenReturn(shibbolethUserMapping); when(shibbolethModuleMock.getUserMapping()).thenReturn(shibbolethUserMapping);
Map<String, String> shibbolethKeysValues = initShibbolethMap(); Map<String, String> shibbolethKeysValues = initShibbolethMap();
sut = new ShibbolethAttributes(shibbolethKeysValues); sut = new ShibbolethAttributes();
sut.setAttributesMap(shibbolethKeysValues);
ReflectionTestUtils.setField(sut, "shibbolethModule", shibbolethModuleMock); ReflectionTestUtils.setField(sut, "shibbolethModule", shibbolethModuleMock);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment