This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static boolean warnedAboutDevMode = false; | |
@Override | |
protected void outputDevelopmentModeWarning() { | |
if (warnedAboutDevMode) { | |
return; | |
} | |
super.outputDevelopmentModeWarning(); | |
warnedAboutDevMode = true; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
${e:import(org.apache.commons.lang3.builder.EqualsBuilder)} | |
${h:import(org.apache.commons.lang3.builder.HashCodeBuilder)} | |
@Override | |
public boolean equals(Object object) { | |
if (object instanceof ${enclosing_type}) { | |
${enclosing_type} another = (${enclosing_type}) object; | |
return new EqualsBuilder().append(${replaceWithFieldName}, another.${replaceWithFieldName}).isEquals(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Person per = new Person("Per", new Address("A-gate 5", "0560", "Oslo"), 30); | |
private Person kari = new Person("Kari", new Address("B-gate 4", "0560", "Oslo"), 37); | |
@Test | |
public void knowsWhichRelativesLivingInTheSamePostalCode() { | |
per.relateTo(SIBLING, kari); | |
Collection<Relative> nearbyRelatives = per.getRelativesWithSamePostalCode(); | |
assertThat(nearbyRelatives, hasSize(1)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SecurityLevelVoter implements AccessDecisionVoter { | |
private String securityLevelPrefix = "SECURITY_LEVEL_"; | |
public int vote(Authentication authentication, | |
Object object, | |
Collection<ConfigAttribute> attributes) { | |
int result = ACCESS_ABSTAIN; | |
Object principal = authentication.getPrincipal(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SupportedBy implements Predicate<ConfigAttribute> { | |
private final AccessDecisionVoter voter; | |
public SupportedBy(AccessDecisionVoter voter) { | |
this.voter = voter; | |
} | |
public boolean evaluate(ConfigAttribute attribute) { | |
return voter.supports(attribute); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Collection<ConfigAttribute> supportedAttributes = select(attributes, new SupportedBy(this)); | |
if (supportedAttributes.isEmpty()) { | |
return ACCESS_ABSTAIN; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SecurityLevelVoter implements AccessDecisionVoter { | |
private String securityLevelPrefix = "SECURITY_LEVEL_"; | |
//...snip... | |
private class AcceptingSecurityLevelOf implements Predicate<ConfigAttribute> { | |
private final int principalSecurityLevel; | |
public AcceptingSecurityLevelOf(MyPrincipal principal) { | |
principalSecurityLevel = toInt(principal.getSecurityLevel(), Integer.MIN_VALUE); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Object p = authentication.getPrincipal(); | |
if (p instanceof MyPrincipal | |
&& exists(supportedAttributes, new AcceptingSecurityLevelOf((MyPrincipal) p))) { | |
return ACCESS_GRANTED; | |
} else { | |
return ACCESS_DENIED; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public int vote(Authentication authentication, | |
Object object, | |
Collection<ConfigAttribute> attributes) { | |
Collection<ConfigAttribute> supportedAttributes = | |
select(attributes, new SupportedBy(this)); | |
if (supportedAttributes.isEmpty()) { | |
return ACCESS_ABSTAIN; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Collection<ConfigAttribute> supportedAttributes = | |
select(attributes, attr -> this.supports(attr)); | |
if (supportedAttributes.isEmpty()) { | |
return ACCESS_ABSTAIN; | |
} |
OlderNewer