src_fm_fc_ms_ff
stringlengths
43
86.8k
target
stringlengths
20
276k
ObjectFieldConverter extends ConverterBase { @Override public void setObject(FieldWrapper field, RequestContainer request) { Class<?> targetClass = field.getTargetClass(); if (null != targetClass) { Object currentObject = field.getObject(); BeanWrapper wrapper = field.getBeanWrapper(); if (null == currentObject) { try { currentObject = targetClass.newInstance(); wrapper.setPropertyValue(field.getBinding(), currentObject); logSetObject(field, currentObject); } catch (InstantiationException | IllegalAccessException e) { LOGGER.error(String.format("error setting property %s for %s", field.getBinding(), wrapper.getWrappedInstance()), e); } } else { LOGGER.debug("no need to set property '{}' on {} (value is {}, type: {})", field.getBinding(), wrapper.getWrappedClass().getName(), currentObject, targetClass.getName()); } } } ObjectFieldConverter(); @Override void setString(FieldWrapper field); @Override void setObject(FieldWrapper field, RequestContainer request); }
@Override @Test public void testSetObject() throws Exception { darth.getOffsprings().clear(); Set<String> parameterNames = new HashSet<>(); parameterNames.add(addParameter("father.name", "Vader")); parameterNames.add(addParameter("father.firstname", "Darth")); parameterNames.add(addParameter("father.offsprings[0].name", "Skywalker")); parameterNames.add(addParameter("father.offsprings[0].firstname", "Luke")); parameterNames.add(addParameter("father.offsprings[1].name", "Organa")); parameterNames.add(addParameter("father.offsprings[1].firstname", "Leia")); Mockito.when(request.getParameterNames()).thenReturn(parameterNames); fieldConverter.setObject(fieldWrapper, request); Person bindVader = (Person) fieldWrapper.getObject(); Assert.assertEquals("Darth", bindVader.getFirstname()); Assert.assertEquals("Vader", bindVader.getName()); List<Person> offsprings = bindVader.getOffsprings(); Assert.assertEquals(2, offsprings.size()); Assert.assertEquals("Luke", offsprings.get(0).getFirstname()); Assert.assertEquals("Skywalker", offsprings.get(0).getName()); Assert.assertEquals("Leia", offsprings.get(1).getFirstname()); Assert.assertEquals("Organa", offsprings.get(1).getName()); }
ObjectFieldConverter extends ConverterBase { @Override public void setString(FieldWrapper field) { } ObjectFieldConverter(); @Override void setString(FieldWrapper field); @Override void setObject(FieldWrapper field, RequestContainer request); }
@Override @Test public void testSetString() throws Exception { fieldConverter.setString(fieldWrapper); Assert.assertNull(fieldWrapper.getStringValue()); }
OptionImpl implements Option { public String getName() { return name; } OptionImpl(String name); OptionImpl(String name, Map<String, String> map); String getName(); OptionImpl addMap(Map<String, String> map); OptionImpl addAttribute(String name, String value); boolean containsAttribute(String name); String getAttribute(String name); int getAttributeAsInteger(String name); Set<String> getAttributeNames(); Map<String, String> getAttributeMap(); String getString(String name); Integer getInteger(String name); Boolean getBoolean(String name); E getEnum(String name, Class<E> type); String toString(); }
@Test public void testGetName() { String name = option.getName(); Assert.assertEquals("option", name); }
XHTML { public static String getBody(String tag, String content) { String regex = "(<" + tag + "(.)*>)(.*)(</( )?" + tag + ">)"; Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(content); if (matcher.matches() && matcher.groupCount() > 2) { String body = matcher.group(3); return body; } return null; } static String removeAttr(String tag, String attr); static String setAttr(String tag, String attr, String value); static String getBody(String tag, String content); static String setBody(String tag, String value); static String getAttr(String tag, String attr); static String getTag(String tag); }
@Test public void testGetBody() { String content = "<a href=\"http: String expResult = "aiticon-web"; String result = XHTML.getBody("a", content); assertEquals(expResult, result); content = "<a href=\"http: expResult = ""; result = XHTML.getBody("a", content); assertEquals(expResult, result); Assert.assertNull(XHTML.getBody("a", "asdad")); }
OptionImpl implements Option { public OptionImpl addMap(Map<String, String> map) { attributeMap.putAll(map); return this; } OptionImpl(String name); OptionImpl(String name, Map<String, String> map); String getName(); OptionImpl addMap(Map<String, String> map); OptionImpl addAttribute(String name, String value); boolean containsAttribute(String name); String getAttribute(String name); int getAttributeAsInteger(String name); Set<String> getAttributeNames(); Map<String, String> getAttributeMap(); String getString(String name); Integer getInteger(String name); Boolean getBoolean(String name); E getEnum(String name, Class<E> type); String toString(); }
@Test public void testAddMap() { option.getAttributeMap().clear(); option.addMap(OptionData.getAttributesMap()); Assert.assertEquals(OptionData.getAttributesMap().size(), option.getAttributeMap().size()); }
OptionImpl implements Option { public OptionImpl addAttribute(String name, String value) { attributeMap.put(name, value); return this; } OptionImpl(String name); OptionImpl(String name, Map<String, String> map); String getName(); OptionImpl addMap(Map<String, String> map); OptionImpl addAttribute(String name, String value); boolean containsAttribute(String name); String getAttribute(String name); int getAttributeAsInteger(String name); Set<String> getAttributeNames(); Map<String, String> getAttributeMap(); String getString(String name); Integer getInteger(String name); Boolean getBoolean(String name); E getEnum(String name, Class<E> type); String toString(); }
@Test public void testAddAttribute() { option.addAttribute("key", "value"); Assert.assertEquals("value", option.getString("key")); }
OptionImpl implements Option { public Integer getInteger(String name) { String value = getString(name); return null == value ? null : INT_PATTERN.matcher(value).matches() ? Integer.valueOf(value) : null; } OptionImpl(String name); OptionImpl(String name, Map<String, String> map); String getName(); OptionImpl addMap(Map<String, String> map); OptionImpl addAttribute(String name, String value); boolean containsAttribute(String name); String getAttribute(String name); int getAttributeAsInteger(String name); Set<String> getAttributeNames(); Map<String, String> getAttributeMap(); String getString(String name); Integer getInteger(String name); Boolean getBoolean(String name); E getEnum(String name, Class<E> type); String toString(); }
@Test public void testGetInteger() { option.addAttribute("key", "value"); option.addAttribute("int", "1"); Assert.assertEquals(Integer.valueOf(1), option.getInteger("int")); Assert.assertNull(option.getInteger("key")); Assert.assertNull(option.getInteger("not-exists")); }
OptionImpl implements Option { public String toString() { StringBuffer result = new StringBuffer(getName() + " [ "); getAttributeNames().forEach(key -> result.append(key + "=\"" + getString(key) + "\" ")); result.append("]"); return result.toString(); } OptionImpl(String name); OptionImpl(String name, Map<String, String> map); String getName(); OptionImpl addMap(Map<String, String> map); OptionImpl addAttribute(String name, String value); boolean containsAttribute(String name); String getAttribute(String name); int getAttributeAsInteger(String name); Set<String> getAttributeNames(); Map<String, String> getAttributeMap(); String getString(String name); Integer getInteger(String name); Boolean getBoolean(String name); E getEnum(String name, Class<E> type); String toString(); }
@Test public void testToString() { option = new OptionImpl("option"); option.addAttribute("key", "value"); Assert.assertEquals("option [ key=\"value\" ]", option.toString()); }
OptionImpl implements Option { public int getAttributeAsInteger(String name) { return Integer.valueOf(attributeMap.get(name)); } OptionImpl(String name); OptionImpl(String name, Map<String, String> map); String getName(); OptionImpl addMap(Map<String, String> map); OptionImpl addAttribute(String name, String value); boolean containsAttribute(String name); String getAttribute(String name); int getAttributeAsInteger(String name); Set<String> getAttributeNames(); Map<String, String> getAttributeMap(); String getString(String name); Integer getInteger(String name); Boolean getBoolean(String name); E getEnum(String name, Class<E> type); String toString(); }
@Test public void testGetAttributeAsInteger() { option = new OptionImpl("option"); option.addAttribute("key", "1"); Assert.assertEquals(1, option.getAttributeAsInteger("key")); }
OptionImpl implements Option { public boolean containsAttribute(String name) { return attributeMap.containsKey(name); } OptionImpl(String name); OptionImpl(String name, Map<String, String> map); String getName(); OptionImpl addMap(Map<String, String> map); OptionImpl addAttribute(String name, String value); boolean containsAttribute(String name); String getAttribute(String name); int getAttributeAsInteger(String name); Set<String> getAttributeNames(); Map<String, String> getAttributeMap(); String getString(String name); Integer getInteger(String name); Boolean getBoolean(String name); E getEnum(String name, Class<E> type); String toString(); }
@Test public void testContainsAttribute() { option.getAttributeMap().clear(); option.addMap(OptionData.getAttributesMap()); Assert.assertEquals(true, option.containsAttribute("attribute-1")); }
HttpHeaderUtils { public static byte[] handleModifiedHeaders(HttpServletRequest servletRequest, HttpServletResponse servletResponse, HttpResource resource, boolean output) throws IOException { byte[] result = new byte[0]; String sessionId = servletRequest.getSession().getId(); long lastModified = resource.update(); Date ifModifiedSince = null; String ifModifiedSinceHeader = servletRequest.getHeader(HttpHeaders.IF_MODIFIED_SINCE); boolean hasModifiedSince = StringUtils.isNotBlank(ifModifiedSinceHeader); if (hasModifiedSince) { try { LOGGER.debug("[{}] received {}={} for {}?{}", sessionId, HttpHeaders.IF_MODIFIED_SINCE, ifModifiedSinceHeader, servletRequest.getServletPath(), servletRequest.getQueryString()); ifModifiedSince = HTTP_DATE.parse(ifModifiedSinceHeader); } catch (ParseException e) { hasModifiedSince = false; LOGGER.debug("[{}] error parsing header {}={} for {}?{} ({})", sessionId, HttpHeaders.IF_MODIFIED_SINCE, ifModifiedSinceHeader, servletRequest.getServletPath(), servletRequest.getQueryString(), e.getMessage()); } } boolean isModifiedAfter = hasModifiedSince && lastModified > ifModifiedSince.getTime(); if (resource.needsUpdate() || isModifiedAfter || !hasModifiedSince) { result = resource.getData(); } if (hasModifiedSince && !isModifiedAfter) { servletResponse.setStatus(HttpServletResponse.SC_NOT_MODIFIED); LOGGER.debug("[{}] setting status {} for {}?{}", sessionId, HttpServletResponse.SC_NOT_MODIFIED, servletRequest.getServletPath(), servletRequest.getQueryString()); } else { String lastModifiedHeader = HTTP_DATE.format(new Date(lastModified)); servletResponse.setHeader(HttpHeaders.LAST_MODIFIED, lastModifiedHeader); LOGGER.debug("[{}] setting {}={} for {}?{}", sessionId, HttpHeaders.LAST_MODIFIED, lastModifiedHeader, servletRequest.getServletPath(), servletRequest.getQueryString()); if (output) { LOGGER.debug("[{}] setting content type {} ({}B) for {}?{}", sessionId, resource.getContentType(), result.length, servletRequest.getServletPath(), servletRequest.getQueryString()); servletResponse.setContentType(resource.getContentType()); servletResponse.setContentLength(result.length); servletResponse.getOutputStream().write(result); } } return result; } static byte[] handleModifiedHeaders(HttpServletRequest servletRequest, HttpServletResponse servletResponse, HttpResource resource, boolean output); static byte[] handleModifiedHeaders(HttpHeaders requestHeaders, HttpHeaders responseHeaders, HttpResource resource); static HttpHeaders parse(HttpServletRequest httpServletRequest); static void applyHeaders(HttpServletResponse httpServletResponse, HttpHeaders headers); }
@Test public void testNotModified() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); request.addHeader(HttpHeaders.IF_MODIFIED_SINCE, HttpHeaderUtils.HTTP_DATE.format(new Date())); MockHttpServletResponse response = new MockHttpServletResponse(); HttpHeaderUtils.HttpResource resource = getResource(); Assert.assertFalse(resource.needsUpdate()); Assert.assertNull(resource.getData()); HttpHeaderUtils.handleModifiedHeaders(request, response, resource, true); Assert.assertTrue(resource.needsUpdate()); Assert.assertArrayEquals(BYTES, resource.getData()); Assert.assertNull(response.getHeader(HttpHeaders.LAST_MODIFIED)); Assert.assertEquals(HttpServletResponse.SC_NOT_MODIFIED, response.getStatus()); Assert.assertNull(response.getContentType()); Assert.assertEquals(0, response.getContentLength()); Assert.assertEquals("", response.getContentAsString()); } @Test public void testOK() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); HttpHeaderUtils.HttpResource resource = getResource(); Assert.assertFalse(resource.needsUpdate()); Assert.assertNull(resource.getData()); HttpHeaderUtils.handleModifiedHeaders(request, response, resource, true); validateResponseOK(response, resource); } @Test public void testInvalid() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); request.addHeader(HttpHeaders.IF_MODIFIED_SINCE, "not a date"); MockHttpServletResponse response = new MockHttpServletResponse(); HttpHeaderUtils.HttpResource resource = getResource(); Assert.assertFalse(resource.needsUpdate()); Assert.assertNull(resource.getData()); HttpHeaderUtils.handleModifiedHeaders(request, response, resource, true); validateResponseOK(response, resource); }
OptionsImpl implements Options { public void addOption(Option option) { optionsMap.put(option.getName(), option); } void addOption(Option option); Option getOption(String name); boolean hasOption(String name); Set<String> getOptionNames(); String getOptionValue(String optionName, String attributeName); String toString(); String getString(String name, String attribute); Integer getInteger(String name, String attribute); Boolean getBoolean(String name, String attribute); E getEnum(String name, String attribute, Class<E> type); }
@Test public void testAddOption() { options.addOption(getOption()); Assert.assertEquals(getOption().getName(), options.getOption("testOption").getName()); }
XHTML { public static String getAttr(String tag, String attr) { String value = ""; Pattern p = Pattern.compile(getAttributeExpression(attr)); Matcher m = p.matcher(tag); if (m.find()) { value = m.group(1); } return value; } static String removeAttr(String tag, String attr); static String setAttr(String tag, String attr, String value); static String getBody(String tag, String content); static String setBody(String tag, String value); static String getAttr(String tag, String attr); static String getTag(String tag); }
@Test public void testGetAttr() { String content = "<a href=\"http: String attr = "href"; String expResult = "http: String result = XHTML.getAttr(content, attr); assertEquals(expResult, result); content = "<a href=\"http: attr = "name"; expResult = ""; result = XHTML.getAttr(content, attr); assertEquals(expResult, result); } @Test public void testGetAttr2() { String result = XHTML.getAttr("<input data-type=\"foobar\" type=\"checkbox\" />", "type"); assertEquals("checkbox", result); }
OptionsImpl implements Options { public String getOptionValue(String optionName, String attributeName) { Option option = getOption(optionName); return (null == option) ? null : option.getString(attributeName); } void addOption(Option option); Option getOption(String name); boolean hasOption(String name); Set<String> getOptionNames(); String getOptionValue(String optionName, String attributeName); String toString(); String getString(String name, String attribute); Integer getInteger(String name, String attribute); Boolean getBoolean(String name, String attribute); E getEnum(String name, String attribute, Class<E> type); }
@Test public void testGetOptionValue() { options.optionsMap.putAll(OptionData.getOptionsMap()); String optionValue = options.getOptionValue("options-4", "attribute-4"); Assert.assertEquals("value-4", optionValue); } @Test public void testGetOptionValueNull() { options.optionsMap.putAll(OptionData.getOptionsMap()); String optionValue = options.getOptionValue("not-exists", "attribute-4"); Assert.assertEquals(null, optionValue); }
OptionsImpl implements Options { public Integer getInteger(String name, String attribute) { return hasOption(name) ? getOption(name).getInteger(attribute) : null; } void addOption(Option option); Option getOption(String name); boolean hasOption(String name); Set<String> getOptionNames(); String getOptionValue(String optionName, String attributeName); String toString(); String getString(String name, String attribute); Integer getInteger(String name, String attribute); Boolean getBoolean(String name, String attribute); E getEnum(String name, String attribute, Class<E> type); }
@Test public void testGetInteger() { options.optionsMap.putAll(OptionData.getOptionsMap()); Assert.assertEquals(Integer.valueOf(6), options.getInteger("options-6", "integer-6")); Assert.assertEquals(Integer.valueOf(-7), options.getInteger("options-7", "integer-7")); Assert.assertNull(options.getInteger("options-4", "attribute-4")); Assert.assertNull(options.getInteger("options-7","not-exists")); }
OptionsImpl implements Options { public Boolean getBoolean(String name, String attribute) { return hasOption(name) ? getOption(name).getBoolean(attribute) : null; } void addOption(Option option); Option getOption(String name); boolean hasOption(String name); Set<String> getOptionNames(); String getOptionValue(String optionName, String attributeName); String toString(); String getString(String name, String attribute); Integer getInteger(String name, String attribute); Boolean getBoolean(String name, String attribute); E getEnum(String name, String attribute, Class<E> type); }
@Test public void testGetBoolean() { options.optionsMap.putAll(OptionData.getOptionsMap()); Assert.assertEquals(Boolean.TRUE, options.getBoolean("options-9", "bool-9")); Assert.assertEquals(Boolean.FALSE, options.getBoolean("options-7", "integer-7")); }
OptionsImpl implements Options { public <E extends Enum<E>> E getEnum(String name, String attribute, Class<E> type) { return hasOption(name) ? getOption(name).getEnum(attribute, type) : null; } void addOption(Option option); Option getOption(String name); boolean hasOption(String name); Set<String> getOptionNames(); String getOptionValue(String optionName, String attributeName); String toString(); String getString(String name, String attribute); Integer getInteger(String name, String attribute); Boolean getBoolean(String name, String attribute); E getEnum(String name, String attribute, Class<E> type); }
@Test public void testGetEnum() { options.optionsMap.putAll(OptionData.getOptionsMap()); Assert.assertEquals(FieldType.TEXT, options.getEnum("options-8", "enum-8", FieldType.class)); Assert.assertNull(options.getEnum("options-7", "integer-7", FieldType.class)); }
OptionsImpl implements Options { public Set<String> getOptionNames() { return optionsMap.keySet(); } void addOption(Option option); Option getOption(String name); boolean hasOption(String name); Set<String> getOptionNames(); String getOptionValue(String optionName, String attributeName); String toString(); String getString(String name, String attribute); Integer getInteger(String name, String attribute); Boolean getBoolean(String name, String attribute); E getEnum(String name, String attribute, Class<E> type); }
@Test public void testGetOptionNames() { options.optionsMap.putAll(OptionData.getOptionsMap()); Set<String> optionsKeys = options.getOptionNames(); Assert.assertEquals(9, optionsKeys.size()); Assert.assertEquals(OptionData.getOptionsMap().keySet(), optionsKeys); }
OptionsImpl implements Options { public String toString() { StringBuffer result = new StringBuffer(); result.append(optionsMap.values()); return result.toString(); } void addOption(Option option); Option getOption(String name); boolean hasOption(String name); Set<String> getOptionNames(); String getOptionValue(String optionName, String attributeName); String toString(); String getString(String name, String attribute); Integer getInteger(String name, String attribute); Boolean getBoolean(String name, String attribute); E getEnum(String name, String attribute, Class<E> type); }
@Test public void testToString() { options.optionsMap.clear(); options.optionsMap.put("key", new OptionImpl("value").addAttribute("attr", "attr-value")); String actual = options.toString(); Assert.assertEquals("[value [ attr=\"attr-value\" ]]", actual); }
MessageSourceChain implements MessageSource { public String getMessage(String code, Object[] args, String defaultMessage, Locale locale) { check(); String message = null; for (int i = 0; i < messageSources.length && message == null; i++) { message = messageSources[i].getMessage(code, args, defaultMessage, locale); } return message; } MessageSourceChain(); MessageSourceChain(MessageSource... messageSources); String getMessage(String code, Object[] args, String defaultMessage, Locale locale); String getMessage(String code, Object[] args, Locale locale); String getMessage(MessageSourceResolvable resolvable, Locale locale); MessageSource[] getMessageSources(); void setMessageSources(MessageSource[] messageSources); }
@Test public void testGetMessage() { Assert.assertEquals(VALUE1, ms.getMessage(KEY1, args, locale)); Assert.assertEquals(VALUE2, ms.getMessage(KEY2, args, locale)); Assert.assertEquals(VALUE3, ms.getMessage(KEY3, args, locale)); } @Test(expected = NoSuchMessageException.class) public void testGetMessageException() { ms.getMessage(KEY4, args, locale); } @Test public void testGetMessageWithDefault() { Assert.assertEquals(VALUE1, ms.getMessage(KEY1, args, defaultMessage, locale)); Assert.assertEquals(VALUE2, ms.getMessage(KEY2, args, defaultMessage, locale)); Assert.assertEquals(VALUE3, ms.getMessage(KEY3, args, defaultMessage, locale)); Assert.assertEquals(VALUE_DEFAULT, ms.getMessage(KEY4, args, defaultMessage, locale)); Assert.assertNull(ms.getMessage(KEY4, args, null, locale)); } @Test public void testGetMessageFromMessageSourceResolvable() { MessageSourceResolvable r1 = getResolvable(KEY1, null); Assert.assertEquals(VALUE1, ms.getMessage(r1, locale)); MessageSourceResolvable r2 = getResolvable(KEY2, null); Assert.assertEquals(VALUE2, ms.getMessage(r2, locale)); MessageSourceResolvable r3 = getResolvable(KEY3, null); Assert.assertEquals(VALUE3, ms.getMessage(r3, locale)); MessageSourceResolvable r4 = getResolvable(KEY4, defaultMessage); Assert.assertEquals(VALUE_DEFAULT, ms.getMessage(r4, locale)); } @Test(expected = NoSuchMessageException.class) public void testGetMessageFromMessageSourceResolvableWithException() { ms.getMessage(getResolvable(KEY4, null), locale); } @Test(expected = UnsupportedOperationException.class) public void testNoMessageSources() { new MessageSourceChain().getMessage(KEY1, args, locale); }
SortParamSupport { Pageable getPageable(String string) { if (MODE_RESET.equals(string) || StringUtils.endsWith(string, MODE_RESET)) { reset = true; } String key = getSessionKey(); String currentOrder = sessionMap.get(key); Pageable currentParams = parseParamsToPageable(currentOrder, false); Pageable parseParams = parseParamsToPageable(string, true); Pageable mergeOrderParams = mergeOrderParams(currentParams, parseParams); String sortString = getSortString(mergeOrderParams); sessionMap.put(key, sortString); return mergeOrderParams; } SortParamSupport(final Map<String, String> applicationSessionParams, String pageId, String dsId, Integer defaultPageSize); }
@Test public void testClear() { Mockito.when(sessionMap.get(SESS_PARAM_ID)).thenReturn("lastname:asc;name:desc;id:desc"); Pageable sortParams = sortParamSupport.getPageable("lastname:;name:;id:"); Assert.assertNull(sortParams.getSort()); }
XSSUtil { public String stripXss(String parameter) { if (null == parameter) { return parameter; } return Jsoup.clean(encoder.canonicalize(parameter), whitelist); } XSSUtil(Encoder encoder); XSSUtil(Encoder encoder, Whitelist whitelist, String... exceptions); String stripXss(String parameter); String[] stripXss(String[] values); boolean doProcess(HttpServletRequest request); boolean doProcess(HttpServletRequest request, String... exceptions); void setProcessed(HttpServletRequest request, boolean processed); }
@Test public void test(){ XSSUtil xssUtil = new XSSUtil(ESAPI.encoder(), new Whitelist()); Assert.assertEquals("", xssUtil.stripXss("<script>alert('XSS!')<%2Fscript>")); Assert.assertEquals("", xssUtil.stripXss("<meta http-equiv%3D\"refresh\" content%3D\"0; url%3Dhttps:%2F%2Fwww.aiticon.com%2F\">")); }
ExpressionEvaluator { @SuppressWarnings("unchecked") public final <T> T evaluate(String expression, Class<T> targetType) { ValueExpression ve = ef.createValueExpression(ctx, expression, targetType); Object value = ve.getValue(ctx); T result = (T) value; if (LOGGER.isDebugEnabled()) { StringBuilder sb = new StringBuilder(expression + " = " + result + " ["); sb.append(variableMapper.toString()); sb.append("]"); LOGGER.debug(sb.toString()); } return result; } ExpressionEvaluator(Map<String, ?> variables); ExpressionEvaluator(javax.el.VariableMapper variableMapper); @SuppressWarnings("unchecked") final T evaluate(String expression, Class<T> targetType); final boolean evaluate(String expression); final void addFunction(String prefix, String name, Method method); final void addFunction(String name, Method method); final void setVariable(String name, Object value); final void setVariables(Map<String, ?> variables); boolean isExpression(String value); String getString(String expression); Boolean getBoolean(String expression); }
@Test public void testNestedMap() { Assert.assertTrue(evaluator.evaluate("${SESSION.foo eq 5}")); Assert.assertTrue(evaluator.evaluate("${SESSION['foo'] eq 5}")); Assert.assertTrue(evaluator.evaluate("${SESSION.foo ne null}")); Assert.assertFalse(evaluator.evaluate("${SESSION['bar'] eq 5}")); Assert.assertTrue(evaluator.evaluate("${SESSION.bar eq null}")); } @Test public void testParamIsNull() { Assert.assertTrue(evaluator.evaluate("${uizuihm eq null}")); } @Test public void testDash() { parameters.put("site-id", ""); evaluator = new ExpressionEvaluator(parameters); Object result = evaluator.evaluate("${site-id eq ''}", boolean.class); System.out.println(result); result = evaluator.evaluate("${site-id}", int.class); System.out.println(result); } @Test public void testTernary() { evaluator = new ExpressionEvaluator(parameters); String result = evaluator.evaluate("${a eq 5 ? 'is five' : 'is not five'}", String.class); Assert.assertEquals("is five", result); result = evaluator.evaluate("${b eq 5 ? 'is five' : 'is not five'}", String.class); Assert.assertEquals("is not five", result); result = evaluator.evaluate("${a eq null ? 'is null': 'is not null'}", String.class); Assert.assertEquals("is not null", result); result = evaluator.evaluate("${c eq null ? 'is null': 'is not null'}", String.class); Assert.assertEquals("is null", result); } @Test public void testNameConventions() { parameters.put("a", "1"); parameters.put("a_", "2"); parameters.put("A", "3"); parameters.put("A_", "4"); parameters.put("ab", "5"); parameters.put("aB", "6"); parameters.put("a_b", "7"); parameters.put("aB_", "8"); evaluator = new ExpressionEvaluator(parameters); Assert.assertEquals(Integer.valueOf(1), evaluator.evaluate("${a}", Integer.class)); Assert.assertEquals(Integer.valueOf(2), evaluator.evaluate("${a_}", Integer.class)); Assert.assertEquals(Integer.valueOf(3), evaluator.evaluate("${A}", Integer.class)); Assert.assertEquals(Integer.valueOf(4), evaluator.evaluate("${A_}", Integer.class)); Assert.assertEquals(Integer.valueOf(5), evaluator.evaluate("${ab}", Integer.class)); Assert.assertEquals(Integer.valueOf(6), evaluator.evaluate("${aB}", Integer.class)); Assert.assertEquals(Integer.valueOf(7), evaluator.evaluate("${a_b}", Integer.class)); Assert.assertEquals(Integer.valueOf(8), evaluator.evaluate("${aB_}", Integer.class)); } @Test public void testNotDefinedInteger() throws Exception { boolean result = evaluator.evaluate("${c eq null}"); System.out.println(result); }
ExpressionEvaluator { public boolean isExpression(String value) { return null != value && value.matches("\\$\\{.*\\}"); } ExpressionEvaluator(Map<String, ?> variables); ExpressionEvaluator(javax.el.VariableMapper variableMapper); @SuppressWarnings("unchecked") final T evaluate(String expression, Class<T> targetType); final boolean evaluate(String expression); final void addFunction(String prefix, String name, Method method); final void addFunction(String name, Method method); final void setVariable(String name, Object value); final void setVariables(Map<String, ?> variables); boolean isExpression(String value); String getString(String expression); Boolean getBoolean(String expression); }
@Test public void testIsExpression() { Assert.assertTrue(evaluator.isExpression("${c eq null}")); Assert.assertTrue(evaluator.isExpression("${sdsdfsdf}")); Assert.assertFalse(evaluator.isExpression("#{sdsdfsdf}")); Assert.assertFalse(evaluator.isExpression("$sdsdfsdf}")); Assert.assertFalse(evaluator.isExpression("{sdsdfsdf}")); Assert.assertFalse(evaluator.isExpression("${sdsdfsdf")); }
XHTML { public static String getTag(String tag) { String value = ""; Pattern p = Pattern.compile("<(\\w+?)\\s"); Matcher m = p.matcher(tag); if (m.find()) { value = m.group(1); } return value; } static String removeAttr(String tag, String attr); static String setAttr(String tag, String attr, String value); static String getBody(String tag, String content); static String setBody(String tag, String value); static String getAttr(String tag, String attr); static String getTag(String tag); }
@Test public void testGetTag() { String content = "<body id=\"top\" background=\"blue\">"; String expResult = "body"; String result = XHTML.getTag(content); assertEquals(expResult, result); }
ApplicationProvider extends SiteApplication implements AccessibleApplication { public Datasource processDataSource(HttpServletResponse servletResponse, boolean applyPermissionsOnRef, ApplicationRequest applicationRequest, String dataSourceId, MarshallService marshallService) throws InvalidConfigurationException, ProcessingException { ApplicationConfigProvider applicationConfigProvider = getApplicationConfig().cloneConfig(marshallService); applicationRequest.setApplicationConfig(applicationConfigProvider); Datasource dataSource = applicationConfigProvider.getDatasource(dataSourceId); if (null == dataSource) { LOGGER.debug("DataSource {} not found on application {} of site {}", dataSource, application.getName(), site.getName()); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); return null; } DataConfig config = dataSource.getConfig(); Environment environment = applicationRequest.getEnvironment(); if (permissionsPresent(config) || environment.isSubjectAuthenticated()) { Params params = config.getParams(); DatasourceRef datasourceRef = new DatasourceRef(); datasourceRef.setId(dataSourceId); if (applyPermissionsOnRef) { datasourceRef.setPermissions(config.getPermissions()); } datasourceRef.setParams(params); setParamValues(applicationRequest, params); ParameterSupport parameterSupport = applicationRequest.getParameterSupportDollar(); CallableDataSource callableDataSource = new CallableDataSource(site, application, applicationRequest, parameterSupport, datasourceRef); if (callableDataSource.doInclude()) { LOGGER.debug("Performing dataSource {} of application {} on site {}", dataSourceId, application.getName(), site.getName()); callableDataSource.perform("service"); return callableDataSource.getDatasource(); } LOGGER.debug("Include condition for dataSource {} of application {} on site {} does not match.", dataSourceId, application.getName(), site.getName()); } Subject subject = environment.getSubject(); LOGGER.debug( "DataSource {} of application {} on site {} neither defines permissions, nor is the subject authenticated (subject is {}). Sending 403.", dataSource, application.getName(), site.getName(), subject == null ? "<unknown>" : subject.getAuthName()); servletResponse.setStatus(HttpStatus.FORBIDDEN.value()); return null; } ApplicationProvider(Site site, Application application, boolean monitorPerformance); ApplicationProvider(Site site, Application application); ApplicationReference process(ApplicationRequest applicationRequest, MarshallService marshallService, Path pathInfo, PlatformConfig platformConfig); void setApplicationConfig(ApplicationConfigProvider applicationConfig); Integer getId(); void setId(Integer id); String getName(); void setName(String name); String getDescription(); void setDescription(String description); String getDisplayName(); String getPackageVersion(); String getTimestamp(); String getLongDescription(); String getAppNGVersion(); boolean isInstalled(); boolean isSnapshot(); boolean isFileBased(); void setFileBased(boolean fileBased); Date getVersion(); void setVersion(Date version); Set<Permission> getPermissions(); void setPermissions(Set<Permission> permissions); Set<Role> getRoles(); void setRoles(Set<Role> roles); Properties getProperties(); void setProperties(Properties properties); void setContext(ConfigurableApplicationContext applicationContext); T getBean(String name, Class<T> clazz); T getBean(Class<T> clazz); Object getBean(String beanName); String[] getBeanNames(Class<?> clazz); boolean isPrivileged(); @Deprecated boolean isCoreApplication(); void setPrivileged(boolean isPrivileged); String getMessage(Locale locale, String key, Object... args); List<JarInfo> getJarInfos(); @Override int hashCode(); @Override boolean equals(Object o); @Override String toString(); void closeContext(); void setResources(Resources applicationResourceHolder); Resources getResources(); boolean isHidden(); boolean containsBean(String beanName); ApplicationConfigProvider getApplicationConfig(); String getSessionParamKey(Site site); Map<String, String> getSessionParams(Site site, Environment environment); FeatureProvider getFeatureProvider(); void setFeatureProvider(FeatureProvider featureProvider); List<ApplicationSubject> getApplicationSubjects(); ApplicationRequest getApplicationRequest(HttpServletRequest servletRequest, HttpServletResponse servletResponse); ApplicationRequest getApplicationRequest(HttpServletRequest servletRequest, HttpServletResponse servletResponse, boolean createNew); Action processAction(HttpServletResponse servletResponse, boolean applyPermissionsOnRef, ApplicationRequest applicationRequest, String actionId, String eventId, MarshallService marshallService); Datasource processDataSource(HttpServletResponse servletResponse, boolean applyPermissionsOnRef, ApplicationRequest applicationRequest, String dataSourceId, MarshallService marshallService); ConfigurableApplicationContext getContext(); @Override Application getApplication(); @Override Site getSite(); Set<Resource> getResourceSet(); @Override void setDatabaseConnection(DatabaseConnection databaseConnection); @Override DatabaseConnection getDatabaseConnection(); void setPlatformScope(); void setPlatformScope(boolean enabled); }
@Test public void testCallDataSourceEntity() throws Exception { addParameter("entityId", "1"); initParameters(); Datasource datasource = applicationProvider.processDataSource(servletResponse, true, request, "entity", marshallService); String resultXML = marshallService.marshallNonRoot(datasource, Datasource.class); WritingXmlValidator.validateXml(resultXML, "xml/" + getClass().getSimpleName() + "-testCallDataSourceEntity.xml"); } @Test public void testCallDataSourceEntities() throws Exception { addParameter("sortEntities", "pageSize:2"); initParameters(); Datasource datasource = applicationProvider.processDataSource(servletResponse, true, request, "entities", marshallService); String resultXML = marshallService.marshallNonRoot(datasource, Datasource.class); WritingXmlValidator.validateXml(resultXML, "xml/" + getClass().getSimpleName() + "-testCallDataSourceEntities.xml"); } @Test public void testCallDataSourceNotFound() throws Exception { Datasource datasource = applicationProvider.processDataSource(servletResponse, true, request, "undefined", marshallService); Assert.assertNull(datasource); Assert.assertEquals(HttpStatus.NOT_FOUND.value(), servletResponse.getStatus()); }
ApplicationProvider extends SiteApplication implements AccessibleApplication { public Action processAction(HttpServletResponse servletResponse, boolean applyPermissionsOnRef, ApplicationRequest applicationRequest, String actionId, String eventId, MarshallService marshallService) throws InvalidConfigurationException, ProcessingException { ApplicationConfigProvider applicationConfigProvider = getApplicationConfig().cloneConfig(marshallService); applicationRequest.setApplicationConfig(applicationConfigProvider); Action action = applicationConfigProvider.getAction(eventId, actionId); if (null == action) { LOGGER.debug("Action {}:{} not found on application {} of site {}", eventId, actionId, application.getName(), site.getName()); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); return null; } Environment environment = applicationRequest.getEnvironment(); if (permissionsPresent(action.getConfig()) || environment.isSubjectAuthenticated()) { Params params = action.getConfig().getParams(); ActionRef actionRef = new ActionRef(); actionRef.setEventId(eventId); actionRef.setId(actionId); actionRef.setParams(params); if (applyPermissionsOnRef) { actionRef.setPermissions(action.getConfig().getPermissions()); } setParamValues(applicationRequest, params); CallableAction callableAction = new CallableAction(site, application, applicationRequest, actionRef); if (callableAction.doInclude() || callableAction.doExecute()) { LOGGER.debug("Performing action {}:{} of application {} on site {}", eventId, actionId, application.getName(), site.getName()); callableAction.perform(false); Messages messages = elementHelper.removeMessages(environment); if (null != messages) { messages.setRef(actionId); action.setMessages(messages); } return action; } LOGGER.debug("Include condition for action {}:{} of application {} on site {} does not match.", eventId, actionId, application.getName(), site.getName()); } Subject subject = environment.getSubject(); LOGGER.debug( "Action {}:{} of application {} on site {} neither defines permissions, nor is the subject authenticated (subject is {}). Sending 403.", eventId, actionId, application.getName(), site.getName(), subject == null ? "<unknown>" : subject.getAuthName()); servletResponse.setStatus(HttpStatus.FORBIDDEN.value()); return null; } ApplicationProvider(Site site, Application application, boolean monitorPerformance); ApplicationProvider(Site site, Application application); ApplicationReference process(ApplicationRequest applicationRequest, MarshallService marshallService, Path pathInfo, PlatformConfig platformConfig); void setApplicationConfig(ApplicationConfigProvider applicationConfig); Integer getId(); void setId(Integer id); String getName(); void setName(String name); String getDescription(); void setDescription(String description); String getDisplayName(); String getPackageVersion(); String getTimestamp(); String getLongDescription(); String getAppNGVersion(); boolean isInstalled(); boolean isSnapshot(); boolean isFileBased(); void setFileBased(boolean fileBased); Date getVersion(); void setVersion(Date version); Set<Permission> getPermissions(); void setPermissions(Set<Permission> permissions); Set<Role> getRoles(); void setRoles(Set<Role> roles); Properties getProperties(); void setProperties(Properties properties); void setContext(ConfigurableApplicationContext applicationContext); T getBean(String name, Class<T> clazz); T getBean(Class<T> clazz); Object getBean(String beanName); String[] getBeanNames(Class<?> clazz); boolean isPrivileged(); @Deprecated boolean isCoreApplication(); void setPrivileged(boolean isPrivileged); String getMessage(Locale locale, String key, Object... args); List<JarInfo> getJarInfos(); @Override int hashCode(); @Override boolean equals(Object o); @Override String toString(); void closeContext(); void setResources(Resources applicationResourceHolder); Resources getResources(); boolean isHidden(); boolean containsBean(String beanName); ApplicationConfigProvider getApplicationConfig(); String getSessionParamKey(Site site); Map<String, String> getSessionParams(Site site, Environment environment); FeatureProvider getFeatureProvider(); void setFeatureProvider(FeatureProvider featureProvider); List<ApplicationSubject> getApplicationSubjects(); ApplicationRequest getApplicationRequest(HttpServletRequest servletRequest, HttpServletResponse servletResponse); ApplicationRequest getApplicationRequest(HttpServletRequest servletRequest, HttpServletResponse servletResponse, boolean createNew); Action processAction(HttpServletResponse servletResponse, boolean applyPermissionsOnRef, ApplicationRequest applicationRequest, String actionId, String eventId, MarshallService marshallService); Datasource processDataSource(HttpServletResponse servletResponse, boolean applyPermissionsOnRef, ApplicationRequest applicationRequest, String dataSourceId, MarshallService marshallService); ConfigurableApplicationContext getContext(); @Override Application getApplication(); @Override Site getSite(); Set<Resource> getResourceSet(); @Override void setDatabaseConnection(DatabaseConnection databaseConnection); @Override DatabaseConnection getDatabaseConnection(); void setPlatformScope(); void setPlatformScope(boolean enabled); }
@Test public void testCallAction() throws Exception { addParameter("action", "create"); addParameter("form_action", "create"); addParameter("name", "new name"); initParameters(); Action action = applicationProvider.processAction(servletResponse, true, request, "create", "events", marshallService); String resultXML = marshallService.marshallNonRoot(action, Action.class); WritingXmlValidator.validateXml(resultXML, "xml/" + getClass().getSimpleName() + "-testCallAction.xml"); } @Test public void testCallActionNotFound() throws Exception { Action action = applicationProvider.processAction(servletResponse, true, request, "foo", "bar", marshallService); Assert.assertNull(action); Assert.assertEquals(HttpStatus.NOT_FOUND.value(), servletResponse.getStatus()); }
RepositoryUtils { public static boolean isSnapshot(String name) { return name.contains(SNAPSHOT); } private RepositoryUtils(); static String getContextPath(); static boolean isNewer(PackageVersion versionA, PackageVersion versionB); static boolean isNewer(PackageInfo packageA, PackageInfo packageB); static Comparator<PackageInfo> getVersionComparator(); static Date getDate(PackageInfo packageInfo); static boolean isSnapshot(String name); static PackageArchive getPackage(Repository repo, File file, String archiveName); static final String SNAPSHOT; }
@Test public void testIsSnapshot() { Assert.assertFalse(RepositoryUtils.isSnapshot("snapshot")); Assert.assertFalse(RepositoryUtils.isSnapshot("SNAPSHOT")); Assert.assertFalse(RepositoryUtils.isSnapshot("sNaPsHoT")); Assert.assertTrue(RepositoryUtils.isSnapshot(RepositoryUtils.SNAPSHOT)); }
RepositoryUtils { public static Date getDate(PackageInfo packageInfo) { try { return FDF.parse(packageInfo.getTimestamp()); } catch (ParseException e) { return new Date(0L); } } private RepositoryUtils(); static String getContextPath(); static boolean isNewer(PackageVersion versionA, PackageVersion versionB); static boolean isNewer(PackageInfo packageA, PackageInfo packageB); static Comparator<PackageInfo> getVersionComparator(); static Date getDate(PackageInfo packageInfo); static boolean isSnapshot(String name); static PackageArchive getPackage(Repository repo, File file, String archiveName); static final String SNAPSHOT; }
@Test public void testGetDate() { ApplicationInfo app = new ApplicationInfo(); app.setTimestamp("19700101-0100"); Date date = RepositoryUtils.getDate(app); Assert.assertEquals(0, date.getTime()); }
RepositoryUtils { public static Comparator<PackageInfo> getVersionComparator() { return (p1, p2) -> { int compared = 0; if (Version.isValidVersion(p1.getVersion()) && Version.isValidVersion(p2.getVersion())) { compared = Version.parseVersion(p1.getVersion(), true) .compareTo(Version.parseVersion(p2.getVersion(), true)); } if (compared == 0) { compared = StringUtils.compare(p1.getVersion(), p2.getVersion()); } if (compared == 0) { compared = getDate(p1).compareTo(getDate(p2)); } return compared * -1; }; } private RepositoryUtils(); static String getContextPath(); static boolean isNewer(PackageVersion versionA, PackageVersion versionB); static boolean isNewer(PackageInfo packageA, PackageInfo packageB); static Comparator<PackageInfo> getVersionComparator(); static Date getDate(PackageInfo packageInfo); static boolean isSnapshot(String name); static PackageArchive getPackage(Repository repo, File file, String archiveName); static final String SNAPSHOT; }
@Test public void testSemverSort() { ApplicationInfo a = new ApplicationInfo(); a.setVersion("1.14.1-SNAPSHOT"); a.setTimestamp("20190826-1159"); ApplicationInfo b = new ApplicationInfo(); b.setVersion("1.14.0-SNAPSHOT"); b.setTimestamp("20190826-1203"); ApplicationInfo c = new ApplicationInfo(); c.setVersion("1.14.0-SNAPSHOT"); c.setTimestamp("20190826-1157"); List<ApplicationInfo> arrayList = new ArrayList<>(Arrays.asList(c, b, a)); Collections.sort(arrayList, RepositoryUtils.getVersionComparator()); Assert.assertEquals(a.getTimestamp(), arrayList.get(0).getTimestamp()); Assert.assertEquals(b.getTimestamp(), arrayList.get(1).getTimestamp()); Assert.assertEquals(c.getTimestamp(), arrayList.get(2).getTimestamp()); }
StringNormalizer { public static String removeNonPrintableCharacters(final String value) { return replaceNonPrintableCharacters(value, StringUtils.EMPTY); } static final String normalize(final String input); static String removeNonPrintableCharacters(final String value); static String replaceNonPrintableCharacters(final String value, final String replacement); static final Pattern NON_PRINTABLE_CHARACTER; }
@Test public void testStripNonPrintableCharacter() { for (int c = 0; c < 32; c++) { if (c != 9 && c != 10 && c != 13) { String s = Character.toString((char) c); Assert.assertEquals("", StringNormalizer.removeNonPrintableCharacters(s)); } } int[] allowedCtrlChar = { 9, 10, 13 }; for (int c : allowedCtrlChar) { String s = Character.toString((char) c); Assert.assertEquals(s, StringNormalizer.removeNonPrintableCharacters(s)); } for (int c = 32; c < 127; c++) { String s = Character.toString((char) c); Assert.assertEquals(s, StringNormalizer.removeNonPrintableCharacters(s)); } for (int c = 127; c < 160; c++) { String s = Character.toString((char) c); Assert.assertEquals(StringUtils.EMPTY, StringNormalizer.removeNonPrintableCharacters(s)); } for (int c = 160; c < 65535; c++) { String s = Character.toString((char) c); Assert.assertEquals(s, StringNormalizer.removeNonPrintableCharacters(s)); } }
RepositoryUtils { public static boolean isNewer(PackageVersion versionA, PackageVersion versionB) { if (null == versionB) { return true; } else { return isNewer(versionA.getPackageInfo(), versionB.getPackageInfo()); } } private RepositoryUtils(); static String getContextPath(); static boolean isNewer(PackageVersion versionA, PackageVersion versionB); static boolean isNewer(PackageInfo packageA, PackageInfo packageB); static Comparator<PackageInfo> getVersionComparator(); static Date getDate(PackageInfo packageInfo); static boolean isSnapshot(String name); static PackageArchive getPackage(Repository repo, File file, String archiveName); static final String SNAPSHOT; }
@Test public void testIsNewer() { ApplicationInfo v1_0_0_a = new ApplicationInfo(); v1_0_0_a.setVersion("1.0.0"); v1_0_0_a.setTimestamp("20180111-0416"); ApplicationInfo v1_0_0_b = new ApplicationInfo(); v1_0_0_b.setVersion("1.0.0"); v1_0_0_b.setTimestamp("20180111-1016"); ApplicationInfo v1_0_0_snapshot = new ApplicationInfo(); v1_0_0_snapshot.setVersion("1.0.0-SNAPSHOT"); v1_0_0_snapshot.setTimestamp("20180111-1116"); ApplicationInfo v1_1_0 = new ApplicationInfo(); v1_1_0.setVersion("1.1.0"); v1_1_0.setTimestamp("20180111-1416"); ApplicationInfo v2_0_0 = new ApplicationInfo(); v2_0_0.setVersion("2.0.0"); v2_0_0.setTimestamp("20180111-1216"); Assert.assertFalse(RepositoryUtils.isNewer(v1_0_0_snapshot, v1_0_0_b)); Assert.assertFalse(RepositoryUtils.isNewer(v1_0_0_b, v1_0_0_b)); Assert.assertFalse(RepositoryUtils.isNewer(v1_0_0_a, v1_0_0_a)); Assert.assertFalse(RepositoryUtils.isNewer(v1_0_0_a, v1_0_0_b)); Assert.assertFalse(RepositoryUtils.isNewer(v1_0_0_a, v2_0_0)); Assert.assertFalse(RepositoryUtils.isNewer(v1_0_0_b, v2_0_0)); Assert.assertFalse(RepositoryUtils.isNewer(v1_1_0, v2_0_0)); Assert.assertTrue(RepositoryUtils.isNewer(v1_0_0_b, v1_0_0_a)); Assert.assertTrue(RepositoryUtils.isNewer(v1_1_0, v1_0_0_a)); Assert.assertTrue(RepositoryUtils.isNewer(v1_1_0, v1_0_0_b)); Assert.assertTrue(RepositoryUtils.isNewer(v2_0_0, v1_0_0_a)); Assert.assertTrue(RepositoryUtils.isNewer(v2_0_0, v1_0_0_b)); Assert.assertTrue(RepositoryUtils.isNewer(v2_0_0, v1_1_0)); ApplicationInfo v0_9_0 = new ApplicationInfo(); v0_9_0.setVersion("0.9.0"); ApplicationInfo v0_40_0 = new ApplicationInfo(); v0_40_0.setVersion("0.40.0"); Assert.assertTrue(RepositoryUtils.isNewer(v0_40_0, v0_9_0)); Assert.assertTrue(RepositoryUtils.isNewer(v0_40_0, v0_9_0)); Assert.assertTrue(RepositoryUtils.isNewer(v0_40_0, v0_9_0)); } @Test public void testIsNewerNotSemVer() { ApplicationInfo v1_0 = new ApplicationInfo(); v1_0.setVersion("1.0-SNAPSHOT"); v1_0.setTimestamp("20180111-0416"); ApplicationInfo v1_0_ = new ApplicationInfo(); v1_0_.setVersion("1.0-SNAPSHOT"); v1_0_.setTimestamp("20180111-0816"); ApplicationInfo v1_1 = new ApplicationInfo(); v1_1.setVersion("1.1-SNAPSHOT"); v1_1.setTimestamp("20180111-1016"); Assert.assertTrue(RepositoryUtils.isNewer(v1_0_, v1_0)); Assert.assertFalse(RepositoryUtils.isNewer(v1_0, v1_0_)); Assert.assertFalse(RepositoryUtils.isNewer(v1_0_, v1_1)); Assert.assertTrue(RepositoryUtils.isNewer(v1_1, v1_0)); Assert.assertFalse(RepositoryUtils.isNewer(v1_0, v1_1)); }
CacheProvider { protected File getCache() { return mkdir(cache); } CacheProvider(Properties platformConfig); CacheProvider(Properties platformConfig, boolean changeOwner); void clearCache(Site site); void clearCache(Site site, String application); File getPlatformCache(Nameable site, Nameable application); String getRelativePlatformCache(Nameable site, Nameable application); File getImageCache(Nameable site, Nameable application); }
@Test public void testgetCache() { File cache = cacheProvider.getCache(); Assert.assertEquals(cacheRoot, cache); }
CacheProvider { public void clearCache(Site site) { clear(getPlatformCache(site)); clear(getApplicationCache(site)); } CacheProvider(Properties platformConfig); CacheProvider(Properties platformConfig, boolean changeOwner); void clearCache(Site site); void clearCache(Site site, String application); File getPlatformCache(Nameable site, Nameable application); String getRelativePlatformCache(Nameable site, Nameable application); File getImageCache(Nameable site, Nameable application); }
@Test public void testClearCache() { File platformSite = new File("target/WEB-INF/cache/platform/" + sitename); File appSite = new File("target/WEB-INF/cache/application/" + sitename); Assert.assertTrue(platformSite.exists()); Assert.assertTrue(appSite.exists()); cacheProvider.clearCache(site); Assert.assertFalse(platformSite.exists()); Assert.assertFalse(appSite.exists()); } @Test public void testClearApplicationCache() { Assert.assertTrue(platformCache.exists()); Assert.assertTrue(applicationCache.exists()); cacheProvider.clearCache(site, applicationName); Assert.assertTrue(applicationRoot.exists()); Assert.assertTrue(platformRoot.exists()); Assert.assertFalse(platformCache.exists()); Assert.assertFalse(applicationCache.exists()); }
CacheProvider { protected File getPlatformCache() { return mkdir(platform); } CacheProvider(Properties platformConfig); CacheProvider(Properties platformConfig, boolean changeOwner); void clearCache(Site site); void clearCache(Site site, String application); File getPlatformCache(Nameable site, Nameable application); String getRelativePlatformCache(Nameable site, Nameable application); File getImageCache(Nameable site, Nameable application); }
@Test public void testgetPlatformCache() { FileUtils.deleteQuietly(platformCache); File cache = cacheProvider.getPlatformCache(sitename, applicationName).getAbsoluteFile(); Assert.assertEquals(platformCache, cache); }
CacheProvider { public String getRelativePlatformCache(Nameable site, Nameable application) { String applicationCache = getPlatformCache(site.getName(), application.getName()).getAbsolutePath(); return applicationCache.substring(prefixLength); } CacheProvider(Properties platformConfig); CacheProvider(Properties platformConfig, boolean changeOwner); void clearCache(Site site); void clearCache(Site site, String application); File getPlatformCache(Nameable site, Nameable application); String getRelativePlatformCache(Nameable site, Nameable application); File getImageCache(Nameable site, Nameable application); }
@Test public void testGetRelativePlatformCache() { String cache = cacheProvider.getRelativePlatformCache(site, application); Assert.assertEquals(new File("/WEB-INF/cache/platform/appNG/foobar").getPath(), cache); }
CacheProvider { public File getImageCache(Nameable site, Nameable application) { return mkdir(getImageCache(site.getName(), application.getName())); } CacheProvider(Properties platformConfig); CacheProvider(Properties platformConfig, boolean changeOwner); void clearCache(Site site); void clearCache(Site site, String application); File getPlatformCache(Nameable site, Nameable application); String getRelativePlatformCache(Nameable site, Nameable application); File getImageCache(Nameable site, Nameable application); }
@Test public void testGetImageCache() { File cache = cacheProvider.getImageCache(site, application).getAbsoluteFile(); Assert.assertEquals(new File(applicationCache, "images"), cache); }
PageParameterProcessor { boolean processPageParams(List<String> applicationUrlParameters, UrlSchema urlSchema) { processPostParams(urlSchema.getPostParams()); processGetParams(urlSchema.getGetParams()); boolean urlParamsAdded = processUrlParams(applicationUrlParameters, urlSchema.getUrlParams()); processSessionParams(); return urlParamsAdded; } PageParameterProcessor(String sessionParamKey, Set<String> sessionParamNames, Environment env, Request request); }
@Test public void testApplicationUrlParameter() throws Exception { Mockito.when(request.getParameter(ACTION)).thenReturn(null); Mockito.when(request.getParameter(PARAM2)).thenReturn("asasd"); Mockito.when(request.isGet()).thenReturn(true); applicationUrlParameter.add("actionFromUrl"); UrlSchema urlSchema = getUrlSchema(); Param user = new Param(); user.setName("user"); urlSchema.getGetParams().getParamList().add(user); Param hash = new Param(); hash.setName(HASH); urlSchema.getGetParams().getParamList().add(hash); sessionParams.put(HASH, ""); sessionParamNames.add(HASH); boolean urlParamAdded = ppp.processPageParams(applicationUrlParameter, urlSchema); Mockito.verify(env, Mockito.atLeast(1)).getAttribute(SESSION, "key"); Assert.assertFalse(urlParamAdded); validateXml(urlSchema, getClass().getSimpleName() + "-"); } @Test public void testApplicationUrlParameterFromSession() throws Exception { Mockito.when(request.getParameter(ACTION)).thenReturn(null); Mockito.when(request.getParameter(PARAM2)).thenReturn("47"); Mockito.when(request.isGet()).thenReturn(true); UrlSchema urlSchema = getUrlSchema(); Param user = new Param(); user.setName("user"); urlSchema.getGetParams().getParamList().add(user); Param hash = new Param(); hash.setName(HASH); urlSchema.getUrlParams().getParamList().add(hash); sessionParams.put(HASH, "hashFromSession"); sessionParamNames.add(HASH); boolean urlParamAdded = ppp.processPageParams(applicationUrlParameter, urlSchema); Mockito.verify(env, Mockito.atLeast(1)).getAttribute(SESSION, "key"); Assert.assertTrue(urlParamAdded); validateXml(urlSchema, getClass().getSimpleName() + "-"); } @Test public void testGetBeforeUrl() throws Exception { Mockito.when(request.isGet()).thenReturn(true); UrlSchema urlSchema = getUrlSchema(); Param user = new Param(); user.setName("user"); urlSchema.getGetParams().getParamList().add(user); Param hash = new Param(); hash.setName(HASH); urlSchema.getGetParams().getParamList().add(hash); sessionParams.put(HASH, ""); sessionParamNames.add(HASH); boolean urlParamAdded = ppp.processPageParams(applicationUrlParameter, urlSchema); Mockito.verify(env, Mockito.atLeast(1)).getAttribute(SESSION, "key"); Assert.assertFalse(urlParamAdded); validateXml(urlSchema, getClass().getSimpleName() + "-"); } @Test public void testPostOverGet() throws Exception { Mockito.when(request.isPost()).thenReturn(true); UrlSchema urlSchema = getUrlSchema(); boolean urlParamAdded = ppp.processPageParams(applicationUrlParameter, urlSchema); Mockito.verify(env, Mockito.atLeast(1)).getAttribute(SESSION, "key"); Assert.assertFalse(urlParamAdded); validateXml(urlSchema, getClass().getSimpleName() + "-"); } @Test public void testSession() throws Exception { sessionParams.put(ACTION, "fooAction"); sessionParamNames.add(ACTION); Mockito.when(request.getParameter(ACTION)).thenReturn(null); Mockito.when(request.isGet()).thenReturn(true); UrlSchema urlSchema = getUrlSchema(); boolean urlParamAdded = ppp.processPageParams(applicationUrlParameter, urlSchema); Mockito.verify(env, Mockito.atLeast(1)).getAttribute(SESSION, "key"); Assert.assertFalse(urlParamAdded); validateXml(urlSchema, getClass().getSimpleName() + "-"); }
PropertyConstantCreator { public static void main(String[] args) throws IOException { if (args.length < 3) { throw new IllegalArgumentException( "at least 3 parameters needed: filePath* targetClass* outFolder* [charset]"); } String filePath = args[0]; String targetClass = args[1]; String outfolder = args[2]; String charSet = StandardCharsets.UTF_8.name(); if (args.length == 4) { charSet = args[3]; } if (!targetClass.matches("([a-zA-Z]+[0-9]*)+(\\.[a-zA-Z]+[0-9]*)*")) { throw new IllegalArgumentException("not a valid classname: " + targetClass); } Properties props = new Properties(); props.load(new InputStreamReader(new FileInputStream(filePath), charSet)); int pckg = targetClass.lastIndexOf("."); String lineBreak = System.lineSeparator(); StringBuilder sb = new StringBuilder(); if (pckg > 0) { sb.append("package " + targetClass.substring(0, pckg) + ";"); sb.append(lineBreak); sb.append(lineBreak); } sb.append("public class " + targetClass.substring(pckg + 1) + " {"); sb.append(lineBreak); sb.append(lineBreak); Set<Object> keySet = new TreeSet<>(props.keySet()); for (Object object : keySet) { String key = (String) object; sb.append("\t", "*&#47;") + " */" + lineBreak); sb.append("\tpublic static final String "); String constantName = key.replace('-', '_').replace('.', '_'); String[] tokens = StringUtils.splitByCharacterTypeCamelCase(constantName); for (int i = 0; i < tokens.length; i++) { String s = tokens[i]; if (!"_".equals(s)) { if (i > 0) { sb.append("_"); } sb.append(s.toUpperCase()); } } sb.append(" = \"" + key + "\";"); sb.append(lineBreak); } sb.append(lineBreak); sb.append("}"); String fileName = targetClass.replace('.', '/') + ".java"; File outFile = new File(new File(outfolder).getAbsoluteFile(), fileName); outFile.getParentFile().mkdirs(); try (FileOutputStream fos = new FileOutputStream(outFile)) { fos.write(sb.toString().getBytes(StandardCharsets.UTF_8)); } } static void main(String[] args); }
@Test public void test() throws IOException { String className = "org.appng.tools.file.Constants"; String path = className.replace('.', '/') + ".java"; String target = "target/constants/"; PropertyConstantCreator.main(new String[] { "src/test/resources/props.properties", className, target }); List<String> expected = Files.readAllLines(new File("src/test/resources/" + path.substring(path.lastIndexOf('/'))).toPath()); List<String> actual = Files.readAllLines(new File(target + path).toPath()); Assert.assertEquals(expected, actual); }
PlatformTransformer { public String transform(ApplicationProvider applicationProvider, Properties platformProperties, String platformXML, String charSet, File debugFolder) throws IOException, TransformerException { InputStream xmlSourceIn = new ByteArrayInputStream(platformXML.getBytes()); StreamSource xmlSource = new StreamSource(xmlSourceIn); boolean deleteIncludes = false; for (Template template : outputType.getTemplates()) { if (outputTypeMatches(template)) { String reference = template.getPath(); String xslPath = new File(templatePath, "xsl").getAbsolutePath(); InputStream xslSource = new FileInputStream(new File(xslPath, reference)); if (MASTER_TYPE.equals(template.getType())) { deleteIncludes = Boolean.TRUE.equals(template.isDeleteIncludes()); getStyleSheetProvider().setMasterSource(xslSource, xslPath); getStyleSheetProvider().setName(reference); getStyleSheetProvider().setInsertBefore(INSERTION_NODE); } else { getStyleSheetProvider().addStyleSheet(xslSource, templatePath + ":" + reference); } } } Boolean devMode = platformProperties.getBoolean(org.appng.api.Platform.Property.DEV_MODE); for (Template template : templates) { if (outputTypeMatches(template)) { String fileName = template.getPath(); Resources applicationResourceHolder = applicationProvider.getResources(); Resource resource = applicationResourceHolder.getResource(ResourceType.XSL, fileName); if (null == resource) { LOGGER.warn("missing resource: no resource named '{}' is assigned to application '{}'", fileName, applicationProvider.getName()); } else { if (devMode) { File cachedFile = resource.getCachedFile(); LOGGER.debug("devMode is active, reading from cached file {}", cachedFile.getAbsolutePath()); styleSheetProvider.addStyleSheet(new FileInputStream(cachedFile), applicationProvider.getName() + ":" + fileName); } else { styleSheetProvider.addStyleSheet(new ByteArrayInputStream(resource.getBytes()), applicationProvider.getName() + ":" + fileName); } } } } SourceAwareTemplate sourceAwareTemplate = null; String styleId = styleSheetProvider.getId(); String result = null; TransformerException transformerException = null; Boolean writeDebugFiles = platformProperties.getBoolean(org.appng.api.Platform.Property.WRITE_DEBUG_FILES); try { ErrorCollector errorCollector = new ErrorCollector(); if (!devMode && STYLESHEETS.containsKey(styleId)) { sourceAwareTemplate = STYLESHEETS.get(styleId); styleSheetProvider.cleanup(); LOGGER.debug("reading templates from cache (id: {})", styleId); } else { byte[] xslData = styleSheetProvider.getStyleSheet(deleteIncludes, null); ByteArrayInputStream templateInputStream = new ByteArrayInputStream(xslData); Source xslSource = new StreamSource(templateInputStream); TransformerFactory transformerFactory = styleSheetProvider.getTransformerFactory(); transformerFactory.setErrorListener(errorCollector); try { Templates templates = transformerFactory.newTemplates(xslSource); sourceAwareTemplate = new SourceAwareTemplate(templates, templateInputStream); } catch (TransformerConfigurationException tce) { sourceAwareTemplate = new SourceAwareTemplate(null, templateInputStream); sourceAwareTemplate.errorCollector = errorCollector; for (TransformerException t : errorCollector.exceptions) { LOGGER.error(t.getMessage(), t); } if (!devMode) { STYLESHEETS.put(styleId, sourceAwareTemplate); } LOGGER.debug("writing templates to cache (id: {})", styleId); } } if (!errorCollector.hasErrors()) { Boolean formatOutput = platformProperties.getBoolean(org.appng.api.Platform.Property.FORMAT_OUTPUT); result = transform(xmlSource, sourceAwareTemplate, formatOutput); this.contentType = HttpHeaders.getContentType(HttpHeaders.CONTENT_TYPE_TEXT_HTML, charSet); if (writeDebugFiles) { writeDebugFile(AbstractRequestProcessor.INDEX_HTML, result, debugFolder); } } else { throw errorCollector.exceptions.get(0); } } catch (TransformerException te) { transformerException = new PlatformTransformerException(te, sourceAwareTemplate); throw transformerException; } finally { if (null != transformerException || writeDebugFiles) { writeDebugFiles(debugFolder, platformXML, sourceAwareTemplate, transformerException); } } return result; } PlatformTransformer(); String transform(ApplicationProvider applicationProvider, Properties platformProperties, String platformXML, String charSet, File debugFolder); StyleSheetProvider getStyleSheetProvider(); void setStyleSheetProvider(StyleSheetProvider styleSheetProvider); void addTemplates(List<Template> templates); Environment getEnvironment(); void setEnvironment(Environment environment); Platform getPlatform(MarshallService marshallService, Path path); String getContentType(); void setTemplatePath(String templatePath); static synchronized void clearCache(); OutputFormat getOutputFormat(); void setOutputFormat(OutputFormat outputFormat); OutputType getOutputType(); void setOutputType(OutputType outputType); }
@Test public void test() throws Exception { init(platformTransformer, TEMPLATE_PATH); transform(); } @Test public void testDevMode() throws Exception { init(platformTransformer, TEMPLATE_PATH); transform(); }
TemplateService { public org.appng.xml.application.Template getTemplate(String templateDir) throws IOException, JAXBException { return validateResource(MarshallService.getApplicationMarshallService(), TEMPLATE_XML, new FileInputStream(new File(templateDir, TEMPLATE_XML)), org.appng.xml.application.Template.class); } ZipFileProcessor<Template> getTemplateExtractor(); static ZipFileProcessor<org.appng.xml.application.Template> getTemplateInfo(final String originalFilename); List<Identifier> getInstalledTemplates(); static void materializeTemplate(Template template, Properties platformConfig, Properties siteProps); static void copyTemplate(Properties platformConfig, Properties siteProps, String templateRealPath); Template installTemplate(PackageArchive packageArchive); Template getTemplateByDisplayName(String name); Template getTemplateByName(String name); Integer deleteTemplate(Template template); static File getTemplateRepoFolder(Properties platformConfig, Properties siteProps); org.appng.xml.application.Template getTemplate(String templateDir); static final String PLATFORM_XML; }
@Test public void testGetTemplate() throws Exception { Template template = service.getTemplate("target/test-classes/template/appng"); Assert.assertEquals(TemplateType.XSL, template.getType()); Assert.assertEquals("appng-template", template.getName()); Assert.assertEquals("0.8.0", template.getVersion()); Assert.assertEquals("appNG Template", template.getDisplayName()); Assert.assertEquals("0.13.0", template.getAppngVersion()); }
TemplateService { public ZipFileProcessor<Template> getTemplateExtractor() { ZipFileProcessor<Template> templateExtractor = new ZipFileProcessor<Template>() { public Template process(ZipFile zipFile) throws IOException { org.appng.xml.application.Template templateXml = null; List<TemplateResource> resources = new ArrayList<>(); try { Enumeration<ZipArchiveEntry> entries = zipFile.getEntriesInPhysicalOrder(); MarshallService applicationMarshallService = MarshallService.getApplicationMarshallService(); while (entries.hasMoreElements()) { ZipArchiveEntry entry = entries.nextElement(); String path = entry.getName(); path = path.substring(path.indexOf('/') + 1); if (!entry.isDirectory()) { try ( InputStream in = zipFile.getInputStream(entry); ByteArrayOutputStream out = new ByteArrayOutputStream()) { try { IOUtils.copy(in, out); TemplateResource templateResource = new TemplateResource(); templateResource.setName(path); templateResource.setFileVersion(entry.getLastModifiedDate()); templateResource.setResourceType(ResourceType.RESOURCE); templateResource.setBytes(out.toByteArray()); templateResource.calculateChecksum(); resources.add(templateResource); if (path.equals(TEMPLATE_XML)) { templateXml = applicationMarshallService.unmarshall( new ByteArrayInputStream(templateResource.getBytes()), org.appng.xml.application.Template.class); } } catch (IOException ioe) { throw ioe; } } LOGGER.info("added resource {}", path); } } } catch (JAXBException e) { throw new IOException(e); } ZipFile.closeQuietly(zipFile); Template template = new Template(templateXml); for (TemplateResource templateResource : resources) { templateResource.setTemplate(template); template.getResources().add(templateResource); } return template; } }; return templateExtractor; } ZipFileProcessor<Template> getTemplateExtractor(); static ZipFileProcessor<org.appng.xml.application.Template> getTemplateInfo(final String originalFilename); List<Identifier> getInstalledTemplates(); static void materializeTemplate(Template template, Properties platformConfig, Properties siteProps); static void copyTemplate(Properties platformConfig, Properties siteProps, String templateRealPath); Template installTemplate(PackageArchive packageArchive); Template getTemplateByDisplayName(String name); Template getTemplateByName(String name); Integer deleteTemplate(Template template); static File getTemplateRepoFolder(Properties platformConfig, Properties siteProps); org.appng.xml.application.Template getTemplate(String templateDir); static final String PLATFORM_XML; }
@Test public void testTemplateExtractor() throws Exception { ZipFileProcessor<org.appng.core.domain.Template> templateExtractor = service.getTemplateExtractor(); org.appng.core.domain.Template processed = templateExtractor.process(new ZipFile(templateZip)); verifyTemplate(processed); }
TemplateService { public Template installTemplate(PackageArchive packageArchive) throws BusinessException { try { ZipFileProcessor<Template> templateExtractor = getTemplateExtractor(); Template template = packageArchive.processZipFile(templateExtractor); Template existing = templateRepository.findByName(template.getName()); if (null == existing) { templateRepository.save(template); } else { List<TemplateResource> resources = existing.getResources(); templateResourceRepository.delete(resources); resources.clear(); existing.update(template); template = existing; } return template; } catch (IOException e) { throw new BusinessException("error while provisioning " + packageArchive.toString(), e); } } ZipFileProcessor<Template> getTemplateExtractor(); static ZipFileProcessor<org.appng.xml.application.Template> getTemplateInfo(final String originalFilename); List<Identifier> getInstalledTemplates(); static void materializeTemplate(Template template, Properties platformConfig, Properties siteProps); static void copyTemplate(Properties platformConfig, Properties siteProps, String templateRealPath); Template installTemplate(PackageArchive packageArchive); Template getTemplateByDisplayName(String name); Template getTemplateByName(String name); Integer deleteTemplate(Template template); static File getTemplateRepoFolder(Properties platformConfig, Properties siteProps); org.appng.xml.application.Template getTemplate(String templateDir); static final String PLATFORM_XML; }
@Test public void testInstall() throws Exception { org.appng.core.domain.Template installed = service.installTemplate(new PackageArchiveImpl(templateZip, true)); verifyTemplate(installed); Assert.assertNotNull(installed.getVersion()); }
InitializerService { @Transactional public void initPlatform(PlatformProperties platformConfig, Environment env, DatabaseConnection rootConnection, ServletContext ctx, ExecutorService executor) throws InvalidConfigurationException { logEnvironment(); loadPlatform(platformConfig, env, null, null, executor); addJarInfo(env, ctx); databaseService.setActiveConnection(rootConnection, false); coreService.createEvent(Type.INFO, "Started platform"); } InitializerService(); @Transactional void initPlatform(PlatformProperties platformConfig, Environment env, DatabaseConnection rootConnection, ServletContext ctx, ExecutorService executor); void reloadPlatform(java.util.Properties config, Environment env, String siteName, String target, ExecutorService executor); void loadPlatform(PlatformProperties platformConfig, Environment env, String siteName, String target, ExecutorService executor); PlatformProperties loadPlatformProperties(java.util.Properties defaultOverrides, Environment env); @Transactional synchronized void loadSite(Environment env, SiteImpl siteToLoad, FieldProcessor fp); @Transactional synchronized void loadSite(Environment env, SiteImpl siteToLoad, boolean sendReloadEvent, FieldProcessor fp); synchronized void loadSite(SiteImpl siteToLoad, ServletContext servletContext, FieldProcessor fp); synchronized void loadSite(SiteImpl siteToLoad, Environment env, boolean sendReloadEvent, FieldProcessor fp); void shutdownPlatform(ServletContext ctx); void shutDownSite(Environment env, Site site, boolean removeFromSiteMap); CoreService getCoreService(); void setCoreService(CoreService coreService); static final String APPNG_USER; static final String APPNG_GROUP; }
@Test public void testInitPlatform() throws Exception { PropertyHolder propertyHolder = new PropertyHolder(PropertySupport.PREFIX_PLATFORM, Collections.emptyList()); for (String prop : platformProperties.getPropertyNames()) { String key = prop.substring(PropertySupport.PREFIX_PLATFORM.length()); String value = platformProperties.getString(prop); String defaultValue = value == null ? StringUtils.EMPTY : value; propertyHolder.addProperty(key, defaultValue, StringUtils.EMPTY, Type.forString(defaultValue)); } propertyHolder.setFinal(); platformMap.put(Platform.Environment.PLATFORM_CONFIG, propertyHolder); File templateRoot = new File("target/test-classes/repository/site-1/www/template/"); FileUtils.deleteQuietly(templateRoot); Mockito.when(ctx.getRealPath("/uploads")).thenReturn("target/uploads"); Mockito.when(env.getAttribute(Scope.PLATFORM, Platform.Environment.SITES)).thenReturn(new HashMap<>()); Mockito.when(env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG)) .thenReturn(platformProperties); PlatformProperties platformProperties = service.loadPlatformProperties(new Properties(), env); service.loadPlatform(platformProperties, env, null, null, null); Mockito.verify(ctx, Mockito.atLeastOnce()).getRealPath(Mockito.anyString()); Mockito.verify(env, VerificationModeFactory.atLeast(1)).setAttribute(Mockito.eq(Scope.PLATFORM), Mockito.anyString(), Mockito.any()); Assert.assertTrue(new File(templateRoot, "assets/favicon.ico").exists()); Assert.assertTrue(new File(templateRoot, "resources/dummy.txt").exists()); Assert.assertFalse(new File(templateRoot, "xsl").exists()); Assert.assertFalse(new File(templateRoot, "conf").exists()); Assert.assertFalse(new File(templateRoot, "template.xml").exists()); }
InitializerService { @Transactional public synchronized void loadSite(Environment env, SiteImpl siteToLoad, FieldProcessor fp) throws InvalidConfigurationException { loadSite(env, siteToLoad, true, fp); } InitializerService(); @Transactional void initPlatform(PlatformProperties platformConfig, Environment env, DatabaseConnection rootConnection, ServletContext ctx, ExecutorService executor); void reloadPlatform(java.util.Properties config, Environment env, String siteName, String target, ExecutorService executor); void loadPlatform(PlatformProperties platformConfig, Environment env, String siteName, String target, ExecutorService executor); PlatformProperties loadPlatformProperties(java.util.Properties defaultOverrides, Environment env); @Transactional synchronized void loadSite(Environment env, SiteImpl siteToLoad, FieldProcessor fp); @Transactional synchronized void loadSite(Environment env, SiteImpl siteToLoad, boolean sendReloadEvent, FieldProcessor fp); synchronized void loadSite(SiteImpl siteToLoad, ServletContext servletContext, FieldProcessor fp); synchronized void loadSite(SiteImpl siteToLoad, Environment env, boolean sendReloadEvent, FieldProcessor fp); void shutdownPlatform(ServletContext ctx); void shutDownSite(Environment env, Site site, boolean removeFromSiteMap); CoreService getCoreService(); void setCoreService(CoreService coreService); static final String APPNG_USER; static final String APPNG_GROUP; }
@Test @Ignore("causes CoreServiceTest to fail") public void testLoadSite() throws InvalidConfigurationException, IOException { FileUtils.copyDirectory(new File("src/test/resources/applications/application1"), new File("target/root/applications/application1")); Site siteToLoad = siteMap.remove("manager"); service.loadSite((SiteImpl) siteToLoad, ctx, new FieldProcessorImpl("testLoadSite")); Application application = siteToLoad.getApplication("application1"); TestService testservice = application.getBean(TestService.class); TestEntity entity = new TestEntity(null, "name", 2, 3.4d, true); testservice.createEntity(entity); Assert.assertEquals(Integer.valueOf(1), entity.getId()); service.shutDownSite(env, siteToLoad, true); }
EmailProvider implements FormProcessProvider { public void onFormSuccess(Writer writer, Form form, Map<String, Object> properties) { String senderEMail = (String) properties.get(SENDER); String senderName = (String) properties.get(SENDER_NAME); String receiverEMail = (String) properties.get(RECEIVER_TO); String receiverEMailDebug = (String) properties.get(RECEIVER_DEBUG); String ccReceiverEMail = (String) properties.get(RECEIVER_CC); String bccReceiverEMail = (String) properties.get(RECEIVER_BCC); String replyTo = (String) properties.get(REPLY_TO); String subject = (String) properties.get(SUBJECT); String content = (String) properties.get(CONTENT); String errorMessage = (String) properties.get(ERROR_MESSAGE); String textEmail = (String) properties.get(EMAIL_CONTENT_TEXT); String htmlEmail = (String) properties.get(EMAIL_CONTENT_HTML); boolean sendDisabled = TRUE.equalsIgnoreCase((String) properties.get(SEND_DISABLED)); mailTransport.setDisableSend(sendDisabled); LOGGER.debug("sending emails is {}", sendDisabled ? "disabled" : "enabled"); boolean addAttachments = TRUE.equalsIgnoreCase((String) properties.get(ATTACHMENTS)); List<Receiver> debugReceivers = getDebugReceivers(receiverEMailDebug); try { if (StringUtils.isEmpty(senderEMail)) { throw new MailException("parameter '" + SENDER + "' is invalid: " + senderEMail); } if (StringUtils.isEmpty(subject)) { throw new MailException("parameter '" + SUBJECT + "' is invalid: " + subject); } Mail mail = mailTransport.createMail(); mail.setSubject(subject); mail.setFrom(senderEMail, senderName); if (StringUtils.isNotBlank(replyTo)) { addReplies(mail, replyTo); } if (StringUtils.isNotBlank(textEmail)) { mail.setTextContent(textEmail); } if (StringUtils.isNotBlank(htmlEmail)) { mail.setHTMLContent(htmlEmail); } addReceivers(mail, receiverEMail, org.appng.mail.Mail.RecipientType.TO); addReceivers(mail, ccReceiverEMail, org.appng.mail.Mail.RecipientType.CC); addReceivers(mail, bccReceiverEMail, org.appng.mail.Mail.RecipientType.BCC); if (addAttachments) { addAttachements(mail, form); } String mailAsString = mailTransport.getMailAsString(mail); if (debugReceivers.isEmpty()) { LOGGER.debug("sending mail: {}", mailAsString); mailTransport.send(mail); } else { Mail debugEmail = mailTransport.createMail(); for (Receiver receiver : debugReceivers) { debugEmail.addReceiver(receiver); } debugEmail.setSubject(subject); debugEmail.setFrom(senderEMail, senderName); debugEmail.setTextContent(mailAsString); addAttachements(debugEmail, form); LOGGER.debug("sending debug-mail: {}", mailTransport.getMailAsString(debugEmail)); mailTransport.send(debugEmail); } if (StringUtils.isNotBlank(content)) { writer.write(content); } } catch (Exception e) { if (StringUtils.isNotBlank(errorMessage)) { try { writer.write(errorMessage); } catch (IOException ioe) { LOGGER.error("unable to append errorMessage", ioe); } } LOGGER.error("Error occured while trying to send E-Mail.", e); } } EmailProvider(MailTransport mailTransport); void onFormSuccess(Writer writer, Form form, Map<String, Object> properties); boolean isValidReceiver(String receiverEmails); static final String RECEIVER_TO; static final String RECEIVER_CC; static final String RECEIVER_BCC; static final String SENDER; static final String SENDER_NAME; static final String SEND_DISABLED; static final String REPLY_TO; static final String SUBJECT; static final String RECEIVER_DEBUG; static final String EMAIL_CONTENT_HTML; static final String EMAIL_CONTENT_TEXT; static final String ATTACHMENTS; static final String CONTENT; static final String ERROR_MESSAGE; }
@Test public void test() throws MailException, URISyntaxException { MailTransport mailtransport = Mockito.mock(MailTransport.class); Mail mail = Mockito.mock(Mail.class); Mockito.when(mailtransport.createMail()).thenReturn(mail); EmailProvider emailProvider = new EmailProvider(mailtransport); Map<String, Object> props = new HashMap<>(); props.put(EmailProvider.SENDER, "[email protected]"); props.put(EmailProvider.SENDER_NAME, "John Doe"); props.put(EmailProvider.SUBJECT, "Foobar"); props.put(EmailProvider.EMAIL_CONTENT_HTML, "Some <bold>HTML</bold>"); props.put(EmailProvider.EMAIL_CONTENT_TEXT, "Some text"); props.put(EmailProvider.CONTENT, "some content"); props.put(EmailProvider.RECEIVER_TO, "[email protected]"); props.put(EmailProvider.RECEIVER_CC, "[email protected]"); props.put(EmailProvider.RECEIVER_BCC, "[email protected], [email protected]"); props.put(EmailProvider.REPLY_TO, "[email protected]"); props.put(EmailProvider.ATTACHMENTS, "true"); Form form = new Form(); FormElement upload = form.getFormData().addFormElement(); upload.setInputTag(InputTag.INPUT); upload.setInputType(InputType.FILE); upload.setName("upload"); URL resource = getClass().getClassLoader().getResource("images/Jellyfish.jpg"); File file = new File(resource.toURI()); FormUpload formUploadBean = new FormUploadBean(file, file.getName(), "jpg", Arrays.asList("jpg"), 10000000l); upload.setFormUploads(Arrays.asList(formUploadBean)); StringWriter writer = new StringWriter(); emailProvider.onFormSuccess(writer, form, props); Mockito.verify(mail).setFrom((String) props.get(EmailProvider.SENDER), (String) props.get(EmailProvider.SENDER_NAME)); Mockito.verify(mail).setSubject((String) props.get(EmailProvider.SUBJECT)); Mockito.verify(mail).setHTMLContent((String) props.get(EmailProvider.EMAIL_CONTENT_HTML)); Mockito.verify(mail).setTextContent((String) props.get(EmailProvider.EMAIL_CONTENT_TEXT)); Mockito.verify(mail).addReplyTo((String) props.get(EmailProvider.REPLY_TO)); Mockito.verify(mail, Mockito.times(4)).addReceiver(Mockito.any(Receiver.class)); Assert.assertEquals(props.get(EmailProvider.CONTENT), writer.toString()); Mockito.verify(mail).addAttachment(file, file.getName(), "jpg"); }
PropertySupport { public void initPlatformConfig(String rootPath, Boolean devMode) { initPlatformConfig(rootPath, devMode, new java.util.Properties(), true); } PropertySupport(PropertyHolder propertyHolder); static java.util.Properties getProperties(Properties platFormConfig, Site site, Application application, boolean addPlatformScope); static String getPropertyName(Site site, Application application, String name); static String getPropertyPrefix(Site site, Application application); static String getSitePrefix(Site site); void initSiteProperties(SiteImpl site, Properties platformConfig); void initPlatformConfig(String rootPath, Boolean devMode); void initPlatformConfig(String rootPath, Boolean devMode, java.util.Properties immutableOverrides, boolean finalize); static final String PREFIX_PLATFORM; static final String PROP_PATTERN; }
@Test public void testInitPlatformConfig() { Properties defaultOverrides = new Properties(); defaultOverrides.put(PropertySupport.PREFIX_PLATFORM + "a", "1"); defaultOverrides.put(PropertySupport.PREFIX_PLATFORM + "b", "foo"); defaultOverrides.put(PropertySupport.PREFIX_PLATFORM + "c", "foo\nbar"); defaultOverrides.put("dummy", "foo"); defaultOverrides.put(PropertySupport.PREFIX_PLATFORM + Platform.Property.FILEBASED_DEPLOYMENT, "false"); defaultOverrides.put(PropertySupport.PREFIX_PLATFORM + Platform.Property.MAIL_DISABLED, "false"); PropertyHolder platformProps = getPlatformConfig(defaultOverrides); Assert.assertFalse(platformProps.getBoolean(Platform.Property.FILEBASED_DEPLOYMENT)); Assert.assertFalse(platformProps.getBoolean(Platform.Property.MAIL_DISABLED)); Assert.assertTrue(platformProps.getBoolean(Platform.Property.DEV_MODE)); Assert.assertEquals(Integer.valueOf(1), platformProps.getInteger("a")); Assert.assertEquals("foo", platformProps.getString("b")); Assert.assertEquals("foo\nbar", platformProps.getClob("c")); Assert.assertNull(platformProps.getString("dummy")); }
PropertySupport { public void initSiteProperties(SiteImpl site, Properties platformConfig) { bundle = ResourceBundle.getBundle("org/appng/core/site-config"); String appNGData = platformConfig.getString(Platform.Property.APPNG_DATA); String repositoryPath = platformConfig.getString(Platform.Property.REPOSITORY_PATH); addSiteProperty(SiteProperties.SITE_ROOT_DIR, normalizePath(appNGData, repositoryPath, site.getName())); String passwordPolicyClass = platformConfig.getString(Platform.Property.PASSWORD_POLICY, ConfigurablePasswordPolicy.class.getName()); PasswordPolicy passwordPolicy = null; try { passwordPolicy = (PasswordPolicy) getClass().getClassLoader().loadClass(passwordPolicyClass).newInstance(); } catch (ReflectiveOperationException e) { LOGGER.error("error while instantiating " + passwordPolicyClass, e); passwordPolicy = new ConfigurablePasswordPolicy(); } LOGGER.debug("Using {} for site {}", passwordPolicy.getClass().getName(), site.getName()); passwordPolicy.configure(platformConfig); site.setPasswordPolicy(passwordPolicy); addSiteProperty(SiteProperties.NAME, site.getName()); addSiteProperty(SiteProperties.HOST, site.getHost()); addSiteProperty(SiteProperties.WWW_DIR, "/www"); String managerPath = addSiteProperty(SiteProperties.MANAGER_PATH, "/manager"); addSiteProperty(SiteProperties.SERVICE_OUTPUT_FORMAT, "html"); addSiteProperty(SiteProperties.SERVICE_OUTPUT_TYPE, "service"); addSiteProperty(SiteProperties.SERVICE_PATH, "/service"); addSiteProperty(SiteProperties.SUPPORTED_LANGUAGES, "en, de"); addSiteProperty(SiteProperties.CACHE_CLEAR_ON_SHUTDOWN, true); addSiteProperty(SiteProperties.CACHE_ENABLED, false); addSiteProperty(SiteProperties.CACHE_EXCEPTIONS, managerPath + "\r\n/health", Type.MULTILINE); addSiteProperty(SiteProperties.CACHE_TIME_TO_LIVE, 1800); addSiteProperty(SiteProperties.CACHE_TIMEOUTS, StringUtils.EMPTY, Type.MULTILINE); addSiteProperty(SiteProperties.CACHE_TIMEOUTS_ANT_STYLE, true); addSiteProperty(SiteProperties.CACHE_STATISTICS, false); addSiteProperty(SiteProperties.ERROR_PAGE, "error"); addSiteProperty(SiteProperties.ERROR_PAGES, "/de=fehler|/en=error"); addSiteProperty(SiteProperties.INDEX_DIR, "/index"); addSiteProperty(SiteProperties.INDEX_TIMEOUT, 5000); addSiteProperty(SiteProperties.INDEX_QUEUE_SIZE, 1000); addSiteProperty(SiteProperties.JDBC_CONNECTION_TIMEOUT, DataSourceFactory.DEFAULT_TIMEOUT); addSiteProperty(SiteProperties.JDBC_LOG_PERFORMANCE, false); addSiteProperty(SiteProperties.JDBC_MAX_LIFETIME, DataSourceFactory.DEFAULT_LIFE_TIME); addSiteProperty(SiteProperties.JDBC_VALIDATION_TIMEOUT, DataSourceFactory.DEFAULT_TIMEOUT); addSiteProperty(SiteProperties.SEARCH_CHUNK_SIZE, 20); addSiteProperty(SiteProperties.SEARCH_MAX_HITS, 100); addSiteProperty(Platform.Property.MAIL_HOST, "localhost"); addSiteProperty(Platform.Property.MAIL_PORT, 25); addSiteProperty(Platform.Property.MAIL_DISABLED, true); addSiteProperty(SiteProperties.INDEX_CONFIG, "/de;de;GermanAnalyzer|/assets;de;GermanAnalyzer"); addSiteProperty(SiteProperties.INDEX_FILETYPES, "jsp,pdf,doc"); addSiteProperty(SiteProperties.INDEX_FILE_SYSTEM_QUEUE_SIZE, 2500); addSiteProperty(SiteProperties.DEFAULT_PAGE, "index"); addSiteProperty(SiteProperties.DEFAULT_PAGE_SIZE, 25); addSiteProperty(SiteProperties.APPEND_TAB_ID, false); addSiteProperty(SiteProperties.ALLOW_SKIP_RENDER, false); addSiteProperty(Platform.Property.ENCODING, HttpHeaders.CHARSET_UTF8); addSiteProperty(SiteProperties.ASSETS_DIR, "/assets"); addSiteProperty(SiteProperties.DOCUMENT_DIR, "/de"); addSiteProperty(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); addSiteProperty(SiteProperties.DEFAULT_APPLICATION, "appng-manager"); addSiteProperty(Platform.Property.LOCALE, Locale.getDefault().getLanguage()); addSiteProperty(Platform.Property.TIME_ZONE, TimeZone.getDefault().getID()); addSiteProperty(SiteProperties.TEMPLATE, "appng"); addSiteProperty(SiteProperties.DATASOURCE_CONFIGURER, HikariCPConfigurer.class.getName()); addSiteProperty(SiteProperties.TAG_PREFIX, "appNG"); addSiteProperty(SiteProperties.REWRITE_CONFIG, "/meta/conf/urlrewrite.xml"); addSiteProperty(SiteProperties.SUPPORT_RELOAD_FILE, !platformConfig.getBoolean(Platform.Property.MESSAGING_ENABLED)); addSiteProperty(SiteProperties.AUTH_APPLICATION, "appng-authentication"); addSiteProperty(SiteProperties.AUTH_LOGIN_PAGE, "webform"); addSiteProperty(SiteProperties.AUTH_LOGIN_REF, "webform"); addSiteProperty(SiteProperties.AUTH_LOGOUT_ACTION_NAME, "action"); addSiteProperty(SiteProperties.AUTH_LOGOUT_ACTION_VALUE, "logout"); addSiteProperty(SiteProperties.AUTH_LOGOUT_PAGE, "webform"); addSiteProperty(SiteProperties.AUTH_LOGOUT_REF, "webform/logout"); addSiteProperty(SiteProperties.CSRF_PROTECTION_ENABLED, "false"); addSiteProperty(SiteProperties.CSRF_PROTECTED_METHODS, "POST,PUT"); addSiteProperty(SiteProperties.CSRF_PROTECTED_PATHS, "/manager"); StringBuilder xssExceptions = new StringBuilder(); xssExceptions.append("# template" + StringUtils.LF); xssExceptions.append(platformConfig.getString(Platform.Property.TEMPLATE_PREFIX) + StringUtils.LF); xssExceptions.append("# appng-manager" + StringUtils.LF); xssExceptions.append(managerPath + "/" + site.getName() + "/appng-manager" + StringUtils.LF); addSiteProperty(SiteProperties.XSS_EXCEPTIONS, xssExceptions.toString(), Type.MULTILINE); addSiteProperty(LdapService.LDAP_HOST, "ldap(s):<host>:<port>"); addSiteProperty(LdapService.LDAP_USER_BASE_DN, "OU=Users,DC=example,DC=com"); addSiteProperty(LdapService.LDAP_GROUP_BASE_DN, "OU=Groups,DC=example,DC=com"); addSiteProperty(LdapService.LDAP_USER, "serviceUser"); addSiteProperty(LdapService.LDAP_PASSWORD, "secret", Type.PASSWORD); addSiteProperty(LdapService.LDAP_DOMAIN, "EXAMPLE"); addSiteProperty(LdapService.LDAP_ID_ATTRIBUTE, "sAMAccountName"); addSiteProperty(LdapService.LDAP_PRINCIPAL_SCHEME, "SAM"); addSiteProperty(LdapService.LDAP_START_TLS, false); propertyHolder.setFinal(); } PropertySupport(PropertyHolder propertyHolder); static java.util.Properties getProperties(Properties platFormConfig, Site site, Application application, boolean addPlatformScope); static String getPropertyName(Site site, Application application, String name); static String getPropertyPrefix(Site site, Application application); static String getSitePrefix(Site site); void initSiteProperties(SiteImpl site, Properties platformConfig); void initPlatformConfig(String rootPath, Boolean devMode); void initPlatformConfig(String rootPath, Boolean devMode, java.util.Properties immutableOverrides, boolean finalize); static final String PREFIX_PLATFORM; static final String PROP_PATTERN; }
@Test public void testInitSiteProperties() { List<Property> properties = new ArrayList<>(); PropertyHolder siteProps = new PropertyHolder(PropertySupport.PREFIX_SITE, properties); PropertySupport propertySupport = new PropertySupport(siteProps); SiteImpl site = new SiteImpl(); site.setName("localhost"); site.setHost("localhost"); propertySupport.initSiteProperties(site, getPlatformConfig(new Properties())); Assert.assertEquals(Boolean.FALSE,siteProps.getObject(SiteProperties.CACHE_ENABLED)); Assert.assertFalse(siteProps.getBoolean(SiteProperties.CACHE_ENABLED)); Assert.assertEquals("localhost", siteProps.getObject(SiteProperties.HOST)); Assert.assertEquals("localhost", siteProps.getString(SiteProperties.HOST)); }
CoreService { public void addGroupsToSubject(String userName, List<String> groupNames, boolean clear) throws BusinessException { SubjectImpl subject = subjectRepository.findByName(userName); List<Integer> groupIds = groupNames.isEmpty() ? null : groupRepository.getGroupIdsForNames(groupNames); assignGroupsToSubject(subject.getId(), groupIds, clear); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testAddGroupsToSubject() throws BusinessException { List<String> groupNames = new ArrayList<>(Arrays.asList("group-1", "group-2", "group-3")); coreService.addGroupsToSubject("subject-1", groupNames, true); SubjectImpl subject = coreService.getSubjectByName("subject-1", true); for (Group group : subject.getGroups()) { groupNames.remove(group.getName()); } assertTrue(groupNames.isEmpty()); }
CoreService { public void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear) { Group group = groupRepository.findByName(groupName); if (clear) { group.getRoles().clear(); } Application application = applicationRepository.findByName(applicationName); for (String applicationRoleName : applicationRoleNames) { Role applicationRole = roleRepository.findByApplicationIdAndName(application.getId(), applicationRoleName); if (null != applicationRole) { group.getRoles().add(applicationRole); } else { throw new NoResultException( "Application '" + applicationName + "' has no role '" + applicationRoleName + "'"); } } } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testAddApplicationRolesToGroup() { coreService.addApplicationRolesToGroup("group-3", "foobar", Arrays.asList("debugger"), true); Group group = coreService.getGroupByName("group-3"); Set<Role> applicationRoles = group.getRoles(); assertEquals(1, applicationRoles.size()); assertEquals("debugger", applicationRoles.iterator().next().getName()); }
CoreService { protected void assignGroupsToSubject(Integer subjectId, List<Integer> groupIds, boolean clear) { Subject subject = subjectRepository.findOne(subjectId); if (clear) { subject.getGroups().clear(); } if (null != groupIds && !groupIds.isEmpty()) { Iterable<GroupImpl> groups = groupRepository.findAll(groupIds); for (GroupImpl group : groups) { if (!subject.getGroups().contains(group)) { subject.getGroups().add(group); group.getSubjects().add(subject); } } } } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testAssignGroupsToSubject() { List<Integer> groupIds = new ArrayList<>(Arrays.asList(1, 2, 3)); coreService.assignGroupsToSubject(1, groupIds, true); Subject subject = coreService.getSubjectById(1, true); for (Group group : subject.getGroups()) { groupIds.remove(group.getId()); } assertTrue(groupIds.isEmpty()); }
CoreService { public MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties) { SiteApplication siteApplication = new SiteApplication(site, application); siteApplication.setActive(true); siteApplication.setReloadRequired(true); siteApplication.setMarkedForDeletion(false); MigrationStatus migrationStatus = createDatabaseConnection(siteApplication); DatabaseConnection dbc = siteApplication.getDatabaseConnection(); if (!migrationStatus.isErroneous()) { siteApplicationRepository.save(siteApplication); site.getSiteApplications().add(siteApplication); auditableListener.createEvent(Type.INFO, String.format("Assigned application %s to site %s", application.getName(), site.getName())); if (MigrationStatus.DB_MIGRATED.equals(migrationStatus)) { auditableListener.createEvent(Type.INFO, String.format("Created database %s with user %s", dbc.getJdbcUrl(), dbc.getUserName())); } if (createProperties) { String prefix = PropertySupport.getPropertyPrefix(site, application); Iterable<PropertyImpl> properties = getProperties(prefix); for (PropertyImpl property : properties) { propertyRepository.delete(property); } PropertyHolder originalProperties = getApplicationProperties(null, application); if (null != originalProperties) { for (String name : originalProperties.getPropertyNames()) { Property platformApplicationProperty = originalProperties.getProperty(name); String value = originalProperties.getString(name); String propName = name.substring(name.lastIndexOf(".") + 1); PropertyImpl property = new PropertyImpl(propName, null, value); property.setDescription(platformApplicationProperty.getDescription()); property.setType(platformApplicationProperty.getType()); if (StringUtils.isNotEmpty(platformApplicationProperty.getClob())) { property.setClob(platformApplicationProperty.getClob()); } else { property.setDefaultString(platformApplicationProperty.getDefaultString()); } createProperty(site.getId(), application.getId(), property); } } } } else if (null != dbc) { auditableListener.createEvent(Type.ERROR, String.format("Error creating database %s with user %s for application %s on site %s", dbc.getJdbcUrl(), dbc.getUserName(), application.getName(), site.getName())); MigrationStatus droppedState = databaseService.dropDataBaseAndUser(dbc); if (MigrationStatus.ERROR.equals(droppedState)) { String message = String.format( "Failed to delete database and user for connection %s, manual cleanup might be required!", dbc.getJdbcUrl()); LOGGER.warn(message); auditableListener.createEvent(Type.ERROR, message); } databaseConnectionRepository.delete(dbc); } else { auditableListener.createEvent(Type.ERROR, String.format("Error creating database and/or user for application %s on site %s", application.getName(), site.getName())); } return migrationStatus; } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testAssignApplicationToSite() { SiteImpl site = coreService.getSite(1); Application application = coreService.findApplicationByName("foobar"); MigrationStatus state = coreService.assignApplicationToSite(site, application, true); assertEquals(MigrationStatus.NO_DB_SUPPORTED, state); Iterable<PropertyImpl> properties = coreService.getProperties(1, application.getId()); String prefix = "platform.site." + site.getName() + ".application." + application.getName() + "."; PropertyHolder propertyHolder = new PropertyHolder(prefix, properties); assertEquals("foobaz", propertyHolder.getString("foobar")); Property prop = propertyHolder.getProperty("foobar"); assertEquals(Property.Type.TEXT, prop.getType()); assertEquals(prefix + "foobar", prop.getName()); }
CoreService { protected MigrationStatus createDatabaseConnection(SiteApplication siteApplication) { Application application = siteApplication.getApplication(); Site site = siteApplication.getSite(); Properties platformConfig = getPlatformProperties(); File applicationRootFolder = getApplicationRootFolder(null); CacheProvider cacheProvider = new CacheProvider(platformConfig); try { File platformCache = cacheProvider.getPlatformCache(site, application); Resources resources = getResources(application, platformCache, applicationRootFolder); resources.dumpToCache(ResourceType.APPLICATION, ResourceType.SQL); File sqlFolder = new File(platformCache, ResourceType.SQL.getFolder()); String databasePrefix = platformConfig.getString(Platform.Property.DATABASE_PREFIX); PropertyHolder applicationProperties = getApplicationProperties(null, siteApplication.getApplication()); ((AccessibleApplication) application).setProperties(applicationProperties); if (null == application.getResources()) { ((AccessibleApplication) application).setResources(resources); } MigrationStatus status = databaseService.manageApplicationConnection(siteApplication, sqlFolder, databasePrefix); return status; } catch (Exception e) { LOGGER.error(String.format("error during database setup for application %s", application.getName()), e); } finally { cacheProvider.clearCache(site, application.getName()); } return MigrationStatus.ERROR; } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testCreateDatabaseConnection() { DatabaseConnection databaseConnection = new DatabaseConnection(DatabaseType.HSQL, "testdb", "sa", "".getBytes()); databaseConnection.setName("testconection"); DatabaseConnection savedConnection = coreService.createDatabaseConnection(databaseConnection, true); assertNotNull(savedConnection.getId()); assertNotNull(savedConnection.getVersion()); assertEquals(databaseConnection.getName(), savedConnection.getName()); assertEquals(databaseConnection.getType(), savedConnection.getType()); assertEquals(databaseConnection.getJdbcUrl(), savedConnection.getJdbcUrl()); assertTrue(savedConnection.isManaged()); }
CoreService { public GroupImpl createGroup(GroupImpl group) { return groupRepository.save(group); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testCreateGroup() { GroupImpl group = new GroupImpl(); group.setName("groupy-group"); coreService.createGroup(group); assertNotNull(group.getId()); assertNotNull(group.getVersion()); }
CoreService { public RepositoryImpl createRepository(RepositoryImpl repository) { return repoRepository.save(repository); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testCreateApplicationRepository() throws URISyntaxException { RepositoryImpl repository = new RepositoryImpl(); repository.setName("name"); repository.setRepositoryMode(RepositoryMode.ALL); repository.setRepositoryType(RepositoryType.LOCAL); repository.setActive(true); repository.setUri(new URI("file:/tmp/repo")); RepositoryImpl savedRepo = coreService.createRepository(repository); assertNotNull(savedRepo.getId()); assertNotNull(savedRepo.getVersion()); }
CoreService { protected void createSite(SiteImpl site, Environment env) { if (site.isCreateRepository()) { File repositoryRootDir = PlatformProperties.get(getPlatformConfig(env)).getRepositoryRootFolder(); File siteRootDir = new File(repositoryRootDir, site.getName()); if (!siteRootDir.exists()) { try { FileUtils.forceMkdir(siteRootDir); } catch (IOException e) { LOGGER.error(String.format( "directory cannot be created or the file named %s already exists but is not a directory", site.getName()), e); } } } initSiteProperties(site, true); siteRepository.save(site); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testCreateSite() { SiteImpl site = new SiteImpl(); site.setName("example"); site.setHost("example.com"); site.setDomain("example.com"); site.setActive(true); coreService.createSite(site); validateSite(site); }
RuleValidation { public static boolean fileSize(List<FormUpload> fUpload, String minSize, String maxSize) { return isValidFileUpload(fUpload, minSize, false) && isValidFileUpload(fUpload, maxSize, true); } RuleValidation(Request container); Map<String, List<FormUpload>> getFileParams(Map<String, List<FormUpload>> formUploads); boolean validate(String rule); static boolean string(String string); static boolean captcha(String value, String result); static boolean email(String string); static boolean equals(String string1, String string2); static boolean number(String string); static boolean number(String string, char separator); static boolean numberFractionDigits(String string, int digits, int fraction); static boolean number(String string, char separator, int digits, int fraction); static boolean regExp(String string, String regex); static boolean size(Object item, int size); static boolean sizeMax(Object item, int max); static boolean sizeMin(Object item, int min); static boolean sizeMinMax(Object item, int min, int max); static boolean fileType(List<FormUpload> fUpload, String types); static boolean fileSize(List<FormUpload> fUpload, String minSize, String maxSize); static boolean fileSizeMin(List<FormUpload> fUpload, String minSize); static boolean fileSizeMax(List<FormUpload> fUpload, String maxSize); static boolean fileCountMin(List<FormUpload> fUpload, int count); static boolean fileCountMax(List<FormUpload> fUpload, int count); static boolean fileCount(List<FormUpload> fUpload, int minCount, int maxCount); static final List<String> SHORT_RULES; }
@Test public void testFileSize() { assertTrue("fileSize(upload,'500KB','2.5MB')"); assertFalse("fileSize(upload,'600KB','1.1MB')"); assertFalse("fileSize(upload,'500KB','0.1MB')"); }
CoreService { public Subject createSubject(SubjectImpl subject) { boolean changePasswordAllowed = UserType.LOCAL_USER.equals(subject.getUserType()); subject.setPasswordChangePolicy( changePasswordAllowed ? PasswordChangePolicy.MAY : PasswordChangePolicy.MUST_NOT); if (changePasswordAllowed) { subject.setPasswordLastChanged(new Date()); } return subjectRepository.save(subject); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testCreateSubject() { SubjectImpl subject = new SubjectImpl(); subject.setRealname("John Doe"); subject.setLanguage("de"); subject.setName("john"); subject.setUserType(UserType.LOCAL_USER); Subject savedSubject = coreService.createSubject(subject); assertNotNull(savedSubject); assertNotNull(savedSubject.getId()); }
CoreService { public void deleteApplicationRepository(org.appng.core.model.Repository repository) { repoRepository.delete(repository.getId()); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testDeleteApplicationRepository() { coreService.deleteApplicationRepository(coreService.getApplicationRepositoryByName("name")); }
CoreService { private void deleteApplicationResource(Resource applicationResource) throws BusinessException { if (null != applicationResource) { resourceRepository.delete((ResourceImpl) applicationResource); } } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test @Ignore public void testDeleteApplicationResource() { }
CoreService { public void deleteRole(Role role) throws BusinessException { deleteRole(role.getId(), null, null); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testDeleteApplicationRole() throws BusinessException { coreService.deleteRole(1, "applicationroleDeleteError", "applicationroleErrorInvalid"); } @Test(expected = BusinessException.class) public void testDeleteApplicationRoleInvalid() throws BusinessException { try { coreService.deleteRole(7, "applicationroleDeleteError", "applicationroleErrorInvalid"); } catch (BusinessException e) { assertEquals("applicationroleErrorInvalid", e.getMessageKey()); throw e; } }
CoreService { public void deleteApplication(String applicationName, FieldProcessor fp) throws BusinessException { Application application = findApplicationByName(applicationName); if (null != application) { File applicationFolder = getApplicationFolder(null, application); deleteApplication(null, fp, application, applicationFolder, null, null, null, null); } else { throw new BusinessException("No such application: " + applicationName); } } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Rollback @Test(expected = BusinessException.class) public void testDeleteApplicationSiteActive() throws BusinessException { coreService.deleteApplication("bugtracker", new FieldProcessorImpl("delete")); }
CoreService { public void deleteProperty(PropertyImpl prop) { propertyRepository.delete(prop); LOGGER.debug("deleting property '{}'", prop.getName()); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test @Ignore public void testDeleteProperty() { }
CoreService { public void deleteSite(String name, FieldProcessor fp) throws BusinessException { SiteImpl siteByName = siteRepository.findByName(name); if (null == siteByName) { throw new BusinessException("No such site " + name); } deleteSite(null, siteByName); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testDeleteSite() throws BusinessException { FieldProcessorImpl fp = new FieldProcessorImpl("delete"); coreService.deleteSite("site-3", fp); assertFalse(fp.hasErrors()); }
CoreService { public void deleteSubject(Subject subject) { subjectRepository.delete(subject.getId()); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testDeleteSubject() { Subject subject = coreService.getSubjectByName("john", false); coreService.deleteSubject(subject); assertNull(coreService.getSubjectById(subject.getId(), false)); }
CoreService { public AccessibleApplication findApplicationByName(String name) { ApplicationImpl application = applicationRepository.findByName(name); if (null != application && !application.isFileBased()) { application.getResourceSet().size(); } return application; } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testFindApplicationByName() { Application application = coreService.findApplicationByName("manager"); assertEquals("manager", application.getName()); }
RuleValidation { public static boolean fileType(List<FormUpload> fUpload, String types) { List<String> fileTypes = Arrays.asList(types.split(COMMA)); if (fUpload != null) { for (FormUpload fileName : fUpload) { if (!fileTypes.contains(fileName.getContentType())) { return false; } } } return true; } RuleValidation(Request container); Map<String, List<FormUpload>> getFileParams(Map<String, List<FormUpload>> formUploads); boolean validate(String rule); static boolean string(String string); static boolean captcha(String value, String result); static boolean email(String string); static boolean equals(String string1, String string2); static boolean number(String string); static boolean number(String string, char separator); static boolean numberFractionDigits(String string, int digits, int fraction); static boolean number(String string, char separator, int digits, int fraction); static boolean regExp(String string, String regex); static boolean size(Object item, int size); static boolean sizeMax(Object item, int max); static boolean sizeMin(Object item, int min); static boolean sizeMinMax(Object item, int min, int max); static boolean fileType(List<FormUpload> fUpload, String types); static boolean fileSize(List<FormUpload> fUpload, String minSize, String maxSize); static boolean fileSizeMin(List<FormUpload> fUpload, String minSize); static boolean fileSizeMax(List<FormUpload> fUpload, String maxSize); static boolean fileCountMin(List<FormUpload> fUpload, int count); static boolean fileCountMax(List<FormUpload> fUpload, int count); static boolean fileCount(List<FormUpload> fUpload, int minCount, int maxCount); static final List<String> SHORT_RULES; }
@Test public void testFileType() { assertTrue("fileType(upload,'jpg,gif,png')"); assertFalse("fileType(upload,'tif,pdf')"); }
ImageProcessor { public ImageProcessor rotate(int degrees) { op.rotate((double) degrees); return this; } ImageProcessor(File imageMagickPath, File sourceFile, File targetFile); ImageProcessor(File imageMagickPath, File sourceFile, File targetFile, boolean checkMagicBytes); ImageProcessor(File sourceFile, File targetFile); ImageProcessor(File sourceFile, File targetFile, boolean checkMagicBytes); private ImageProcessor(File imageMagickPath, File sourceFile, File targetFile, boolean setGlobalSearchPath, boolean checkMagicBytes); static boolean isImageMagickPresent(File imageMagickPath); static void setGlobalSearchPath(File imageMagickPath); ImageMetaData getMetaData(); ImageProcessor rotate(int degrees); ImageProcessor resize(int targetWidth, int targetHeight, boolean scaleUp); ImageProcessor resize(int targetWidth, int targetHeight); ImageProcessor quality(double quality); ImageProcessor strip(); ImageProcessor autoCrop(int croppingWidth, int croppingHeight, int originalWidth, int originalHeight); ImageProcessor autoCrop(int croppingWidth, int croppingHeight, int originalWidth, int originalHeight, int croppingOffsetX, int croppingOffsetY); ImageProcessor crop(int targetWidth, int targetHeight, int offsetWidth, int offsetHeight); File getImage(); ImageProcessor fitToWidthAndHeight(int maxwidth, int maxHeight); ImageProcessor fitToWidth(Integer maxWidth); ImageProcessor fitToHeight(Integer maxHeight); IMOperation getOp(); }
@Test public void testRotate() throws IOException { File targetFile = new File(targetFolder, "desert-rotated.jpg"); ImageProcessor ip = getSource(targetFile); ip.fitToWidth(150).rotate(-45); ip.getImage(); }
CoreService { private PropertyHolder getApplicationProperties(Site site, Application application) { String prefix = PropertySupport.getPropertyPrefix(site, application); Iterable<PropertyImpl> properties = getProperties(prefix); return new PersistentPropertyHolder(prefix, properties); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testGetApplicationProperties() { coreService.saveProperty(new PropertyImpl(PropertySupport.PREFIX_PLATFORM + "foo", "bar")); PropertyHolder platformProperties = coreService.getPlatformProperties(); assertEquals("bar", platformProperties.getString("foo")); }
CoreService { public DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword) { DatabaseConnection conn = databaseConnectionRepository.findOne(dcId); CacheProvider cacheProvider = null == conn.getSite() ? null : new CacheProvider(getPlatformProperties()); prepareConnection(conn, clearPassword, cacheProvider); return conn; } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test @Ignore public void testGetDatabaseConnection() { }
CoreService { public Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp) { SearchQuery<DatabaseConnection> query = new SearchQuery<DatabaseConnection>(DatabaseConnection.class); CacheProvider cacheProvider = null; if (siteId == null) { query.isNull("site.id"); } else { query.equals("site.id", siteId); cacheProvider = new CacheProvider(getPlatformProperties()); } Page<DatabaseConnection> connections = databaseConnectionRepository.search(query, fp.getPageable()); for (DatabaseConnection databaseConnection : connections) { prepareConnection(databaseConnection, true, cacheProvider); } return connections; } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test @Ignore public void testGetDatabaseConnections() { }
CoreService { public GroupImpl getGroupByName(String name) { return groupRepository.findByName(name); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testGetGroupByName() { Group group = coreService.getGroupByName("group-1"); assertEquals(Integer.valueOf(1), group.getId()); }
CoreService { public List<? extends Group> getGroups() { return groupRepository.findAll(); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testGetGroups() { List<? extends Group> groups = coreService.getGroups(); assertEquals(4, groups.size()); assertEquals("group-1", groups.get(0).getName()); assertEquals("group-2", groups.get(1).getName()); assertEquals("group-3", groups.get(2).getName()); assertEquals("groupy-group", groups.get(3).getName()); }
CoreService { public File getApplicationFolder(Environment env, String applicationName) { return new File(getApplicationRootFolder(env), applicationName); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testGetApplicationFolder() { assertEquals(new File(rootPath + "/applications/manager"), coreService.getApplicationFolder(environment, "manager")); }
CoreService { public List<RepositoryImpl> getApplicationRepositories() { return repoRepository.findAll(); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testGetApplicationRepositories() { List<RepositoryImpl> applicationRepositories = coreService.getApplicationRepositories(); assertEquals(1, applicationRepositories.size()); assertEquals("repo", applicationRepositories.get(0).getName()); }
CoreService { public org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName) { return repoRepository.findByName(repositoryName); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test @Ignore public void testGetApplicationRepositoryByName() { }
CoreService { public List<RoleImpl> getApplicationRolesForApplication(Integer applicationId) { return roleRepository.findByApplicationId(applicationId); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testGetApplicationRolesForApplication() { List<RoleImpl> applicationRoles = coreService.getApplicationRolesForApplication(2); assertEquals(1, applicationRoles.size()); assertEquals("user", applicationRoles.get(0).getName()); }
CoreService { protected File getApplicationRootFolder(Environment environment) { return PlatformProperties.get(getPlatformConfig(environment)).getApplicationDir(); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testGetApplicationRootFolder() { assertEquals(new File(rootPath + "/applications"), coreService.getApplicationRootFolder(environment)); }
RuleValidation { public static boolean fileCount(List<FormUpload> fUpload, int minCount, int maxCount) { return fileCountMin(fUpload, minCount) && fileCountMax(fUpload, maxCount); } RuleValidation(Request container); Map<String, List<FormUpload>> getFileParams(Map<String, List<FormUpload>> formUploads); boolean validate(String rule); static boolean string(String string); static boolean captcha(String value, String result); static boolean email(String string); static boolean equals(String string1, String string2); static boolean number(String string); static boolean number(String string, char separator); static boolean numberFractionDigits(String string, int digits, int fraction); static boolean number(String string, char separator, int digits, int fraction); static boolean regExp(String string, String regex); static boolean size(Object item, int size); static boolean sizeMax(Object item, int max); static boolean sizeMin(Object item, int min); static boolean sizeMinMax(Object item, int min, int max); static boolean fileType(List<FormUpload> fUpload, String types); static boolean fileSize(List<FormUpload> fUpload, String minSize, String maxSize); static boolean fileSizeMin(List<FormUpload> fUpload, String minSize); static boolean fileSizeMax(List<FormUpload> fUpload, String maxSize); static boolean fileCountMin(List<FormUpload> fUpload, int count); static boolean fileCountMax(List<FormUpload> fUpload, int count); static boolean fileCount(List<FormUpload> fUpload, int minCount, int maxCount); static final List<String> SHORT_RULES; }
@Test public void testFileCount() { assertTrue("fileCount(upload, 1, 2)"); assertFalse("fileCount(upload, 1, 0)"); assertFalse("fileCount(upload, 3, 2)"); }
CoreService { public List<ApplicationImpl> getApplications() { return applicationRepository.findAll(); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test @Ignore public void testGetApplications() { }
CoreService { public Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site) { List<ApplicationSubject> applicationSubjects = new ArrayList<>(); ApplicationImpl application = applicationRepository.findOne(applicationId); List<SubjectImpl> subjects = subjectRepository.findSubjectsForApplication(applicationId); String siteTimeZone = site.getProperties().getString(Platform.Property.TIME_ZONE); for (SubjectImpl subject : subjects) { initializeSubject(subject); subject.getApplicationroles(application); if (UserType.GLOBAL_GROUP.equals(subject.getUserType())) { List<SubjectImpl> membersOfGroup = ldapService.getMembersOfGroup(site, subject.getAuthName()); for (SubjectImpl ldapSubject : membersOfGroup) { String timeZone = subject.getTimeZone(); if (null == timeZone) { timeZone = siteTimeZone; } ldapSubject.setTimeZone(timeZone); ldapSubject.setLanguage(subject.getLanguage()); ldapSubject.getGroups().addAll(subject.getGroups()); ApplicationSubject ps = getApplicationSubject(application, ldapSubject); applicationSubjects.add(ps); } } else { ApplicationSubject ps = getApplicationSubject(application, subject); applicationSubjects.add(ps); } } return applicationSubjects; } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test @Ignore public void testGetApplicationSubjects() { }
CoreService { private Page<PropertyImpl> getProperties(String prefix, Pageable pageable) { SearchQuery<PropertyImpl> query = new SearchQuery<PropertyImpl>(PropertyImpl.class); query.like("name", prefix + "%"); query.notLike("name", prefix + "%.%"); Page<PropertyImpl> page = propertyRepository.search(query, pageable); return page; } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testGetPropertiesIntegerInteger() { Iterable<PropertyImpl> properties = coreService.getProperties(1, 1); Iterator<PropertyImpl> iterator = properties.iterator(); PropertyImpl prop = iterator.next(); assertEquals("platform.site.site-1.application.manager.foo", prop.getName()); assertEquals("bar", prop.getString()); iterator.next(); assertFalse(iterator.hasNext()); } @Test public void testGetPropertiesStringString() { Iterable<PropertyImpl> properties = coreService.getProperties("site-1", "manager"); Iterator<PropertyImpl> iterator = properties.iterator(); PropertyImpl prop = iterator.next(); assertEquals("platform.site.site-1.application.manager.foo", prop.getName()); assertEquals("bar", prop.getString()); iterator.next(); assertFalse(iterator.hasNext()); }
CoreService { public PropertyImpl getProperty(String propertyId) { return propertyRepository.findOne(propertyId); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test @Ignore public void testGetProperty() { }
CoreService { public SiteImpl getSite(Integer id) { SiteImpl site = siteRepository.findOne(id); initSite(site); return site; } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testGetSite() { SiteImpl site = coreService.getSite(1); assertNotNull(site); assertEquals(Integer.valueOf(1), site.getId()); }
CoreService { public SiteImpl getSiteByName(String name) { SiteImpl site = siteRepository.findByName(name); initSite(site); return site; } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testGetSiteByName() { SiteImpl site = coreService.getSiteByName("site-1"); assertNotNull(site); assertEquals(Integer.valueOf(1), site.getId()); assertEquals("site-1", site.getName()); }
CoreService { protected List<Integer> getSiteIds() { return siteRepository.getSiteIds(); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testGetSiteIds() { List<Integer> siteIds = coreService.getSiteIds(); assertEquals(2, siteIds.size()); assertEquals(Integer.valueOf(1), siteIds.get(0)); assertEquals(Integer.valueOf(4), siteIds.get(1)); }
CoreService { public List<SiteImpl> getSites() { return siteRepository.findAll(); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testGetSites() { List<SiteImpl> sites = coreService.getSites(); assertEquals(2, sites.size()); assertEquals("site-1", sites.get(0).getName()); assertEquals("example", sites.get(1).getName()); }
CoreService { public Subject getSubjectByEmail(String email) { return subjectRepository.findByEmail(email); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testGetSubjectByEmail() { Subject subject = coreService.getSubjectByEmail("[email protected]"); assertEquals(Integer.valueOf(1), subject.getId()); }
RuleValidation { public static boolean fileCountMin(List<FormUpload> fUpload, int count) { return getNumberOfFiles(fUpload) >= count; } RuleValidation(Request container); Map<String, List<FormUpload>> getFileParams(Map<String, List<FormUpload>> formUploads); boolean validate(String rule); static boolean string(String string); static boolean captcha(String value, String result); static boolean email(String string); static boolean equals(String string1, String string2); static boolean number(String string); static boolean number(String string, char separator); static boolean numberFractionDigits(String string, int digits, int fraction); static boolean number(String string, char separator, int digits, int fraction); static boolean regExp(String string, String regex); static boolean size(Object item, int size); static boolean sizeMax(Object item, int max); static boolean sizeMin(Object item, int min); static boolean sizeMinMax(Object item, int min, int max); static boolean fileType(List<FormUpload> fUpload, String types); static boolean fileSize(List<FormUpload> fUpload, String minSize, String maxSize); static boolean fileSizeMin(List<FormUpload> fUpload, String minSize); static boolean fileSizeMax(List<FormUpload> fUpload, String maxSize); static boolean fileCountMin(List<FormUpload> fUpload, int count); static boolean fileCountMax(List<FormUpload> fUpload, int count); static boolean fileCount(List<FormUpload> fUpload, int minCount, int maxCount); static final List<String> SHORT_RULES; }
@Test public void testFileCountMin() { assertTrue("fileCountMin(upload, 1)"); assertFalse("fileCountMin(upload, 5)"); assertFalse("fileCountMin(upload, 3)"); }
CoreService { public Subject getSubjectById(Integer id, boolean initialize) { SubjectImpl subject = subjectRepository.findOne(id); if (initialize) { initializeSubject(subject); } return subject; } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testGetSubjectById() { Subject subject = coreService.getSubjectById(1, false); assertEquals(Integer.valueOf(1), subject.getId()); }
CoreService { public SubjectImpl getSubjectByName(String name, boolean initialize) { SubjectImpl subject = subjectRepository.findByName(name); if (initialize) { initializeSubject(subject); } return subject; } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testGetSubjectByName() { Subject subject = coreService.getSubjectByName("subject-1", false); assertEquals(Integer.valueOf(1), subject.getId()); }
CoreService { public List<SubjectImpl> getSubjects() { return subjectRepository.findAll(); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testGetSubjects() { List<SubjectImpl> subjects = coreService.getSubjects(); assertEquals(3, subjects.size()); assertEquals("subject-1", subjects.get(0).getName()); assertEquals("subject-2", subjects.get(1).getName()); assertEquals("subject-3", subjects.get(2).getName()); }
CoreService { public boolean login(Environment env, Principal principal) { SubjectImpl loginSubject = null; SubjectImpl subject = getSubjectByName(principal.getName(), false); if (null != subject) { if (verifySubject(UserType.GLOBAL_USER.equals(subject.getUserType()), subject, env, "{} must be a global user!")) { LOGGER.info("user {} found", principal.getName()); loginSubject = subject; } } else { LOGGER.info("Subject authentication failed. Trying to authenticate based on LDAP group membership."); loginSubject = new SubjectImpl(); loginSubject.setName(principal.getName()); boolean hasAnyRole = false; List<SubjectImpl> globalGroups = getSubjectsByType(UserType.GLOBAL_GROUP); HttpServletRequest request = ((DefaultEnvironment) env).getServletRequest(); for (Subject globalGroup : globalGroups) { if (request.isUserInRole(globalGroup.getName())) { LOGGER.info("user '{}' belongs to group '{}'", principal.getName(), globalGroup.getName()); hasAnyRole = true; for (Group group : globalGroup.getGroups()) { initGroup(group); if (!loginSubject.getGroups().contains(group)) { loginSubject.getGroups().add(group); loginSubject.setLanguage(globalGroup.getLanguage()); loginSubject.setRealname(globalGroup.getName()); } } } } if (hasAnyRole) { LOGGER.info("User '{}' successfully authenticated.", principal.getName()); } else { loginSubject = null; LOGGER.error("No valid group membership found for user '{}'", principal.getName()); } } return login(env, loginSubject); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testLoginPrincipalWithGroup() { servletRequest.addUserRole("subject-1"); Mockito.when(environment.getServletRequest()).thenReturn(servletRequest); Principal principal = Mockito.mock(Principal.class); boolean success = coreService.login(environment, principal); assertTrue(success); Mockito.verify(environment).setSubject(Mockito.any(SubjectImpl.class)); logout(); } @Test public void testLogin() { boolean success = coreService.login(null, environment, "subject-3", "test"); assertTrue(success); Mockito.verify(environment).setSubject(Mockito.any(SubjectImpl.class)); SubjectImpl subject = coreService.getSubjectByName("subject-3", true); assertNotNull(subject.getLastLogin()); assertFalse(subject.isLocked()); assertNotNull(envSubject); assertFalse(envSubject.isLocked()); logout(); }
CoreService { public boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId) { Group group = groupRepository.getGroup(groupId); if (null != group) { if (isValidPassword(authSubject, password)) { SubjectImpl subject = new SubjectImpl(); subject.getGroups().add(group); subject.setLanguage(authSubject.getLanguage()); subject.setTimeZone(authSubject.getTimeZone()); subject.setRealname(authSubject.getRealname()); subject.setName(authSubject.getAuthName()); subject.setEmail(authSubject.getEmail()); return login(env, subject); } } else { LOGGER.warn("no such group: {}", groupId); } return false; } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testLoginGroup() { SubjectImpl authSubject = new SubjectImpl(); authSubject.setDigest(AppNGTestDataProvider.DIGEST); authSubject.setSalt(AppNGTestDataProvider.SALT); authSubject.setEmail("[email protected]"); authSubject.setTimeZone(TimeZone.getDefault().getDisplayName()); authSubject.setLanguage(Locale.ENGLISH.getLanguage()); authSubject.setName("johndoe"); authSubject.setRealname("John Doe"); boolean success = coreService.loginGroup(environment, authSubject, "test", 1); assertTrue(success); ArgumentCaptor<Subject> subjectCaptor = ArgumentCaptor.forClass(Subject.class); Mockito.verify(environment).setSubject(subjectCaptor.capture()); Subject subject = subjectCaptor.getValue(); Assert.assertEquals(authSubject.getEmail(), subject.getEmail()); Assert.assertEquals(authSubject.getLanguage(), subject.getLanguage()); Assert.assertEquals(authSubject.getTimeZone(), subject.getTimeZone()); Assert.assertEquals(authSubject.getAuthName(), subject.getName()); Assert.assertEquals(authSubject.getRealname(), subject.getRealname()); logout(); }
CoreService { private ApplicationImpl provideApplication(PackageArchive applicationArchive, boolean isFileBased, boolean isPrivileged, boolean isHidden, FieldProcessor fp, boolean updateHiddenAndPrivileged) throws BusinessException { ApplicationInfo applicationInfo = (ApplicationInfo) applicationArchive.getPackageInfo(); String applicationName = applicationInfo.getName(); String applicationVersion = applicationInfo.getVersion(); File outputDir = getApplicationFolder(null, applicationName); ApplicationImpl application = applicationRepository.findByName(applicationName); if (null == application) { LOGGER.info("deploying application {}-{}", applicationName, applicationVersion); application = RepositoryImpl.getApplication(applicationInfo); application.setFileBased(isFileBased); application.setPrivileged(isPrivileged); application.setHidden(isHidden); createApplication(application, applicationInfo, fp); } else { LOGGER.info("updating application {}-{}", applicationName, applicationVersion); if (updateHiddenAndPrivileged) { application.setPrivileged(isPrivileged); application.setHidden(isHidden); } RepositoryImpl.getApplication(application, applicationInfo); } updateApplication(application, applicationArchive, outputDir); return application; } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testProvideApplication() throws URISyntaxException, BusinessException { RepositoryImpl repository = new RepositoryImpl(); repository.setActive(true); repository.setName("testrepo"); repository.setRepositoryMode(RepositoryMode.STABLE); repository.setRepositoryType(RepositoryType.LOCAL); URI uri = getClass().getClassLoader().getResource("zip").toURI(); repository.setUri(uri); coreService.createRepository(repository); String applicationName = "demo-application"; String applicationVersion = "1.5.2"; String applicationTimestamp = "2012-11-27-1305"; String appngVersion = "1.0.0-M1"; coreService.installPackage(repository.getId(), applicationName, applicationVersion, applicationTimestamp, true, false, true); Application application = coreService.findApplicationByName(applicationName); ((ApplicationImpl) application).setDisplayName("a cool display name"); validateApplication(appngVersion, applicationName, applicationVersion, applicationTimestamp, application); assertEquals("bar", application.getProperties().getString("foo")); Property property = ((PropertyHolder) application.getProperties()).getProperty("foo"); assertEquals("a foo property", property.getDescription()); assertEquals(Property.Type.TEXT, property.getType()); Property multiline = ((PropertyHolder) application.getProperties()).getProperty("clobValue"); assertEquals(Property.Type.MULTILINE, multiline.getType()); assertEquals("a\nb\nc", application.getProperties().getClob("clobValue")); }
CoreService { protected void reloadRepository(Integer repositoryId) throws BusinessException { if (null != repositoryId) { RepositoryImpl repository = repoRepository.findOne(repositoryId); if (null != repository) { try { repository.reload(); } catch (Exception e) { throw new BusinessException("Unable to reload repository with ID " + repositoryId, e); } } } } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test(expected = BusinessException.class) public void testReloadRepository() throws BusinessException { coreService.reloadRepository(1); }
CoreService { public void resetConnection(FieldProcessor fp, Integer conId) { SiteApplication siteApplication = siteApplicationRepository.findByDatabaseConnectionId(conId); if (null != siteApplication) { String databasePrefix = getPlatform(true, false).getString(Platform.Property.DATABASE_PREFIX); databaseService.resetApplicationConnection(siteApplication, databasePrefix); } } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test @Ignore public void testResetConnection() { }
CoreService { public byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash) { SubjectImpl subject = getSubjectByName(authSubject.getAuthName(), false); if (canSubjectResetPassword(subject)) { PasswordHandler passwordHandler = getPasswordHandler(authSubject); if (passwordHandler.isValidPasswordResetDigest(hash)) { LOGGER.debug("setting new password for {}", email); String password = passwordPolicy.generatePassword(); getDefaultPasswordHandler(authSubject).applyPassword(password); subject.setDigest(authSubject.getDigest()); subject.setSalt(null); subject.setPasswordLastChanged(new Date()); subject.setPasswordChangePolicy(PasswordChangePolicy.MAY); return password.getBytes(); } else { LOGGER.debug("hash did not match, not setting new password for '{}'", authSubject.getAuthName()); } } else { LOGGER.debug("{} does not exist, is locked or must not change password!", authSubject.getAuthName()); } return null; } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testResetPassword() { AuthSubject subject = coreService.getSubjectByName("subject-3", true); String currentDigest = subject.getDigest(); String currentSalt = subject.getSalt(); SaltedDigest saltedDigest = new SaltedDigestSha1(); if (null == currentSalt) { currentSalt = saltedDigest.getSalt(); subject.setSalt(currentSalt); } String hash = saltedDigest.getDigest(subject.getEmail(), currentSalt); coreService.resetPassword(subject, new DefaultPasswordPolicy(), subject.getEmail(), hash); assertNull(subject.getSalt()); assertNotEquals(subject.getDigest(), currentDigest); assertTrue(subject.getDigest().startsWith(BCryptPasswordHandler.getPrefix())); }
RuleValidation { public static boolean fileCountMax(List<FormUpload> fUpload, int count) { return getNumberOfFiles(fUpload) <= count; } RuleValidation(Request container); Map<String, List<FormUpload>> getFileParams(Map<String, List<FormUpload>> formUploads); boolean validate(String rule); static boolean string(String string); static boolean captcha(String value, String result); static boolean email(String string); static boolean equals(String string1, String string2); static boolean number(String string); static boolean number(String string, char separator); static boolean numberFractionDigits(String string, int digits, int fraction); static boolean number(String string, char separator, int digits, int fraction); static boolean regExp(String string, String regex); static boolean size(Object item, int size); static boolean sizeMax(Object item, int max); static boolean sizeMin(Object item, int min); static boolean sizeMinMax(Object item, int min, int max); static boolean fileType(List<FormUpload> fUpload, String types); static boolean fileSize(List<FormUpload> fUpload, String minSize, String maxSize); static boolean fileSizeMin(List<FormUpload> fUpload, String minSize); static boolean fileSizeMax(List<FormUpload> fUpload, String maxSize); static boolean fileCountMin(List<FormUpload> fUpload, int count); static boolean fileCountMax(List<FormUpload> fUpload, int count); static boolean fileCount(List<FormUpload> fUpload, int minCount, int maxCount); static final List<String> SHORT_RULES; }
@Test public void testFileCountMax() { assertTrue("fileCountMax(upload, 3)"); assertFalse("fileCountMax(upload, 1)"); assertFalse("fileCountMax(upload, 0)"); }
CoreService { public Subject restoreSubject(String name) { SubjectImpl subject = getSubjectByName(name, true); if (null != subject) { initAuthenticatedSubject(subject); LOGGER.trace("successfully restored subject '{}'", subject.getName()); } else { LOGGER.error("can not restore subject '{}'", name); } return subject; } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testRestoreSubject() { Subject subject = coreService.restoreSubject("subject-1"); assertTrue(subject.isAuthenticated()); assertNull(subject.getDigest()); assertNull(subject.getSalt()); }