Search in sources :

Example 71 with LinkedHashMap

use of java.util.LinkedHashMap in project spring-security by spring-projects.

the class MethodSecurityMetadataSourceBeanDefinitionParser method parseInternal.

public AbstractBeanDefinition parseInternal(Element elt, ParserContext pc) {
    // Parse the included methods
    List<Element> methods = DomUtils.getChildElementsByTagName(elt, Elements.PROTECT);
    Map<String, List<ConfigAttribute>> mappings = new LinkedHashMap<String, List<ConfigAttribute>>();
    for (Element protectmethodElt : methods) {
        String[] tokens = StringUtils.commaDelimitedListToStringArray(protectmethodElt.getAttribute(ATT_ACCESS));
        String methodName = protectmethodElt.getAttribute(ATT_METHOD);
        mappings.put(methodName, SecurityConfig.createList(tokens));
    }
    RootBeanDefinition metadataSource = new RootBeanDefinition(MapBasedMethodSecurityMetadataSource.class);
    metadataSource.getConstructorArgumentValues().addGenericArgumentValue(mappings);
    return metadataSource;
}
Also used : ConfigAttribute(org.springframework.security.access.ConfigAttribute) Element(org.w3c.dom.Element) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap)

Example 72 with LinkedHashMap

use of java.util.LinkedHashMap in project spring-security by spring-projects.

the class ExpressionBasedMessageSecurityMetadataSourceFactory method createExpressionMessageMetadataSource.

/**
	 * Create a {@link MessageSecurityMetadataSource} that uses {@link MessageMatcher}
	 * mapped to Spring Expressions. Each entry is considered in order and only the first
	 * match is used.
	 *
	 * For example:
	 *
	 * <pre>
	 *     LinkedHashMap&lt;MessageMatcher&lt;?&gt;,String&gt; matcherToExpression = new LinkedHashMap&lt;MessageMatcher&lt;Object&gt;,String&gt;();
	 *     matcherToExpression.put(new SimDestinationMessageMatcher("/public/**"), "permitAll");
	 *     matcherToExpression.put(new SimDestinationMessageMatcher("/admin/**"), "hasRole('ROLE_ADMIN')");
	 *     matcherToExpression.put(new SimDestinationMessageMatcher("/**"), "authenticated");
	 *
	 *     MessageSecurityMetadataSource metadataSource = createExpressionMessageMetadataSource(matcherToExpression);
	 * </pre>
	 *
	 * <p>
	 * If our destination is "/public/hello", it would match on "/public/**" and on "/**".
	 * However, only "/public/**" would be used since it is the first entry. That means
	 * that a destination of "/public/hello" will be mapped to "permitAll".
	 * </p>
	 *
	 * <p>
	 * For a complete listing of expressions see {@link MessageSecurityExpressionRoot}
	 * </p>
	 *
	 * @param matcherToExpression an ordered mapping of {@link MessageMatcher} to Strings
	 * that are turned into an Expression using
	 * {@link DefaultMessageSecurityExpressionHandler#getExpressionParser()}
	 * @param handler the {@link SecurityExpressionHandler} to use
	 * @return the {@link MessageSecurityMetadataSource} to use. Cannot be null.
	 */
public static MessageSecurityMetadataSource createExpressionMessageMetadataSource(LinkedHashMap<MessageMatcher<?>, String> matcherToExpression, SecurityExpressionHandler<Message<Object>> handler) {
    LinkedHashMap<MessageMatcher<?>, Collection<ConfigAttribute>> matcherToAttrs = new LinkedHashMap<MessageMatcher<?>, Collection<ConfigAttribute>>();
    for (Map.Entry<MessageMatcher<?>, String> entry : matcherToExpression.entrySet()) {
        MessageMatcher<?> matcher = entry.getKey();
        String rawExpression = entry.getValue();
        Expression expression = handler.getExpressionParser().parseExpression(rawExpression);
        ConfigAttribute attribute = new MessageExpressionConfigAttribute(expression);
        matcherToAttrs.put(matcher, Arrays.asList(attribute));
    }
    return new DefaultMessageSecurityMetadataSource(matcherToAttrs);
}
Also used : MessageMatcher(org.springframework.security.messaging.util.matcher.MessageMatcher) ConfigAttribute(org.springframework.security.access.ConfigAttribute) Expression(org.springframework.expression.Expression) Collection(java.util.Collection) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) DefaultMessageSecurityMetadataSource(org.springframework.security.messaging.access.intercept.DefaultMessageSecurityMetadataSource) LinkedHashMap(java.util.LinkedHashMap)

