A PHP Error was encountered
Severity: 8192
Message: Function create_function() is deprecated
Filename: geshi/geshi.php
Line Number: 4698
Backtrace:
File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/geshi/geshi.php
Line: 4698
Function: _error_handler
File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/geshi/geshi.php
Line: 4621
Function: _optimize_regexp_list_tokens_to_string
File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/geshi/geshi.php
Line: 1655
Function: optimize_regexp_list
File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/geshi/geshi.php
Line: 2029
Function: optimize_keyword_group
File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/geshi/geshi.php
Line: 2168
Function: build_parse_cache
File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/Process.php
Line: 45
Function: parse_code
File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/models/Pastes.php
Line: 517
Function: syntax
File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/controllers/Main.php
Line: 624
Function: getPaste
File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/system/core/Exceptions.php:271)
Filename: view/download.php
Line Number: 2
Backtrace:
File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/themes/geocities/views/view/download.php
Line: 2
Function: header
File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/core/MY_Loader.php
Line: 173
Function: include
File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/core/MY_Loader.php
Line: 43
Function: _ci_load
File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/controllers/Main.php
Line: 625
Function: view
File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/system/core/Exceptions.php:271)
Filename: view/download.php
Line Number: 3
Backtrace:
File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/themes/geocities/views/view/download.php
Line: 3
Function: header
File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/core/MY_Loader.php
Line: 173
Function: include
File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/core/MY_Loader.php
Line: 43
Function: _ci_load
File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/controllers/Main.php
Line: 625
Function: view
File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/index.php
Line: 315
Function: require_once
/*
* Copyright 2019, Pearson Education, Learning Technology Group
*
* PlatformAuthenticationResponseService.java
*/
package com.pearson.ltg.rbs.ltitoolgateway.service.openidconnect;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.PostConstruct;
import org.apache.commons.collections.CollectionUtils;
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.stereotype.Service;
import com.pearson.ltg.rbs.ltitoolgateway.constant.Constants;
import com.pearson.ltg.rbs.ltitoolgateway.exception.InvalidDataException;
import com.pearson.ltg.rbs.ltitoolgateway.jwt.JwtHelper;
import com.pearson.ltg.rbs.ltitoolgateway.model.AuthenticationResponse;
import com.pearson.ltg.rbs.ltitoolgateway.model.IssuerResponse;
import com.pearson.ltg.rbs.ltitoolgateway.model.LTILaunchRequest;
import com.pearson.ltg.rbs.ltitoolgateway.model.LTILaunchRequestSettings;
import com.pearson.ltg.rbs.ltitoolgateway.model.PlatformConfiguration;
import com.pearson.ltg.rbs.ltitoolgateway.model.PublicKeyData;
import com.pearson.ltg.rbs.ltitoolgateway.model.RumbaRole;
import com.pearson.ltg.rbs.ltitoolgateway.service.IPlatformConfigurationService;
import com.pearson.ltg.rbs.ltitoolgateway.util.Encryption;
import com.pearson.ltg.samlutils.model.SamlResponseInputData;
import com.pearson.ltg.samlutils.service.ISamlResponseService;
import io.jsonwebtoken.Claims;
import reactor.core.publisher.Mono;
import reactor.util.function.Tuples;
@Service
public class PlatformAuthenticationResponseService implements IPlatformAuthenticationResponseService {
private static final Logger LOGGER = LoggerFactory.getLogger(PlatformAuthenticationResponseService.class);
@Value("${saml.issuerId}")
String issuerId;
@Value("${saml.rumbaSSOUrl}")
String rumbaSSOUrl;
@Value("${saml.externalIdp}")
String externalIdp;
@Value("${saml.nameIdentitifer}")
String nameIdentitifer;
@Value("${saml.nameQualifier}")
String nameQualifier;
@Value("${saml.certificatePath}")
String certificatePath;
@Value("${saml.privateKeyPkcs8Path}")
String privateKeyPkcs8Path;
@Autowired
JwtHelper jwtHelper;
@Autowired
Encryption encryption;
@Autowired
IAuthenticationService authenticationService;
@Autowired
IPlatformConfigurationService platformConfigurationService;
@Autowired
ILaunchRequestServiceLocator launchRequestServiceLocator;
@Autowired
ISamlResponseService samlResponseService;
@Value("${ims.roles.mapped.to.rumba.teacher}")
Set imsRolesMappedToRumbaTeacher;
@Value("${ims.roles.mapped.to.rumba.student}")
Set imsRolesMappedToRumbaStudent;
@PostConstruct
public void init() {
LOGGER.info("rolesMappedToRumbaTeacher {}", imsRolesMappedToRumbaTeacher);
LOGGER.info("rolesMappedToRumbaStudent {}", imsRolesMappedToRumbaStudent);
}
@Override
public Mono> handlePlatformAuthenticationResponse(AuthenticationResponse authenticationResponse) {
IssuerResponse issuerResponse= authenticationService.retrieveIssuerResponse(authenticationResponse.getState());
String jwtToken = authenticationResponse.getIdToken();
String issuerId = issuerResponse.getIssuerId();
return platformConfigurationService
.getByIssuerId(issuerId)
.flatMap(platformConfiguration -> getPublicKeyData(platformConfiguration)
.map(publicKeyData -> {
setPlatformConfigurationServicePublicKeyData(platformConfiguration, publicKeyData);
return Tuples.of(platformConfiguration, publicKeyData);
}))
.map(tuple -> jwtHelper.getClaimsFromJWTToken(jwtToken, tuple.getT2())
.map(claims -> {
RumbaRole rumbaRole = obtainRumbaRoleFromLTIRoles(claims);
String messageType = claims.get(Constants.CLAIM_PREFIX + "message_type", String.class);
LaunchRequestProviderType.getLaunchRequestProviderType(messageType)
.map(launchRequestProviderType -> launchRequestServiceLocator.getProvider(launchRequestProviderType)
.map(launchRequestService -> {
launchRequestService.validateLaunchRequest(claims);
launchRequestService.processRequest(claims)
.map(ltiLaunchRequest -> setLtiLaunchRequest(ltiLaunchRequest, tuple.getT1().getRumbaDistrictId(), rumbaRole));
}));
}))
.onErrorResume(InvalidDataException.class, exception -> Response.badRequest(exception.getMessage(), ResponseMediaType.JSON));
// if(Objects.nonNull(platformConfiguration)) {
// PublicKeyData publicKeyData = getPublicKeyData(platformConfiguration);
// Claims claims = jwtHelper.getClaimsFromJWTToken(jwtToken, publicKeyData);
// if (publicKeyData.getIsNewPublicKey()) {
// setPlatformConfigurationPublicKeyData(platformConfiguration, publicKeyData);
// platformConfigurationService.update(platformConfiguration, issuerId);
// LOGGER.debug("platform configuration has been updated issuerId {}, public key id {}", platformConfiguration.getIssuerId(), publicKeyData.getPublicKeyId());
// }
// String messageType = claims.get(Constants.CLAIM_PREFIX + "message_type", String.class);
// LaunchRequestProviderType launchRequestProviderType = LaunchRequestProviderType.getLaunchRequestProviderType(messageType);
// ILaunchRequestService> launchRequestService = launchRequestServiceLocator.getProvider(launchRequestProviderType);
// RumbaRole rumbaRole = obtainRumbaRoleFromLTIRoles(claims);
// launchRequestService.validateLaunchRequest(claims.getSubject(), rumbaRole);
// LTILaunchRequest ltiLaunchRequest = launchRequestService.processRequest(claims);
// ltiLaunchRequest.setIssuer(issuerId);
// ltiLaunchRequest.setOrganizationId(platformConfiguration.getRumbaDistrictId());
// ltiLaunchRequest.setRumbaRole(rumbaRole);
// return ltiLaunchRequest;
// }
// throw new InvalidDataException("platformConfiguration is null" + platformConfiguration);
}
@Override
public String getAutoSubmitForm(String redirectUrl, String rumbaUserId) {
SamlResponseInputData samlResponseInputData = new SamlResponseInputData();
samlResponseInputData.setIssuer(issuerId);
samlResponseInputData.setAuthTokenForSaml(rumbaUserId);
samlResponseInputData.setRumbaSSOUrl(rumbaSSOUrl);
samlResponseInputData.setExternalIdpUrl(externalIdp);
samlResponseInputData.setServiceUrl(redirectUrl);
samlResponseInputData.setTimeInSecondsTillValid(3000);
samlResponseInputData.setNameIdentifier(nameIdentitifer);
samlResponseInputData.setNameQualifier(nameQualifier);
samlResponseInputData.setCertificateFilePath(certificatePath);
samlResponseInputData.setPrivateKeyFilePath(privateKeyPkcs8Path);
LOGGER.info("Created auto submit form request {}", samlResponseInputData);
String autoSubmitForm = samlResponseService.getRumbaAutoSubmitForm(samlResponseInputData);
LOGGER.info("Created auto submit form {}", autoSubmitForm);
return autoSubmitForm;
}
@SuppressWarnings("unchecked")
private RumbaRole obtainRumbaRoleFromLTIRoles(Claims claims) {
List roles = (List) claims.get(Constants.CLAIM_PREFIX + "roles");
if (CollectionUtils.isNotEmpty(roles)) {
List studentRoles = roles
.stream()
.filter(imsRolesMappedToRumbaStudent::contains)
.collect(Collectors.toList());
if(CollectionUtils.isNotEmpty(studentRoles)) {
return RumbaRole.S;
}
List teacherRoles = roles
.stream()
.filter(imsRolesMappedToRumbaTeacher::contains)
.collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(teacherRoles)) {
return RumbaRole.T;
}
}
return null;
}
private Mono getPublicKeyData(PlatformConfiguration platformConfiguration) {
PublicKeyData publicKeyData = new PublicKeyData();
publicKeyData.setPublicKeyString(platformConfiguration.getPlatformPublicKey());
publicKeyData.setPublicKeyId(platformConfiguration.getPlatformPublicKeyId());
publicKeyData.setPublicKeySetUrl(platformConfiguration.getPlatformPublicKeySetUrl());
publicKeyData.setPublicKeyType(platformConfiguration.getPlatformPublicKeyType());
publicKeyData.setPublicKeyAlgorithm(platformConfiguration.getPlatformPublicKeyAlgorithm());
return Mono.just(publicKeyData);
}
private void setPlatformConfigurationPublicKeyData(PlatformConfiguration platformConfiguration, PublicKeyData publicKeyData) {
String platformPublicKey = encryption.keyToString(publicKeyData.getPublicKey());
platformConfiguration.setPlatformPublicKey(platformPublicKey);
platformConfiguration.setPlatformPublicKeyAlgorithm(publicKeyData.getPublicKeyAlgorithm());
platformConfiguration.setPlatformPublicKeyId(publicKeyData.getPublicKeyId());
platformConfiguration.setPlatformPublicKeyType(publicKeyData.getPublicKeyType());
}
private void setPlatformConfigurationServicePublicKeyData(PlatformConfiguration platformConfiguration, PublicKeyData publicKeyData) {
if (publicKeyData.getIsNewPublicKey()) {
setPlatformConfigurationPublicKeyData(platformConfiguration, publicKeyData);
platformConfigurationService.update(platformConfiguration, issuerId);
LOGGER.debug("platform configuration has been updated issuerId {}, public key id {}", platformConfiguration.getIssuerId(), publicKeyData.getPublicKeyId());
}
}
private Mono> setLtiLaunchRequest(LTILaunchRequest ltiLaunchRequest, String rumbaDistrictId, RumbaRole rumaRole) {
ltiLaunchRequest.setIssuer(issuerId);
ltiLaunchRequest.setOrganizationId(rumbaDistrictId);
ltiLaunchRequest.setRumbaRole(rumaRole);
return Mono.just(ltiLaunchRequest);
}
}