private static boolean isSecurityAuthenticationConstant(ExpressionTree tree) { if (tree.is(Kind.MEMBER_SELECT)) { MemberSelectExpressionTree constantExpression = (MemberSelectExpressionTree) tree; return "javax.naming.Context".equals(constantExpression.expression().symbolType().fullyQualifiedName()) && "SECURITY_AUTHENTICATION".equals(constantExpression.identifier().name()); } return LiteralUtils.hasValue(tree, "java.naming.security.authentication"); } }
private static boolean isSecurityAuthenticationConstant(ExpressionTree tree) { if (tree.is(Kind.MEMBER_SELECT)) { MemberSelectExpressionTree constantExpression = (MemberSelectExpressionTree) tree; return "javax.naming.Context".equals(constantExpression.expression().symbolType().fullyQualifiedName()) && "SECURITY_AUTHENTICATION".equals(constantExpression.identifier().name()); } return LiteralUtils.hasValue(tree, "java.naming.security.authentication"); } }
@Override protected void onMethodInvocationFound(MethodInvocationTree methodTree) { if (methodTree.arguments().size() != 2) { return; } ExpressionTree putKey = methodTree.arguments().get(0); ExpressionTree putValue = methodTree.arguments().get(1); ExpressionTree defaultPropertyValue = JavaPropertiesHelper.retrievedPropertyDefaultValue(putValue); ExpressionTree mechanismTree = defaultPropertyValue == null ? putValue : defaultPropertyValue; if (isSecurityAuthenticationConstant(putKey) && LiteralUtils.hasValue(mechanismTree, "none")) { reportIssue(putValue, "Change authentication to \"simple\" or stronger."); } }
@Override protected void onMethodInvocationFound(MethodInvocationTree methodTree) { if (methodTree.arguments().size() != 2) { return; } ExpressionTree putKey = methodTree.arguments().get(0); ExpressionTree putValue = methodTree.arguments().get(1); ExpressionTree defaultPropertyValue = JavaPropertiesHelper.retrievedPropertyDefaultValue(putValue); ExpressionTree mechanismTree = defaultPropertyValue == null ? putValue : defaultPropertyValue; if (isSecurityAuthenticationConstant(putKey) && LiteralUtils.hasValue(mechanismTree, "none")) { reportIssue(putValue, "Change authentication to \"simple\" or stronger."); } }