Example 73 with LinkedHashMap

use of java.util.LinkedHashMap in project camel by apache.

the class SmppDataSmCommandTest method executeWithOptionalParameter.

@SuppressWarnings("unchecked")
@Test
public void executeWithOptionalParameter() throws Exception {
    Exchange exchange = new DefaultExchange(new DefaultCamelContext(), ExchangePattern.InOut);
    exchange.getIn().setHeader(SmppConstants.COMMAND, "DataSm");
    Map<String, String> optionalParameters = new LinkedHashMap<String, String>();
    optionalParameters.put("SOURCE_SUBADDRESS", "1292");
    optionalParameters.put("ADDITIONAL_STATUS_INFO_TEXT", "urgent");
    optionalParameters.put("DEST_ADDR_SUBUNIT", "4");
    optionalParameters.put("DEST_TELEMATICS_ID", "2");
    optionalParameters.put("QOS_TIME_TO_LIVE", "3600000");
    optionalParameters.put("ALERT_ON_MESSAGE_DELIVERY", null);
    // fall back test for vendor specific optional parameter 
    optionalParameters.put("0x2150", "0815");
    optionalParameters.put("0x2151", "0816");
    optionalParameters.put("0x2152", "6");
    optionalParameters.put("0x2153", "9");
    optionalParameters.put("0x2154", "7400000");
    optionalParameters.put("0x2155", null);
    exchange.getIn().setHeader(SmppConstants.OPTIONAL_PARAMETERS, optionalParameters);
    expect(session.dataShortMessage(eq("CMT"), eq(TypeOfNumber.UNKNOWN), eq(NumberingPlanIndicator.UNKNOWN), eq("1616"), eq(TypeOfNumber.UNKNOWN), eq(NumberingPlanIndicator.UNKNOWN), eq("1717"), eq(new ESMClass()), eq(new RegisteredDelivery((byte) 1)), eq(DataCodings.newInstance((byte) 0)), eq(new OptionalParameter.Source_subaddress("1292".getBytes())), eq(new OptionalParameter.Additional_status_info_text("urgent")), eq(new OptionalParameter.Dest_addr_subunit((byte) 4)), eq(new OptionalParameter.Dest_telematics_id((short) 2)), eq(new OptionalParameter.Qos_time_to_live(3600000)), eq(new OptionalParameter.Alert_on_message_delivery((byte) 0)))).andReturn(new DataSmResult(new MessageId("1"), new OptionalParameter[] { new OptionalParameter.Source_subaddress("1292".getBytes()), new OptionalParameter.Additional_status_info_text("urgent"), new OptionalParameter.Dest_addr_subunit((byte) 4), new OptionalParameter.Dest_telematics_id((short) 2), new OptionalParameter.Qos_time_to_live(3600000), new OptionalParameter.Alert_on_message_delivery((byte) 0) }));
    replay(session);
    command.execute(exchange);
    verify(session);
    assertEquals(3, exchange.getOut().getHeaders().size());
    assertEquals("1", exchange.getOut().getHeader(SmppConstants.ID));
    Map<String, String> optParamMap = exchange.getOut().getHeader(SmppConstants.OPTIONAL_PARAMETERS, Map.class);
    assertEquals(6, optParamMap.size());
    assertEquals("1292", optParamMap.get("SOURCE_SUBADDRESS"));
    assertEquals("urgent", optParamMap.get("ADDITIONAL_STATUS_INFO_TEXT"));
    assertEquals("4", optParamMap.get("DEST_ADDR_SUBUNIT"));
    assertEquals("2", optParamMap.get("DEST_TELEMATICS_ID"));
    assertEquals("3600000", optParamMap.get("QOS_TIME_TO_LIVE"));
    assertEquals("0", optParamMap.get("ALERT_ON_MESSAGE_DELIVERY"));
    Map<Short, Object> optionalResultParameter = exchange.getOut().getHeader(SmppConstants.OPTIONAL_PARAMETER, Map.class);
    assertEquals(6, optionalResultParameter.size());
    assertArrayEquals("1292".getBytes("UTF-8"), (byte[]) optionalResultParameter.get(Short.valueOf((short) 0x0202)));
    assertEquals("urgent", optionalResultParameter.get(Short.valueOf((short) 0x001D)));
    assertEquals(Byte.valueOf((byte) 4), optionalResultParameter.get(Short.valueOf((short) 0x0005)));
    assertEquals(Short.valueOf((short) 2), optionalResultParameter.get(Short.valueOf((short) 0x0008)));
    assertEquals(Integer.valueOf(3600000), optionalResultParameter.get(Short.valueOf((short) 0x0017)));
    assertEquals((byte) 0, optionalResultParameter.get(Short.valueOf((short) 0x130C)));
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) ESMClass(org.jsmpp.bean.ESMClass) DataSmResult(org.jsmpp.session.DataSmResult) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) LinkedHashMap(java.util.LinkedHashMap) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) OptionalParameter(org.jsmpp.bean.OptionalParameter) RegisteredDelivery(org.jsmpp.bean.RegisteredDelivery) MessageId(org.jsmpp.util.MessageId) Test(org.junit.Test)

