Search in sources :

Example 56 with ArrayList

use of java.util.ArrayList in project blade by biezhi.

the class ConstraintSecurityHandler method createConstraintsWithMappingsForPath.

/* ------------------------------------------------------------ */
/** 
     * Generate Constraints and ContraintMappings for the given url pattern and ServletSecurityElement
     * 
     * @param name the name
     * @param pathSpec the path spec
     * @param securityElement the servlet security element
     * @return the list of constraint mappings
     */
public static List<ConstraintMapping> createConstraintsWithMappingsForPath(String name, String pathSpec, ServletSecurityElement securityElement) {
    List<ConstraintMapping> mappings = new ArrayList<ConstraintMapping>();
    //Create a constraint that will describe the default case (ie if not overridden by specific HttpMethodConstraints)
    Constraint httpConstraint = null;
    ConstraintMapping httpConstraintMapping = null;
    if (securityElement.getEmptyRoleSemantic() != EmptyRoleSemantic.PERMIT || securityElement.getRolesAllowed().length != 0 || securityElement.getTransportGuarantee() != TransportGuarantee.NONE) {
        httpConstraint = ConstraintSecurityHandler.createConstraint(name, securityElement);
        //Create a mapping for the pathSpec for the default case
        httpConstraintMapping = new ConstraintMapping();
        httpConstraintMapping.setPathSpec(pathSpec);
        httpConstraintMapping.setConstraint(httpConstraint);
        mappings.add(httpConstraintMapping);
    }
    //See Spec 13.4.1.2 p127
    List<String> methodOmissions = new ArrayList<String>();
    //make constraint mappings for this url for each of the HttpMethodConstraintElements
    Collection<HttpMethodConstraintElement> methodConstraintElements = securityElement.getHttpMethodConstraints();
    if (methodConstraintElements != null) {
        for (HttpMethodConstraintElement methodConstraintElement : methodConstraintElements) {
            //Make a Constraint that captures the <auth-constraint> and <user-data-constraint> elements supplied for the HttpMethodConstraintElement
            Constraint methodConstraint = ConstraintSecurityHandler.createConstraint(name, methodConstraintElement);
            ConstraintMapping mapping = new ConstraintMapping();
            mapping.setConstraint(methodConstraint);
            mapping.setPathSpec(pathSpec);
            if (methodConstraintElement.getMethodName() != null) {
                mapping.setMethod(methodConstraintElement.getMethodName());
                //See spec 13.4.1.2 p127 - add an omission for every method name to the default constraint
                methodOmissions.add(methodConstraintElement.getMethodName());
            }
            mappings.add(mapping);
        }
    }
    //UNLESS the default constraint contains all default values. In that case, we won't add it. See Servlet Spec 3.1 pg 129
    if (methodOmissions.size() > 0 && httpConstraintMapping != null)
        httpConstraintMapping.setMethodOmissions(methodOmissions.toArray(new String[methodOmissions.size()]));
    return mappings;
}
Also used : Constraint(org.eclipse.jetty.util.security.Constraint) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) HttpMethodConstraintElement(javax.servlet.HttpMethodConstraintElement)

Example 57 with ArrayList

use of java.util.ArrayList in project blade by biezhi.

the class HashLoginService method loadRoleInfo.

/* ------------------------------------------------------------ */
@Override
protected String[] loadRoleInfo(UserPrincipal user) {
    UserIdentity id = _propertyUserStore.getUserIdentity(user.getName());
    if (id == null)
        return null;
    Set<RolePrincipal> roles = id.getSubject().getPrincipals(RolePrincipal.class);
    if (roles == null)
        return null;
    List<String> list = new ArrayList<>();
    for (RolePrincipal r : roles) list.add(r.getName());
    return list.toArray(new String[roles.size()]);
}
Also used : UserIdentity(org.eclipse.jetty.server.UserIdentity) ArrayList(java.util.ArrayList)

