Skip to content

Commit

Permalink
reorg components to fix circular dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoayyed committed May 20, 2020
1 parent 02f89c8 commit 7c4302b
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
@FunctionalInterface
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS)
public interface PrincipalAttributesRepository extends Serializable {
public interface RegisteredServicePrincipalAttributesRepository extends Serializable {

/**
* Gets attributes for the given principal id.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.apereo.cas.services;

import org.apereo.cas.authentication.principal.Principal;
import org.apereo.cas.authentication.principal.PrincipalAttributesRepository;
import org.apereo.cas.authentication.principal.RegisteredServicePrincipalAttributesRepository;
import org.apereo.cas.authentication.principal.Service;

import com.fasterxml.jackson.annotation.JsonIgnore;
Expand Down Expand Up @@ -73,7 +73,7 @@ default RegisteredServiceConsentPolicy getConsentPolicy() {
*
* @return the principal attribute repository
*/
default PrincipalAttributesRepository getPrincipalAttributesRepository() {
default RegisteredServicePrincipalAttributesRepository getPrincipalAttributesRepository() {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class DefaultAttributeDefinitionStoreTests {

@Test
public void verifyAttrDefnNotFound() {
val service = CoreAuthenticationTestUtils.getRegisteredService();
val store = new DefaultAttributeDefinitionStore();
store.setScope("example.org");
val defn = DefaultAttributeDefinition.builder()
Expand All @@ -41,12 +42,13 @@ public void verifyAttrDefnNotFound() {
.build();
store.registerAttributeDefinition(defn);
var values = (Optional<Pair<AttributeDefinition, List<Object>>>) store.resolveAttributeValues("whatever",
CollectionUtils.wrap(CoreAuthenticationTestUtils.CONST_USERNAME));
CollectionUtils.wrap(CoreAuthenticationTestUtils.CONST_USERNAME), service);
assertTrue(values.isEmpty());
}

@Test
public void verifyAttributeDefinitionsAsMap() {
val service = CoreAuthenticationTestUtils.getRegisteredService();
val store = new DefaultAttributeDefinitionStore();
store.setScope("example.org");
val defn = DefaultAttributeDefinition.builder()
Expand All @@ -56,7 +58,7 @@ public void verifyAttributeDefinitionsAsMap() {
.build();
store.registerAttributeDefinition(defn);
assertFalse(store.isEmpty());
val attrs = store.resolveAttributeValues(CoreAuthenticationTestUtils.getAttributes());
val attrs = store.resolveAttributeValues(CoreAuthenticationTestUtils.getAttributes(), service);
assertFalse(attrs.isEmpty());
assertTrue(attrs.containsKey("mail"));
assertTrue(attrs.containsKey(defn.getName()));
Expand All @@ -66,6 +68,7 @@ public void verifyAttributeDefinitionsAsMap() {

@Test
public void verifyScopedAttrDefn() {
val service = CoreAuthenticationTestUtils.getRegisteredService();
val store = new DefaultAttributeDefinitionStore();
store.setScope("example.org");
val defn = DefaultAttributeDefinition.builder()
Expand All @@ -74,13 +77,15 @@ public void verifyScopedAttrDefn() {
.scoped(true)
.build();
store.registerAttributeDefinition(defn);
var values = store.resolveAttributeValues("eduPersonPrincipalName", CollectionUtils.wrap(CoreAuthenticationTestUtils.CONST_USERNAME));
var values = store.resolveAttributeValues("eduPersonPrincipalName",
CollectionUtils.wrap(CoreAuthenticationTestUtils.CONST_USERNAME), service);
assertTrue(values.isPresent());
assertTrue(values.get().getValue().contains("[email protected]"));
}

@Test
public void verifyScriptedEmbeddedAttrDefn() {
val service = CoreAuthenticationTestUtils.getRegisteredService();
val store = new DefaultAttributeDefinitionStore();
store.setScope("example.org");
val defn = DefaultAttributeDefinition.builder()
Expand All @@ -91,14 +96,15 @@ public void verifyScriptedEmbeddedAttrDefn() {
.build();
store.registerAttributeDefinition(defn);
var values = store.resolveAttributeValues("eduPersonPrincipalName",
CollectionUtils.wrap(CoreAuthenticationTestUtils.CONST_USERNAME));
CollectionUtils.wrap(CoreAuthenticationTestUtils.CONST_USERNAME), service);
assertTrue(values.isPresent());
assertTrue(values.get().getValue().contains("[email protected]"));
assertTrue(values.get().getValue().contains("[email protected]"));
}

@Test
public void verifyScriptedExternalAttrDefn() {
val service = CoreAuthenticationTestUtils.getRegisteredService();
val store = new DefaultAttributeDefinitionStore();
store.setScope("system.org");
val defn = DefaultAttributeDefinition.builder()
Expand All @@ -109,14 +115,15 @@ public void verifyScriptedExternalAttrDefn() {
.build();
store.registerAttributeDefinition(defn);
var values = store.resolveAttributeValues("eduPersonPrincipalName",
CollectionUtils.wrap(CoreAuthenticationTestUtils.CONST_USERNAME));
CollectionUtils.wrap(CoreAuthenticationTestUtils.CONST_USERNAME), service);
assertTrue(values.isPresent());
assertTrue(values.get().getValue().contains("[email protected]"));
assertTrue(values.get().getValue().contains("[email protected]"));
}

@Test
public void verifyFormattedAttrDefn() {
val service = CoreAuthenticationTestUtils.getRegisteredService();
val store = new DefaultAttributeDefinitionStore();
store.setScope("example.org");
val defn = DefaultAttributeDefinition.builder()
Expand All @@ -127,7 +134,7 @@ public void verifyFormattedAttrDefn() {
.build();
store.registerAttributeDefinition(defn);
var values = store.resolveAttributeValues("eduPersonPrincipalName",
CollectionUtils.wrap(CoreAuthenticationTestUtils.CONST_USERNAME));
CollectionUtils.wrap(CoreAuthenticationTestUtils.CONST_USERNAME), service);
assertTrue(values.isPresent());
assertTrue(values.get().getValue().contains("hello,[email protected]"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ dependencies {
implementation libraries.bouncycastle

api project(":api:cas-server-core-api-services")
api project(":api:cas-server-core-api-authentication")
api project(":api:cas-server-core-api-ticket")
api project(":api:cas-server-core-api-events")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.apereo.cas.authentication.principal.cache.AbstractPrincipalAttributesRepository;
import org.apereo.cas.services.RegisteredService;
import org.apereo.cas.services.RegisteredServicePrincipalAttributesRepository;

import lombok.EqualsAndHashCode;
import lombok.ToString;
Expand All @@ -26,12 +25,6 @@ public class DefaultPrincipalAttributesRepository extends AbstractPrincipalAttri

private static final long serialVersionUID = -4535358847021241725L;

@Override
protected void addPrincipalAttributes(final String id, final Map<String, List<Object>> attributes,
final RegisteredService registeredService) {
LOGGER.debug("Using [{}], no caching takes place for [{}] to add attributes.", id, this.getClass().getSimpleName());
}

@Override
public Map<String, List<Object>> getAttributes(final Principal principal, final RegisteredService registeredService) {
val mergeStrategy = determineMergingStrategy();
Expand All @@ -46,4 +39,10 @@ public Map<String, List<Object>> getAttributes(final Principal principal, final
}
return convertAttributesToPrincipalAttributesAndCache(principal, principalAttributes, registeredService);
}

@Override
protected void addPrincipalAttributes(final String id, final Map<String, List<Object>> attributes,
final RegisteredService registeredService) {
LOGGER.debug("Using [{}], no caching takes place for [{}] to add attributes.", id, this.getClass().getSimpleName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.apereo.cas.authentication.AttributeMergingStrategy;
import org.apereo.cas.authentication.attribute.PrincipalAttributeRepositoryFetcher;
import org.apereo.cas.authentication.principal.Principal;
import org.apereo.cas.services.RegisteredServicePrincipalAttributesRepository;
import org.apereo.cas.authentication.principal.RegisteredServicePrincipalAttributesRepository;
import org.apereo.cas.services.RegisteredService;
import org.apereo.cas.util.CollectionUtils;
import org.apereo.cas.util.spring.ApplicationContextProvider;
Expand All @@ -20,7 +20,6 @@
import org.apereo.services.persondir.IPersonAttributeDao;

import javax.persistence.Transient;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
Expand Down Expand Up @@ -68,6 +67,13 @@ public abstract class AbstractPrincipalAttributesRepository implements Registere
@Setter
private boolean ignoreResolvedAttributes;

@Override
public abstract Map<String, List<Object>> getAttributes(Principal principal, RegisteredService registeredService);

@Override
public void close() {
}

/**
* Gets attribute repository.
*
Expand Down Expand Up @@ -111,9 +117,6 @@ protected static Map<String, List<Object>> convertPersonAttributesToPrincipalAtt
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}

@Override
public abstract Map<String, List<Object>> getAttributes(Principal principal, RegisteredService registeredService);

/**
* Convert attributes to principal attributes and cache.
*
Expand Down Expand Up @@ -197,8 +200,4 @@ protected Map<String, List<Object>> getPrincipalAttributes(final Principal princ
}
return convertPrincipalAttributesToPersonAttributes(principal.getAttributes());
}

@Override
public void close() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.apereo.cas.authentication.attribute.AttributeDefinitionStore;
import org.apereo.cas.authentication.principal.DefaultPrincipalAttributesRepository;
import org.apereo.cas.authentication.principal.Principal;
import org.apereo.cas.authentication.principal.RegisteredServicePrincipalAttributesRepository;
import org.apereo.cas.authentication.principal.Service;
import org.apereo.cas.configuration.CasConfigurationProperties;
import org.apereo.cas.services.consent.DefaultRegisteredServiceConsentPolicy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
import org.apereo.cas.authentication.principal.DefaultPrincipalAttributesRepository;
import org.apereo.cas.authentication.principal.DefaultPrincipalElectionStrategy;
import org.apereo.cas.authentication.principal.DefaultPrincipalResolutionExecutionPlan;
import org.apereo.cas.services.RegisteredServicePrincipalAttributesRepository;
import org.apereo.cas.authentication.principal.PrincipalElectionStrategyConfigurer;
import org.apereo.cas.authentication.principal.PrincipalFactory;
import org.apereo.cas.authentication.principal.PrincipalFactoryUtils;
import org.apereo.cas.authentication.principal.PrincipalResolutionExecutionPlanConfigurer;
import org.apereo.cas.authentication.principal.PrincipalResolver;
import org.apereo.cas.authentication.principal.RegisteredServicePrincipalAttributesRepository;
import org.apereo.cas.authentication.principal.cache.CachingPrincipalAttributesRepository;
import org.apereo.cas.authentication.principal.resolvers.ChainingPrincipalResolver;
import org.apereo.cas.authentication.principal.resolvers.EchoingPrincipalResolver;
Expand Down Expand Up @@ -60,7 +60,7 @@ public class CasCoreAuthenticationPrincipalConfiguration {
@RefreshScope
@Autowired
public PrincipalElectionStrategy principalElectionStrategy(final List<PrincipalElectionStrategyConfigurer> configurers) {
LOGGER.trace("building principal election strategies from [{}]", configurers);
LOGGER.trace("Building principal election strategies from [{}]", configurers);
val chain = new ChainingPrincipalElectionStrategy();
AnnotationAwareOrderComparator.sortIfNecessary(configurers);

Expand Down Expand Up @@ -112,8 +112,7 @@ public PrincipalResolver personDirectoryAttributeRepositoryPrincipalResolver() {
@RefreshScope
@Autowired
public PrincipalResolver defaultPrincipalResolver(final List<PrincipalResolutionExecutionPlanConfigurer> configurers,
@Qualifier("principalElectionStrategy")
final PrincipalElectionStrategy principalElectionStrategy) {
@Qualifier("principalElectionStrategy") final PrincipalElectionStrategy principalElectionStrategy) {
val plan = new DefaultPrincipalResolutionExecutionPlan();
val sortedConfigurers = new ArrayList<PrincipalResolutionExecutionPlanConfigurer>(configurers);
AnnotationAwareOrderComparator.sortIfNecessary(sortedConfigurers);
Expand All @@ -132,6 +131,7 @@ public PrincipalResolver defaultPrincipalResolver(final List<PrincipalResolution

@ConditionalOnMissingBean(name = "casCorePrincipalResolutionExecutionPlanConfigurer")
@Bean
@RefreshScope
public PrincipalResolutionExecutionPlanConfigurer casCorePrincipalResolutionExecutionPlanConfigurer() {
return plan -> {
if (attributeRepositories.getObject().isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import org.apereo.cas.authentication.AttributeMergingStrategy;
import org.apereo.cas.authentication.CoreAuthenticationTestUtils;
import org.apereo.cas.authentication.principal.Principal;
import org.apereo.cas.services.RegisteredServicePrincipalAttributesRepository;
import org.apereo.cas.authentication.principal.PrincipalFactory;
import org.apereo.cas.authentication.principal.PrincipalFactoryUtils;

Expand All @@ -29,7 +28,8 @@
import static org.mockito.Mockito.*;

/**
* Parent class for test cases around {@link RegisteredServicePrincipalAttributesRepository}.
* Parent class for test cases around
* {@link org.apereo.cas.authentication.principal.RegisteredServicePrincipalAttributesRepository}.
*
* @author Misagh Moayyed
* @since 4.2
Expand Down Expand Up @@ -71,8 +71,6 @@ public void initialize() {
this.principal = this.principalFactory.createPrincipal("uid", Collections.singletonMap(MAIL, email));
}

protected abstract AbstractPrincipalAttributesRepository getPrincipalAttributesRepository(String unit, long duration);

@Test
@SneakyThrows
public void checkExpiredCachedAttributes() {
Expand Down Expand Up @@ -142,4 +140,6 @@ public void verifyMergingStrategyWithMultivaluedAttributeMerger() {
assertTrue(mailAttr.contains("[email protected]"));
}
}

protected abstract AbstractPrincipalAttributesRepository getPrincipalAttributesRepository(String unit, long duration);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.apereo.cas.TestOneTimePasswordAuthenticationHandler;
import org.apereo.cas.authentication.AcceptUsersAuthenticationHandler;
import org.apereo.cas.services.RegisteredServicePrincipalAttributesRepository;
import org.apereo.cas.authentication.principal.RegisteredServicePrincipalAttributesRepository;
import org.apereo.cas.authentication.principal.cache.CachingPrincipalAttributesRepository;
import org.apereo.cas.services.AnonymousRegisteredServiceUsernameAttributeProvider;
import org.apereo.cas.services.DefaultRegisteredServiceAccessStrategy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import net.sf.ehcache.distribution.RMISynchronousCacheReplicator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint;
import org.springframework.boot.actuate.cache.CachesEndpoint;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
Expand Down

0 comments on commit 7c4302b

Please sign in to comment.