Example 74 with LinkedHashMap

use of java.util.LinkedHashMap in project camel by apache.

the class SmppSubmitMultiCommandTest method executeWithOptionalParameterNewStyle.

@Test
public void executeWithOptionalParameterNewStyle() throws Exception {
    Exchange exchange = new DefaultExchange(new DefaultCamelContext(), ExchangePattern.InOut);
    exchange.getIn().setHeader(SmppConstants.COMMAND, "SubmitMulti");
    exchange.getIn().setHeader(SmppConstants.ID, "1");
    exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR_TON, TypeOfNumber.NATIONAL.value());
    exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR_NPI, NumberingPlanIndicator.NATIONAL.value());
    exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR, "1818");
    exchange.getIn().setHeader(SmppConstants.DEST_ADDR_TON, TypeOfNumber.INTERNATIONAL.value());
    exchange.getIn().setHeader(SmppConstants.DEST_ADDR_NPI, NumberingPlanIndicator.INTERNET.value());
    exchange.getIn().setHeader(SmppConstants.DEST_ADDR, Arrays.asList("1919"));
    exchange.getIn().setHeader(SmppConstants.SCHEDULE_DELIVERY_TIME, new Date(1111111));
    exchange.getIn().setHeader(SmppConstants.VALIDITY_PERIOD, new Date(2222222));
    exchange.getIn().setHeader(SmppConstants.PROTOCOL_ID, (byte) 1);
    exchange.getIn().setHeader(SmppConstants.PRIORITY_FLAG, (byte) 2);
    exchange.getIn().setHeader(SmppConstants.REGISTERED_DELIVERY, new RegisteredDelivery(SMSCDeliveryReceipt.FAILURE).value());
    exchange.getIn().setHeader(SmppConstants.REPLACE_IF_PRESENT_FLAG, ReplaceIfPresentFlag.REPLACE.value());
    Map<Short, Object> optionalParameters = new LinkedHashMap<Short, Object>();
    // standard optional parameter
    optionalParameters.put(Short.valueOf((short) 0x0202), "1292".getBytes("UTF-8"));
    optionalParameters.put(Short.valueOf((short) 0x001D), "urgent");
    optionalParameters.put(Short.valueOf((short) 0x0005), Byte.valueOf("4"));
    optionalParameters.put(Short.valueOf((short) 0x0008), Short.valueOf((short) 2));
    optionalParameters.put(Short.valueOf((short) 0x0017), Integer.valueOf(3600000));
    optionalParameters.put(Short.valueOf((short) 0x130C), null);
    // vendor specific optional parameter
    optionalParameters.put(Short.valueOf((short) 0x2150), "0815".getBytes("UTF-8"));
    optionalParameters.put(Short.valueOf((short) 0x2151), "0816");
    optionalParameters.put(Short.valueOf((short) 0x2152), Byte.valueOf("6"));
    optionalParameters.put(Short.valueOf((short) 0x2153), Short.valueOf((short) 9));
    optionalParameters.put(Short.valueOf((short) 0x2154), Integer.valueOf(7400000));
    optionalParameters.put(Short.valueOf((short) 0x2155), null);
    exchange.getIn().setHeader(SmppConstants.OPTIONAL_PARAMETER, optionalParameters);
    exchange.getIn().setBody("short message body");
    expect(session.submitMultiple(eq("CMT"), eq(TypeOfNumber.NATIONAL), eq(NumberingPlanIndicator.NATIONAL), eq("1818"), aryEq(new Address[] { new Address(TypeOfNumber.INTERNATIONAL, NumberingPlanIndicator.INTERNET, "1919") }), eq(new ESMClass()), eq((byte) 1), eq((byte) 2), eq("-300101001831100+"), eq("-300101003702200+"), eq(new RegisteredDelivery(SMSCDeliveryReceipt.FAILURE)), eq(ReplaceIfPresentFlag.REPLACE), eq(DataCodings.newInstance((byte) 0)), eq((byte) 0), aryEq("short message body".getBytes()), eq(new OptionalParameter.OctetString(Tag.SOURCE_SUBADDRESS, "1292")), eq(new OptionalParameter.COctetString(Tag.ADDITIONAL_STATUS_INFO_TEXT.code(), "urgent")), eq(new OptionalParameter.Byte(Tag.DEST_ADDR_SUBUNIT, (byte) 4)), eq(new OptionalParameter.Short(Tag.DEST_TELEMATICS_ID.code(), (short) 2)), eq(new OptionalParameter.Int(Tag.QOS_TIME_TO_LIVE, 3600000)), eq(new OptionalParameter.Null(Tag.ALERT_ON_MESSAGE_DELIVERY)), eq(new OptionalParameter.OctetString((short) 0x2150, "1292", "UTF-8")), eq(new OptionalParameter.COctetString((short) 0x2151, "0816")), eq(new OptionalParameter.Byte((short) 0x2152, (byte) 6)), eq(new OptionalParameter.Short((short) 0x2153, (short) 9)), eq(new OptionalParameter.Int((short) 0x2154, 7400000)), eq(new OptionalParameter.Null((short) 0x2155)))).andReturn(new SubmitMultiResult("1"));
    replay(session);
    command.execute(exchange);
    verify(session);
    assertEquals(Arrays.asList("1"), exchange.getOut().getHeader(SmppConstants.ID));
    assertEquals(1, exchange.getOut().getHeader(SmppConstants.SENT_MESSAGE_COUNT));
    assertNull(exchange.getOut().getHeader(SmppConstants.ERROR));
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) EasyMock.isNull(org.easymock.EasyMock.isNull) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertNull(org.junit.Assert.assertNull) Address(org.jsmpp.bean.Address) ESMClass(org.jsmpp.bean.ESMClass) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Date(java.util.Date) LinkedHashMap(java.util.LinkedHashMap) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) SubmitMultiResult(org.jsmpp.bean.SubmitMultiResult) RegisteredDelivery(org.jsmpp.bean.RegisteredDelivery) Test(org.junit.Test)