Example 58 with ArrayList

use of java.util.ArrayList in project blade by biezhi.

the class AbstractFileRouteLoader method load.

/**
     * Load Route
     *
     * @param inputStream route inputstream
     * @return return route list
     * @throws ParseException parse exception
     * @throws IOException    io exception
     */
private List<Route> load(InputStream inputStream) throws ParseException, IOException {
    int line = 0;
    List<Route> routes = new ArrayList<Route>();
    BufferedReader in = null;
    try {
        in = new BufferedReader(new InputStreamReader(inputStream));
        String input;
        while ((input = in.readLine()) != null) {
            line++;
            input = input.trim();
            if (!input.equals("") && !input.startsWith(".")) {
                Route route = parse(input, line);
                routes.add(route);
            }
        }
    } finally {
        IOKit.closeQuietly(in);
    }
    return routes;
}
Also used : InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) Route(com.blade.mvc.route.Route)

Example 59 with ArrayList

use of java.util.ArrayList in project kata-tcg by bkimminich.

the class AiStrategy method collectMaxDamageCardCombo.

private void collectMaxDamageCardCombo(List<Card> selectedCards, int availableMana, List<Card> availableCards) {
    for (Card card : availableCards) {
        List<Card> remainingCards = new ArrayList<>(availableCards);
        if (selectedCards.stream().mapToInt(Card::getValue).sum() + card.getValue() <= availableMana) {
            selectedCards.add(card);
            remainingCards.remove(card);
            collectMaxDamageCardCombo(selectedCards, availableMana - card.getValue(), remainingCards);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Card(de.kimminich.kata.tcg.Card)

Example 60 with ArrayList

use of java.util.ArrayList in project Japid by branaway.

the class JavaSyntaxTool method parseParams.

/**
	 * parse a line of text that is supposed to be parameter list for a method
	 * declaration.
	 * 
	 * TODO: the parameter annotation, modifiers, etc ignored. should do it!
	 * 
	 * @param line
	 * @return
	 */
public static List<Parameter> parseParams(String line) {
    final List<Parameter> ret = new ArrayList<Parameter>();
    if (line == null || line.trim().length() == 0)
        return ret;
    // make it tolerant of lowercase default
    line = line.replace("@default(", "@Default(");
    String cl = String.format(classTempForParams, line);
    try {
        CompilationUnit cu = parse(cl);
        VoidVisitorAdapter visitor = new VoidVisitorAdapter() {

            @Override
            public void visit(Parameter p, Object arg) {
                ret.add(p);
            }
        };
        cu.accept(visitor, null);
    } catch (ParseException e) {
        throw new RuntimeException("the line does not seem to be a valid param list declaration: " + line);
    }
    return ret;
}
Also used : CompilationUnit(japa.parser.ast.CompilationUnit) ArrayList(java.util.ArrayList) Parameter(japa.parser.ast.body.Parameter) TypeParameter(japa.parser.ast.TypeParameter) ParseException(japa.parser.ParseException) VoidVisitorAdapter(japa.parser.ast.visitor.VoidVisitorAdapter)

Aggregations

ArrayList (java.util.ArrayList)66688 Test (org.junit.Test)10926 List (java.util.List)8600 HashMap (java.util.HashMap)7604 IOException (java.io.IOException)5211 Map (java.util.Map)3776 File (java.io.File)3552 HashSet (java.util.HashSet)2622 Iterator (java.util.Iterator)1783 Test (org.testng.annotations.Test)1379 SQLException (java.sql.SQLException)1319 ResultSet (java.sql.ResultSet)1285 KieSession (org.kie.api.runtime.KieSession)1130 Date (java.util.Date)1109 Set (java.util.Set)1104 PreparedStatement (java.sql.PreparedStatement)1055 LinkedHashMap (java.util.LinkedHashMap)1046 Collection (java.util.Collection)925 URL (java.net.URL)816 LinkedList (java.util.LinkedList)813