Skip to content

Commit

Permalink
cleanup: be consistent in usage of final modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
theborakompanioni committed Aug 11, 2021
1 parent 36c60a0 commit 7d2bd4f
Show file tree
Hide file tree
Showing 21 changed files with 74 additions and 79 deletions.
52 changes: 26 additions & 26 deletions src/main/java/at/pollux/thymeleaf/shiro/processor/ShiroFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ public static boolean isGuest() {
return !ShiroFacade.isUser();
}

public static boolean hasPermission(final String permission) {
public static boolean hasPermission(String permission) {
return hasAllPermissions(singleton(permission));
}

public static boolean lacksPermission(final String permission) {
public static boolean lacksPermission(String permission) {
return !ShiroFacade.hasPermission(permission);
}

public static boolean hasAnyPermissions(final Collection<String> permissions) {
public static boolean hasAnyPermissions(Collection<String> permissions) {
if (SecurityUtils.getSubject() != null) {
final Subject subject = SecurityUtils.getSubject();
for (final String permission : permissions) {
Subject subject = SecurityUtils.getSubject();
for (String permission : permissions) {
if (subject.isPermitted(permission)) {
return true;
}
Expand All @@ -54,7 +54,7 @@ public static boolean hasAnyPermissions(final Collection<String> permissions) {
return false;
}

public static boolean hasAnyPermissions(final String... permissions) {
public static boolean hasAnyPermissions(String... permissions) {
return hasAnyPermissions(Arrays.asList(permissions));
}

Expand All @@ -65,7 +65,7 @@ public static boolean hasAllPermissions(Collection<String> permissions) {
return false;
}

final Subject subject = SecurityUtils.getSubject();
Subject subject = SecurityUtils.getSubject();
for (final String permission : permissions) {
if (!subject.isPermitted(permission)) {
return false;
Expand All @@ -80,18 +80,18 @@ public static boolean hasAllPermissions(String... permissions) {
return hasAllPermissions(Arrays.asList(permissions));
}

public static boolean hasRole(final String roleName) {
public static boolean hasRole(String roleName) {
return hasAllRoles(singleton(roleName));
}

public static boolean lacksRole(final String roleName) {
public static boolean lacksRole(String roleName) {
return !hasRole(roleName);
}

public static boolean hasAnyRoles(final Collection<String> roles) {
public static boolean hasAnyRoles(Collection<String> roles) {
if (SecurityUtils.getSubject() != null) {
final Subject subject = SecurityUtils.getSubject();
for (final String role : roles) {
Subject subject = SecurityUtils.getSubject();
for (String role : roles) {
if (subject.hasRole(StringUtils.trim(role))) {
return true;
}
Expand All @@ -100,18 +100,18 @@ public static boolean hasAnyRoles(final Collection<String> roles) {
return false;
}

public static boolean hasAnyRoles(final String... roles) {
public static boolean hasAnyRoles(String... roles) {
return hasAnyRoles(Arrays.asList(roles));
}

public static boolean hasAllRoles(final Collection<String> roles) {
public static boolean hasAllRoles(Collection<String> roles) {
if (SecurityUtils.getSubject() != null) {
if (roles.isEmpty()) {
return false;
}

final Subject subject = SecurityUtils.getSubject();
for (final String role : roles) {
Subject subject = SecurityUtils.getSubject();
for (String role : roles) {
if (!subject.hasRole(StringUtils.trim(role))) {
return false;
}
Expand All @@ -121,11 +121,11 @@ public static boolean hasAllRoles(final Collection<String> roles) {
return false;
}

public static boolean hasAllRoles(final String... roles) {
public static boolean hasAllRoles(String... roles) {
return hasAllRoles(Arrays.asList(roles));
}

public static String getPrincipalText(final String type, final String property) {
public static String getPrincipalText(String type, String property) {
if (SecurityUtils.getSubject() == null) {
return "";
}
Expand All @@ -144,30 +144,30 @@ public static String getPrincipalText(final String type, final String property)
return principal != null ? principal.toString() : "";
}

public static Object getPrincipalFromClassName(final String type) {
public static Object getPrincipalFromClassName(String type) {
Object principal;

try {
final Class<?> cls = Class.forName(type);
Class<?> cls = Class.forName(type);
principal = SecurityUtils.getSubject().getPrincipals().oneByType(cls);
} catch (final ClassNotFoundException e) {
} catch (ClassNotFoundException e) {
String message = "Unable to find class for name [" + type + "]";
throw new IllegalArgumentException(message, e);
}

return principal;
}

public static String getPrincipalProperty(final Object principal, final String property) {
public static String getPrincipalProperty(Object principal, String property) {
try {
final BeanInfo bi = Introspector.getBeanInfo(principal.getClass());
for (final PropertyDescriptor pd : bi.getPropertyDescriptors()) {
BeanInfo bi = Introspector.getBeanInfo(principal.getClass());
for (PropertyDescriptor pd : bi.getPropertyDescriptors()) {
if (pd.getName().equals(property)) {
final Object value = pd.getReadMethod().invoke(principal, (Object[]) null);
Object value = pd.getReadMethod().invoke(principal, (Object[]) null);
return String.valueOf(value);
}
}
} catch (final Exception e) {
} catch (Exception e) {
String message = "Error reading property [" + property + "] from principal of type [" + principal.getClass().getName() + "]";
throw new IllegalArgumentException(message, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ private ThymeleafFacade() {
throw new UnsupportedOperationException();
}

public static String getRawValue(final IProcessableElementTag element, final AttributeName attributeName) {
public static String getRawValue(IProcessableElementTag element, AttributeName attributeName) {
notNull(element, "element must not be null");
notNull(attributeName, "attributeName must not be empty");

final String rawValue = trim(element.getAttributeValue(attributeName));
String rawValue = trim(element.getAttributeValue(attributeName));
notEmpty(rawValue, "value of '" + attributeName + "' must not be empty");

return rawValue;
}

public static String getRawValue(final IProcessableElementTag element, final String attributeName) {
public static String getRawValue(IProcessableElementTag element, String attributeName) {
notNull(element, "element must not be null");
notEmpty(attributeName, "attributeName must not be empty");

final String rawValue = trim(element.getAttributeValue(attributeName));
String rawValue = trim(element.getAttributeValue(attributeName));
notEmpty(rawValue, "value of '" + attributeName + "' must not be empty");

return rawValue;
Expand All @@ -49,9 +49,8 @@ public static Object evaluateExpression(ITemplateContext arguments, String expre
notNull(arguments, "arguments must not be null");
notEmpty(expression, "expression must not be empty");

final IStandardExpressionParser parser = new StandardExpressionParser();

final IStandardExpression evaluableExpression = parser.parseExpression(arguments, expression);
IStandardExpressionParser parser = new StandardExpressionParser();
IStandardExpression evaluableExpression = parser.parseExpression(arguments, expression);

return evaluableExpression.execute(arguments);
}
Expand All @@ -60,7 +59,7 @@ public static List<Object> evaluateAsIterable(ITemplateContext arguments, String
notNull(arguments, "arguments must not be null");
notEmpty(rawValue, "rawValue must not be empty");

final Object evaluatedExpression = evaluateExpression(arguments, rawValue);
Object evaluatedExpression = evaluateExpression(arguments, rawValue);

return EvaluationUtils.evaluateAsList(evaluatedExpression);
}
Expand All @@ -69,7 +68,7 @@ public static List<Object> evaluateAsIterableOrRawValue(ITemplateContext argumen
notNull(arguments, "arguments must not be null");
notEmpty(rawValue, "rawValue must not be empty");

final List<Object> result = new ArrayList<Object>();
List<Object> result = new ArrayList<>();
try {
result.addAll(evaluateAsIterable(arguments, rawValue));
} catch (TemplateProcessingException ex) {
Expand All @@ -84,8 +83,8 @@ public static List<String> evaluateAsStringsWithDelimiter(ITemplateContext argum
notEmpty(rawValue, "rawValue must not be empty");
notEmpty(delimiter, "delimiter must not be empty");

final List<String> result = new ArrayList<String>();
final List<Object> iterates = evaluateAsIterableOrRawValue(arguments, rawValue);
List<String> result = new ArrayList<>();
List<Object> iterates = evaluateAsIterableOrRawValue(arguments, rawValue);

for (Object o : iterates) {
result.addAll(asList(StringUtils.split(o, delimiter)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.thymeleaf.templatemode.TemplateMode;

public class GuestAttrProcessor extends AbstractAttributeTagProcessor {

private static final String ATTRIBUTE_NAME = "guest";
private static final int PRECEDENCE = 300;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ protected void doProcess(ITemplateContext iTemplateContext,
AttributeName attributeName,
String attributeValue,
IElementTagStructureHandler iElementTagStructureHandler) {
final String rawValue = getRawValue(iProcessableElementTag, attributeName);
final List<String> values = evaluateAsStringsWithDelimiter(iTemplateContext, rawValue, DELIMITER);
String rawValue = getRawValue(iProcessableElementTag, attributeName);
List<String> values = evaluateAsStringsWithDelimiter(iTemplateContext, rawValue, DELIMITER);

if (ShiroFacade.hasAllPermissions(values)) {
iElementTagStructureHandler.removeAttribute(attributeName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ protected void doProcess(ITemplateContext iTemplateContext,
AttributeName attributeName,
String attributeValue,
IElementTagStructureHandler iElementTagStructureHandler) {
final String rawValue = getRawValue(iProcessableElementTag, attributeName);
final List<String> values = evaluateAsStringsWithDelimiter(iTemplateContext, rawValue, DELIMITER);
String rawValue = getRawValue(iProcessableElementTag, attributeName);
List<String> values = evaluateAsStringsWithDelimiter(iTemplateContext, rawValue, DELIMITER);

if (ShiroFacade.hasAllRoles(values)) {
iElementTagStructureHandler.removeAttribute(attributeName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ protected void doProcess(ITemplateContext iTemplateContext,
AttributeName attributeName,
String attributeValue,
IElementTagStructureHandler iElementTagStructureHandler) {
final String rawValue = getRawValue(iProcessableElementTag, attributeName);
final List<String> values = evaluateAsStringsWithDelimiter(iTemplateContext, rawValue, DELIMITER);
String rawValue = getRawValue(iProcessableElementTag, attributeName);
List<String> values = evaluateAsStringsWithDelimiter(iTemplateContext, rawValue, DELIMITER);

if (ShiroFacade.hasAnyPermissions(values)) {
iElementTagStructureHandler.removeAttribute(attributeName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
import static at.pollux.thymeleaf.shiro.processor.ThymeleafFacade.getRawValue;

public class HasAnyRolesAttrProcessor extends AbstractAttributeTagProcessor {


private static final String DELIMITER = ",";

private static final String ATTRIBUTE_NAME = "hasAnyRoles";
Expand All @@ -39,8 +37,8 @@ protected void doProcess(ITemplateContext iTemplateContext,
AttributeName attributeName,
String attributeValue,
IElementTagStructureHandler iElementTagStructureHandler) {
final String rawValue = getRawValue(iProcessableElementTag, attributeName);
final List<String> values = evaluateAsStringsWithDelimiter(iTemplateContext, rawValue, DELIMITER);
String rawValue = getRawValue(iProcessableElementTag, attributeName);
List<String> values = evaluateAsStringsWithDelimiter(iTemplateContext, rawValue, DELIMITER);

if (ShiroFacade.hasAnyRoles(values)) {
iElementTagStructureHandler.removeAttribute(attributeName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ protected void doProcess(ITemplateContext iTemplateContext,
AttributeName attributeName,
String attributeValue,
IElementTagStructureHandler iElementTagStructureHandler) {
final String rawValue = getRawValue(iProcessableElementTag, attributeName);
final List<String> values = evaluateAsStringsWithDelimiter(iTemplateContext, rawValue, DELIMITER);
String rawValue = getRawValue(iProcessableElementTag, attributeName);
List<String> values = evaluateAsStringsWithDelimiter(iTemplateContext, rawValue, DELIMITER);

if (ShiroFacade.hasAllPermissions(values)) {
iElementTagStructureHandler.removeAttribute(attributeName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ protected void doProcess(ITemplateContext iTemplateContext,
AttributeName attributeName,
String attributeValue,
IElementTagStructureHandler iElementTagStructureHandler) {
final String rawValue = getRawValue(iProcessableElementTag, attributeName);
final List<String> values = evaluateAsStringsWithDelimiter(iTemplateContext, rawValue, DELIMITER);
String rawValue = getRawValue(iProcessableElementTag, attributeName);
List<String> values = evaluateAsStringsWithDelimiter(iTemplateContext, rawValue, DELIMITER);

if (ShiroFacade.hasAllRoles(values)) {
iElementTagStructureHandler.removeAttribute(attributeName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ protected void doProcess(ITemplateContext iTemplateContext,
AttributeName attributeName,
String attributeValue,
IElementTagStructureHandler iElementTagStructureHandler) {
final String rawValue = getRawValue(iProcessableElementTag, attributeName);
final List<String> values = evaluateAsStringsWithDelimiter(iTemplateContext, rawValue, DELIMITER);
String rawValue = getRawValue(iProcessableElementTag, attributeName);
List<String> values = evaluateAsStringsWithDelimiter(iTemplateContext, rawValue, DELIMITER);

if (!ShiroFacade.hasAnyPermissions(values)) {
iElementTagStructureHandler.removeAttribute(attributeName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ protected void doProcess(ITemplateContext iTemplateContext,
AttributeName attributeName,
String attributeValue,
IElementTagStructureHandler iElementTagStructureHandler) {
final String rawValue = getRawValue(iProcessableElementTag, attributeName);
final List<String> values = evaluateAsStringsWithDelimiter(iTemplateContext, rawValue, DELIMITER);
String rawValue = getRawValue(iProcessableElementTag, attributeName);
List<String> values = evaluateAsStringsWithDelimiter(iTemplateContext, rawValue, DELIMITER);
if (!ShiroFacade.hasAnyRoles(values)) {
iElementTagStructureHandler.removeAttribute(attributeName);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ protected void doProcess(ITemplateContext iTemplateContext,
String attributeValue,
IElementTagStructureHandler iElementTagStructureHandler) {

final String type = iProcessableElementTag.getAttributeValue("type");
final String property = iProcessableElementTag.getAttributeValue("property");
String type = iProcessableElementTag.getAttributeValue("type");
String property = iProcessableElementTag.getAttributeValue("property");

final String text = ShiroFacade.getPrincipalText(type, property);
final String elementCompleteName = iProcessableElementTag.getElementCompleteName();
String text = ShiroFacade.getPrincipalText(type, property);
String elementCompleteName = iProcessableElementTag.getElementCompleteName();

final IModelFactory modelFactory = iTemplateContext.getModelFactory();
final IModel model = modelFactory.createModel();
IModelFactory modelFactory = iTemplateContext.getModelFactory();
IModel model = modelFactory.createModel();

model.add(modelFactory.createOpenElementTag(elementCompleteName));
model.add(modelFactory.createText(HtmlEscape.escapeHtml5(text)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public HasAllPermissionsElementProcessor(String dialectPrefix) {
protected void doProcess(ITemplateContext iTemplateContext,
IProcessableElementTag iProcessableElementTag,
IElementTagStructureHandler iElementTagStructureHandler) {
final String rawValue = getRawValue(iProcessableElementTag, "name");
final List<String> values = evaluateAsStringsWithDelimiter(iTemplateContext, rawValue, DELIMITER);
String rawValue = getRawValue(iProcessableElementTag, "name");
List<String> values = evaluateAsStringsWithDelimiter(iTemplateContext, rawValue, DELIMITER);

if (ShiroFacade.hasAllPermissions(values)) {
iElementTagStructureHandler.removeTags();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public HasAllRolesElementProcessor(String dialectPrefix) {
protected void doProcess(ITemplateContext iTemplateContext,
IProcessableElementTag iProcessableElementTag,
IElementTagStructureHandler iElementTagStructureHandler) {
final String rawValue = getRawValue(iProcessableElementTag, "name");
final List<String> values = evaluateAsStringsWithDelimiter(iTemplateContext, rawValue, DELIMITER);
String rawValue = getRawValue(iProcessableElementTag, "name");
List<String> values = evaluateAsStringsWithDelimiter(iTemplateContext, rawValue, DELIMITER);

if (ShiroFacade.hasAllRoles(values)) {
iElementTagStructureHandler.removeTags();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public HasAnyPermissionsElementProcessor(String dialectPrefix) {
protected void doProcess(ITemplateContext iTemplateContext,
IProcessableElementTag iProcessableElementTag,
IElementTagStructureHandler iElementTagStructureHandler) {
final String rawValue = getRawValue(iProcessableElementTag, "name");
final List<String> values = evaluateAsStringsWithDelimiter(iTemplateContext, rawValue, DELIMITER);
String rawValue = getRawValue(iProcessableElementTag, "name");
List<String> values = evaluateAsStringsWithDelimiter(iTemplateContext, rawValue, DELIMITER);

if (ShiroFacade.hasAnyPermissions(values)) {
iElementTagStructureHandler.removeTags();
Expand Down
Loading

0 comments on commit 7d2bd4f

Please sign in to comment.