Example 75 with LinkedHashMap

use of java.util.LinkedHashMap in project camel by apache.

the class SmppSubmitSmCommandTest method executeWithOptionalParameter.

@Test
public void executeWithOptionalParameter() throws Exception {
    Exchange exchange = new DefaultExchange(new DefaultCamelContext(), ExchangePattern.InOut);
    exchange.getIn().setHeader(SmppConstants.COMMAND, "SubmitSm");
    exchange.getIn().setHeader(SmppConstants.ID, "1");
    exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR_TON, TypeOfNumber.NATIONAL.value());
    exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR_NPI, NumberingPlanIndicator.NATIONAL.value());
    exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR, "1818");
    exchange.getIn().setHeader(SmppConstants.DEST_ADDR_TON, TypeOfNumber.INTERNATIONAL.value());
    exchange.getIn().setHeader(SmppConstants.DEST_ADDR_NPI, NumberingPlanIndicator.INTERNET.value());
    exchange.getIn().setHeader(SmppConstants.DEST_ADDR, "1919");
    exchange.getIn().setHeader(SmppConstants.SCHEDULE_DELIVERY_TIME, new Date(1111111));
    exchange.getIn().setHeader(SmppConstants.VALIDITY_PERIOD, new Date(2222222));
    exchange.getIn().setHeader(SmppConstants.PROTOCOL_ID, (byte) 1);
    exchange.getIn().setHeader(SmppConstants.PRIORITY_FLAG, (byte) 2);
    exchange.getIn().setHeader(SmppConstants.REGISTERED_DELIVERY, new RegisteredDelivery(SMSCDeliveryReceipt.FAILURE).value());
    exchange.getIn().setHeader(SmppConstants.REPLACE_IF_PRESENT_FLAG, ReplaceIfPresentFlag.REPLACE.value());
    exchange.getIn().setBody("short message body");
    Map<String, String> optionalParameters = new LinkedHashMap<String, String>();
    optionalParameters.put("SOURCE_SUBADDRESS", "1292");
    optionalParameters.put("ADDITIONAL_STATUS_INFO_TEXT", "urgent");
    optionalParameters.put("DEST_ADDR_SUBUNIT", "4");
    optionalParameters.put("DEST_TELEMATICS_ID", "2");
    optionalParameters.put("QOS_TIME_TO_LIVE", "3600000");
    optionalParameters.put("ALERT_ON_MESSAGE_DELIVERY", null);
    exchange.getIn().setHeader(SmppConstants.OPTIONAL_PARAMETERS, optionalParameters);
    expect(session.submitShortMessage(eq("CMT"), eq(TypeOfNumber.NATIONAL), eq(NumberingPlanIndicator.NATIONAL), eq("1818"), eq(TypeOfNumber.INTERNATIONAL), eq(NumberingPlanIndicator.INTERNET), eq("1919"), eq(new ESMClass()), eq((byte) 1), eq((byte) 2), eq("-300101001831100+"), eq("-300101003702200+"), eq(new RegisteredDelivery(SMSCDeliveryReceipt.FAILURE)), eq(ReplaceIfPresentFlag.REPLACE.value()), eq(DataCodings.newInstance((byte) 0)), eq((byte) 0), aryEq("short message body".getBytes()), eq(new OptionalParameter.Source_subaddress("1292".getBytes())), eq(new OptionalParameter.Additional_status_info_text("urgent".getBytes())), eq(new OptionalParameter.Dest_addr_subunit((byte) 4)), eq(new OptionalParameter.Dest_telematics_id((short) 2)), eq(new OptionalParameter.Qos_time_to_live(3600000)), eq(new OptionalParameter.Alert_on_message_delivery((byte) 0)))).andReturn("1");
    replay(session);
    command.execute(exchange);
    verify(session);
    assertEquals(Arrays.asList("1"), exchange.getOut().getHeader(SmppConstants.ID));
    assertEquals(1, exchange.getOut().getHeader(SmppConstants.SENT_MESSAGE_COUNT));
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) ESMClass(org.jsmpp.bean.ESMClass) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Date(java.util.Date) LinkedHashMap(java.util.LinkedHashMap) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) RegisteredDelivery(org.jsmpp.bean.RegisteredDelivery) Test(org.junit.Test)

Aggregations

LinkedHashMap (java.util.LinkedHashMap)2398 Map (java.util.Map)691 ArrayList (java.util.ArrayList)675 HashMap (java.util.HashMap)439 Test (org.junit.Test)317 List (java.util.List)298 IOException (java.io.IOException)152 HashSet (java.util.HashSet)128 Set (java.util.Set)110 LinkedHashSet (java.util.LinkedHashSet)100 File (java.io.File)93 LinkedList (java.util.LinkedList)75 TreeMap (java.util.TreeMap)72 Node (org.apache.hadoop.hive.ql.lib.Node)70 NodeProcessor (org.apache.hadoop.hive.ql.lib.NodeProcessor)68 Rule (org.apache.hadoop.hive.ql.lib.Rule)68 GraphWalker (org.apache.hadoop.hive.ql.lib.GraphWalker)66 Dispatcher (org.apache.hadoop.hive.ql.lib.Dispatcher)65 Iterator (java.util.Iterator)64 DefaultRuleDispatcher (org.apache.hadoop.hive.ql.lib.DefaultRuleDispatcher)64