http://git-wip-us.apache.org/repos/asf/syncope/blob/39f8a069/client/old_console/src/main/java/org/apache/syncope/client/console/commons/PreferenceManager.java ---------------------------------------------------------------------- diff --git a/client/old_console/src/main/java/org/apache/syncope/client/console/commons/PreferenceManager.java b/client/old_console/src/main/java/org/apache/syncope/client/console/commons/PreferenceManager.java new file mode 100644 index 0000000..a4e246e --- /dev/null +++ b/client/old_console/src/main/java/org/apache/syncope/client/console/commons/PreferenceManager.java @@ -0,0 +1,176 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.console.commons; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.core.type.TypeReference; +import java.io.IOException; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.commons.lang3.math.NumberUtils; +import org.apache.wicket.request.Request; +import org.apache.wicket.request.Response; +import org.apache.wicket.util.cookies.CookieDefaults; +import org.apache.wicket.util.cookies.CookieUtils; +import org.apache.wicket.util.crypt.Base64; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.util.StringUtils; + +public class PreferenceManager { + + /** + * Logger. + */ + private static final Logger LOG = LoggerFactory.getLogger(PreferenceManager.class); + + private static final String PREFMAN_KEY = "prefMan"; + + private static final int ONE_YEAR_TIME = 60 * 60 * 24 * 365; + + private static final TypeReference<Map<String, String>> MAP_TYPE_REF = new TypeReference<Map<String, String>>() { + }; + + private static final List<Integer> PAGINATOR_CHOICES = Arrays.asList(new Integer[] { 10, 25, 50 }); + + private final ObjectMapper mapper; + + private final CookieUtils cookieUtils; + + public PreferenceManager() { + this.mapper = new ObjectMapper(); + + CookieDefaults cookieDefaults = new CookieDefaults(); + cookieDefaults.setMaxAge(ONE_YEAR_TIME); + this.cookieUtils = new CookieUtils(cookieDefaults); + } + + public List<Integer> getPaginatorChoices() { + return PAGINATOR_CHOICES; + } + + private Map<String, String> getPrefs(final String value) { + Map<String, String> prefs; + try { + if (StringUtils.hasText(value)) { + prefs = mapper.readValue(value, MAP_TYPE_REF); + } else { + throw new Exception("Invalid cookie value '" + value + "'"); + } + } catch (Exception e) { + LOG.debug("No preferences found", e); + prefs = new HashMap<String, String>(); + } + + return prefs; + } + + private String setPrefs(final Map<String, String> prefs) throws IOException { + StringWriter writer = new StringWriter(); + mapper.writeValue(writer, prefs); + + return writer.toString(); + } + + public String get(final Request request, final String key) { + String result = null; + + String prefString = cookieUtils.load(PREFMAN_KEY); + if (prefString != null) { + final Map<String, String> prefs = getPrefs(new String(Base64.decodeBase64(prefString.getBytes()))); + result = prefs.get(key); + } + + return result; + } + + public Integer getPaginatorRows(final Request request, final String key) { + Integer result = getPaginatorChoices().get(0); + + String value = get(request, key); + if (value != null) { + result = NumberUtils.toInt(value, 10); + } + + return result; + } + + public List<String> getList(final Request request, final String key) { + final List<String> result = new ArrayList<String>(); + + final String compound = get(request, key); + + if (StringUtils.hasText(compound)) { + String[] items = compound.split(";"); + result.addAll(Arrays.asList(items)); + } + + return result; + } + + public void set(final Request request, final Response response, final Map<String, List<String>> prefs) { + Map<String, String> current = new HashMap<>(); + + String prefString = cookieUtils.load(PREFMAN_KEY); + if (prefString != null) { + current.putAll(getPrefs(new String(Base64.decodeBase64(prefString.getBytes())))); + } + + // after retrieved previous setting in order to overwrite the key ... + for (Map.Entry<String, List<String>> entry : prefs.entrySet()) { + current.put(entry.getKey(), StringUtils.collectionToDelimitedString(entry.getValue(), ";")); + } + + try { + cookieUtils.save(PREFMAN_KEY, new String(Base64.encodeBase64(setPrefs(current).getBytes()))); + } catch (IOException e) { + LOG.error("Could not save {} info: {}", getClass().getSimpleName(), current, e); + } + } + + public void set(final Request request, final Response response, final String key, final String value) { + String prefString = cookieUtils.load(PREFMAN_KEY); + + final Map<String, String> current = new HashMap<>(); + if (prefString != null) { + current.putAll(getPrefs(new String(Base64.decodeBase64(prefString.getBytes())))); + } + + // after retrieved previous setting in order to overwrite the key ... + current.put(key, value); + + try { + cookieUtils.save(PREFMAN_KEY, new String(Base64.encodeBase64(setPrefs(current).getBytes()))); + } catch (IOException e) { + LOG.error("Could not save {} info: {}", getClass().getSimpleName(), current, e); + } + } + + public void setList(final Request request, final Response response, final String key, final List<String> values) { + set(request, response, key, StringUtils.collectionToDelimitedString(values, ";")); + } + + public void setList(final Request request, final Response response, final Map<String, List<String>> prefs) { + set(request, response, prefs); + } +}
http://git-wip-us.apache.org/repos/asf/syncope/blob/39f8a069/client/old_console/src/main/java/org/apache/syncope/client/console/commons/PreviewUtils.java ---------------------------------------------------------------------- diff --git a/client/old_console/src/main/java/org/apache/syncope/client/console/commons/PreviewUtils.java b/client/old_console/src/main/java/org/apache/syncope/client/console/commons/PreviewUtils.java new file mode 100644 index 0000000..12c93d4 --- /dev/null +++ b/client/old_console/src/main/java/org/apache/syncope/client/console/commons/PreviewUtils.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.console.commons; + +import java.lang.reflect.InvocationTargetException; +import org.apache.commons.lang3.StringUtils; +import org.apache.syncope.client.console.init.ImplementationClassNamesLoader; +import org.apache.syncope.client.console.wicket.markup.html.form.preview.AbstractBinaryPreviewer; +import org.apache.wicket.Component; +import org.apache.wicket.util.crypt.Base64; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.util.ClassUtils; + [email protected] +public class PreviewUtils { + + @Autowired + private ImplementationClassNamesLoader implementationClassNamesLoader; + + public Component getPreviewer(final String mimeType, final String file) + throws InstantiationException, IllegalAccessException, InvocationTargetException { + + final Class<? extends AbstractBinaryPreviewer> previewer = StringUtils.isBlank(file) + ? null + : implementationClassNamesLoader.getPreviewerClass(mimeType); + + return previewer == null + ? null + : ClassUtils.getConstructorIfAvailable(previewer, String.class, String.class, byte[].class). + newInstance(new Object[] { "previewer", mimeType, Base64.decodeBase64(file) }). + preview(); + } + + public Component getPreviewer(final String mimeType, final byte[] file) + throws InstantiationException, IllegalAccessException, InvocationTargetException { + + final Class<? extends AbstractBinaryPreviewer> previewer = + implementationClassNamesLoader.getPreviewerClass(mimeType); + + return previewer == null + ? null + : ClassUtils.getConstructorIfAvailable(previewer, String.class, String.class, byte[].class). + newInstance(new Object[] { "previewer", mimeType, file }). + preview(); + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/39f8a069/client/old_console/src/main/java/org/apache/syncope/client/console/commons/SchemaModalPageFactory.java ---------------------------------------------------------------------- diff --git a/client/old_console/src/main/java/org/apache/syncope/client/console/commons/SchemaModalPageFactory.java b/client/old_console/src/main/java/org/apache/syncope/client/console/commons/SchemaModalPageFactory.java new file mode 100644 index 0000000..38a60fa --- /dev/null +++ b/client/old_console/src/main/java/org/apache/syncope/client/console/commons/SchemaModalPageFactory.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.console.commons; + +import org.apache.syncope.client.console.pages.AbstractSchemaModalPage; +import org.apache.syncope.client.console.pages.DerSchemaModalPage; +import org.apache.syncope.client.console.pages.PlainSchemaModalPage; +import org.apache.syncope.client.console.pages.VirSchemaModalPage; +import org.apache.syncope.common.lib.types.AttributableType; +import org.apache.syncope.common.lib.types.SchemaType; + +public final class SchemaModalPageFactory { + + private static final long serialVersionUID = -3533177688264693505L; + + private SchemaModalPageFactory() { + // empty constructor for static utility class + } + + @SuppressWarnings("unchecked") + public static <T extends AbstractSchemaModalPage> T getSchemaModalPage( + final AttributableType entity, final SchemaType schemaType) { + + T page; + + switch (schemaType) { + case DERIVED: + page = (T) new DerSchemaModalPage(entity); + break; + + case VIRTUAL: + page = (T) new VirSchemaModalPage(entity); + break; + + default: + page = (T) new PlainSchemaModalPage(entity); + break; + } + + return page; + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/39f8a069/client/old_console/src/main/java/org/apache/syncope/client/console/commons/SelectChoiceRenderer.java ---------------------------------------------------------------------- diff --git a/client/old_console/src/main/java/org/apache/syncope/client/console/commons/SelectChoiceRenderer.java b/client/old_console/src/main/java/org/apache/syncope/client/console/commons/SelectChoiceRenderer.java new file mode 100644 index 0000000..7b9164d --- /dev/null +++ b/client/old_console/src/main/java/org/apache/syncope/client/console/commons/SelectChoiceRenderer.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.console.commons; + +import org.apache.wicket.markup.html.form.IChoiceRenderer; + +public class SelectChoiceRenderer<T> implements IChoiceRenderer<T> { + + private static final long serialVersionUID = -3242441544405909243L; + + @Override + public Object getDisplayValue(T obj) { + if (obj instanceof SelectOption) { + return ((SelectOption) obj).getDisplayValue(); + } else { + return obj.toString(); + } + } + + @Override + public String getIdValue(T obj, int i) { + return obj.toString(); + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/39f8a069/client/old_console/src/main/java/org/apache/syncope/client/console/commons/SelectOption.java ---------------------------------------------------------------------- diff --git a/client/old_console/src/main/java/org/apache/syncope/client/console/commons/SelectOption.java b/client/old_console/src/main/java/org/apache/syncope/client/console/commons/SelectOption.java new file mode 100644 index 0000000..839df70 --- /dev/null +++ b/client/old_console/src/main/java/org/apache/syncope/client/console/commons/SelectOption.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.console.commons; + +import java.io.Serializable; +import org.apache.commons.lang3.builder.HashCodeBuilder; + +public class SelectOption implements Serializable { + + private static final long serialVersionUID = 2961127533930849828L; + + private String displayValue; + + private String keyValue; + + public SelectOption(final String displayValue, final String keyValue) { + this.displayValue = displayValue; + this.keyValue = keyValue; + } + + public String getDisplayValue() { + return displayValue; + } + + public void setDisplayValue(final String displayValue) { + this.displayValue = displayValue; + } + + public String getKeyValue() { + return keyValue; + } + + public void setKeyValue(final String keyValue) { + this.keyValue = keyValue; + } + + @Override + public boolean equals(final Object obj) { + if (obj == null || !(obj instanceof SelectOption)) { + return false; + } + + return (keyValue == null && ((SelectOption) obj).keyValue == null) || keyValue != null + && keyValue.equals(((SelectOption) obj).keyValue); + } + + @Override + public int hashCode() { + return HashCodeBuilder.reflectionHashCode(this); + } + + @Override + public String toString() { + return keyValue; + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/39f8a069/client/old_console/src/main/java/org/apache/syncope/client/console/commons/SortableAttributableProviderComparator.java ---------------------------------------------------------------------- diff --git a/client/old_console/src/main/java/org/apache/syncope/client/console/commons/SortableAttributableProviderComparator.java b/client/old_console/src/main/java/org/apache/syncope/client/console/commons/SortableAttributableProviderComparator.java new file mode 100644 index 0000000..e82b9bb --- /dev/null +++ b/client/old_console/src/main/java/org/apache/syncope/client/console/commons/SortableAttributableProviderComparator.java @@ -0,0 +1,122 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.console.commons; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import org.apache.syncope.common.lib.to.AbstractAttributableTO; +import org.apache.syncope.common.lib.to.AttrTO; +import org.apache.syncope.common.lib.types.SchemaType; +import org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider; +import org.apache.wicket.model.AbstractReadOnlyModel; + +public class SortableAttributableProviderComparator extends SortableDataProviderComparator<AbstractAttributableTO> { + + private static final long serialVersionUID = 1775967163571699258L; + + private static final Set<String> INLINE_PROPS = new HashSet<>(Arrays.asList( + new String[] { "key", "status", "token", "username" })); + + public SortableAttributableProviderComparator(final SortableDataProvider<AbstractAttributableTO, String> provider) { + super(provider); + } + + @Override + public int compare(final AbstractAttributableTO attributable1, AbstractAttributableTO attributable2) { + if (INLINE_PROPS.contains(provider.getSort().getProperty())) { + return super.compare(attributable1, attributable2); + } + + return super.compare(new AttrModel(attributable1), new AttrModel(attributable2)); + } + + @SuppressWarnings("rawtypes") + private class AttrModel extends AbstractReadOnlyModel<Comparable> { + + private static final long serialVersionUID = -7856686374020091808L; + + private final Map<String, AttrTO> attrs; + + private final Map<String, AttrTO> derAttrs; + + private final Map<String, AttrTO> virAttrs; + + public AttrModel(final AbstractAttributableTO attributableTO) { + super(); + + this.attrs = attributableTO.getPlainAttrMap(); + this.derAttrs = attributableTO.getDerAttrMap(); + this.virAttrs = attributableTO.getVirAttrMap(); + } + + /** + * @see UserAttrColumn constructor + */ + @Override + public Comparable getObject() { + int hashPos = provider.getSort().getProperty().indexOf('#'); + + SchemaType schemaType = null; + final String schema; + if (hashPos == -1) { + schema = provider.getSort().getProperty(); + } else { + String[] splitted = provider.getSort().getProperty().split("#"); + try { + schemaType = SchemaType.valueOf(splitted[0]); + } catch (IllegalArgumentException e) { + // this should never happen + } + schema = provider.getSort().getProperty().substring(hashPos + 1); + } + + final AttrTO attr; + if (schemaType == null) { + attr = this.attrs.get(schema); + } else { + switch (schemaType) { + case PLAIN: + default: + attr = this.attrs.get(schema); + break; + + case DERIVED: + attr = this.derAttrs.get(schema); + break; + + case VIRTUAL: + attr = this.virAttrs.get(schema); + break; + } + } + + Comparable result = null; + + List<String> values = attr == null ? null : attr.getValues(); + if (values != null && !values.isEmpty()) { + result = values.iterator().next(); + } + + return result; + } + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/39f8a069/client/old_console/src/main/java/org/apache/syncope/client/console/commons/SortableDataProviderComparator.java ---------------------------------------------------------------------- diff --git a/client/old_console/src/main/java/org/apache/syncope/client/console/commons/SortableDataProviderComparator.java b/client/old_console/src/main/java/org/apache/syncope/client/console/commons/SortableDataProviderComparator.java new file mode 100644 index 0000000..bc4357d --- /dev/null +++ b/client/old_console/src/main/java/org/apache/syncope/client/console/commons/SortableDataProviderComparator.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.console.commons; + +import java.io.Serializable; +import java.util.Comparator; +import org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.PropertyModel; + +public class SortableDataProviderComparator<T> implements Comparator<T>, Serializable { + + private static final long serialVersionUID = -8897687699977460543L; + + protected final SortableDataProvider<T, String> provider; + + public SortableDataProviderComparator(final SortableDataProvider<T, String> provider) { + this.provider = provider; + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + protected int compare(final IModel<Comparable> model1, final IModel<Comparable> model2) { + int result; + + if (model1.getObject() == null && model2.getObject() == null) { + result = 0; + } else if (model1.getObject() == null) { + result = 1; + } else if (model2.getObject() == null) { + result = -1; + } else { + result = model1.getObject().compareTo(model2.getObject()); + } + + result = provider.getSort().isAscending() + ? result + : -result; + + return result; + } + + @SuppressWarnings("rawtypes") + @Override + public int compare(final T object1, final T object2) { + IModel<Comparable> model1 = new PropertyModel<>(object1, provider.getSort().getProperty()); + IModel<Comparable> model2 = new PropertyModel<>(object2, provider.getSort().getProperty()); + + return compare(model1, model2); + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/39f8a069/client/old_console/src/main/java/org/apache/syncope/client/console/commons/XMLRolesReader.java ---------------------------------------------------------------------- diff --git a/client/old_console/src/main/java/org/apache/syncope/client/console/commons/XMLRolesReader.java b/client/old_console/src/main/java/org/apache/syncope/client/console/commons/XMLRolesReader.java new file mode 100644 index 0000000..3a0b446 --- /dev/null +++ b/client/old_console/src/main/java/org/apache/syncope/client/console/commons/XMLRolesReader.java @@ -0,0 +1,118 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.console.commons; + +import java.util.HashMap; +import java.util.Map; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.apache.commons.lang3.tuple.Pair; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** + * XMLRolesReader singleton class. + */ +public class XMLRolesReader { + + /** + * Logger. + */ + private static final Logger LOG = LoggerFactory.getLogger(XMLRolesReader.class); + + private String authorizations; + + private Map<Pair<String, String>, String> authMap; + + public void setAuthorizations(final String authorizations) { + this.authorizations = authorizations; + } + + private void init() { + authMap = new HashMap<Pair<String, String>, String>(); + + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + try { + DocumentBuilder db = dbf.newDocumentBuilder(); + Document doc = db.parse(getClass().getResource("/" + authorizations).openStream()); + doc.getDocumentElement().normalize(); + + Node authNode = null; + NodeList root = doc.getChildNodes(); + for (int i = 0; i < root.getLength() && authNode == null; i++) { + if ("auth".equals(root.item(i).getNodeName())) { + authNode = root.item(i); + } + } + if (authNode == null) { + throw new IllegalArgumentException("Could not find root <auth> node"); + } + + NodeList pages = authNode.getChildNodes(); + for (int i = 0; i < pages.getLength(); i++) { + if ("page".equals(pages.item(i).getNodeName())) { + String page = pages.item(i).getAttributes().getNamedItem("id").getTextContent(); + + NodeList actions = pages.item(i).getChildNodes(); + for (int j = 0; j < actions.getLength(); j++) { + if ("action".equals(actions.item(j).getNodeName())) { + String action = actions.item(j).getAttributes().getNamedItem("id").getTextContent(); + + NodeList entitlements = actions.item(j).getChildNodes(); + for (int k = 0; k < entitlements.getLength(); k++) { + if ("entitlement".equals(entitlements.item(k).getNodeName())) { + String entitlement = entitlements.item(k).getTextContent(); + authMap.put(new ImmutablePair<String, String>(page, action), entitlement); + } + } + } + } + } + } + } catch (Exception e) { + LOG.error("While initializing parsing of {}", authorizations, e); + } + } + + /** + * Get entitlement required for page / action. + * + * @param pageId page + * @param actionId action + * @return entitlement required + */ + public String getEntitlement(final String pageId, final String actionId) { + synchronized (this) { + if (authMap == null) { + init(); + } + } + + Pair<String, String> key = new ImmutablePair<String, String>(pageId, actionId); + return authMap.containsKey(key) + ? authMap.get(key) + : StringUtils.EMPTY; + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/39f8a069/client/old_console/src/main/java/org/apache/syncope/client/console/commons/status/AbstractStatusBeanProvider.java ---------------------------------------------------------------------- diff --git a/client/old_console/src/main/java/org/apache/syncope/client/console/commons/status/AbstractStatusBeanProvider.java b/client/old_console/src/main/java/org/apache/syncope/client/console/commons/status/AbstractStatusBeanProvider.java new file mode 100644 index 0000000..c10f55c --- /dev/null +++ b/client/old_console/src/main/java/org/apache/syncope/client/console/commons/status/AbstractStatusBeanProvider.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.console.commons.status; + +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import org.apache.syncope.client.console.commons.SortableDataProviderComparator; +import org.apache.wicket.extensions.markup.html.repeater.data.sort.SortOrder; +import org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider; +import org.apache.wicket.model.AbstractReadOnlyModel; +import org.apache.wicket.model.IModel; + +public abstract class AbstractStatusBeanProvider extends SortableDataProvider<StatusBean, String> { + + private static final long serialVersionUID = 4287357360778016173L; + + private SortableDataProviderComparator<StatusBean> comparator; + + public AbstractStatusBeanProvider(final String sort) { + //Default sorting + setSort(sort, SortOrder.ASCENDING); + comparator = new SortableDataProviderComparator<StatusBean>(this); + } + + @Override + public Iterator<StatusBean> iterator(final long first, final long count) { + List<StatusBean> list = getStatusBeans(); + Collections.sort(list, comparator); + return list.subList((int) first, (int) first + (int) count).iterator(); + } + + @Override + public long size() { + return getStatusBeans().size(); + } + + @Override + public IModel<StatusBean> model(final StatusBean resource) { + return new AbstractReadOnlyModel<StatusBean>() { + + private static final long serialVersionUID = -7802635613997243712L; + + @Override + public StatusBean getObject() { + return resource; + } + }; + } + + public abstract List<StatusBean> getStatusBeans(); + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/39f8a069/client/old_console/src/main/java/org/apache/syncope/client/console/commons/status/ConnObjectWrapper.java ---------------------------------------------------------------------- diff --git a/client/old_console/src/main/java/org/apache/syncope/client/console/commons/status/ConnObjectWrapper.java b/client/old_console/src/main/java/org/apache/syncope/client/console/commons/status/ConnObjectWrapper.java new file mode 100644 index 0000000..be038db --- /dev/null +++ b/client/old_console/src/main/java/org/apache/syncope/client/console/commons/status/ConnObjectWrapper.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.console.commons.status; + +import java.io.Serializable; +import org.apache.syncope.common.lib.to.AbstractAttributableTO; +import org.apache.syncope.common.lib.to.ConnObjectTO; + +public class ConnObjectWrapper implements Serializable { + + private static final long serialVersionUID = 9083721948999924299L; + + private final AbstractAttributableTO attributable; + + private final String resourceName; + + private final ConnObjectTO connObjectTO; + + public ConnObjectWrapper(final AbstractAttributableTO attributable, final String resourceName, + final ConnObjectTO connObjectTO) { + + this.attributable = attributable; + this.resourceName = resourceName; + this.connObjectTO = connObjectTO; + } + + public AbstractAttributableTO getAttributable() { + return attributable; + } + + public String getResourceName() { + return resourceName; + } + + public ConnObjectTO getConnObjectTO() { + return connObjectTO; + } + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/39f8a069/client/old_console/src/main/java/org/apache/syncope/client/console/commons/status/Status.java ---------------------------------------------------------------------- diff --git a/client/old_console/src/main/java/org/apache/syncope/client/console/commons/status/Status.java b/client/old_console/src/main/java/org/apache/syncope/client/console/commons/status/Status.java new file mode 100644 index 0000000..7198c2c --- /dev/null +++ b/client/old_console/src/main/java/org/apache/syncope/client/console/commons/status/Status.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.console.commons.status; + +public enum Status { + + NOT_YET_SUBMITTED(""), + CREATED("created"), + ACTIVE("active"), + SUSPENDED("inactive"), + UNDEFINED("undefined"), + OBJECT_NOT_FOUND("objectnotfound"); + + public boolean isActive() { + return this == ACTIVE; + } + + private Status(final String name) { + this.name = name; + } + + private final String name; + + @Override + public String toString() { + return name; + } + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/39f8a069/client/old_console/src/main/java/org/apache/syncope/client/console/commons/status/StatusBean.java ---------------------------------------------------------------------- diff --git a/client/old_console/src/main/java/org/apache/syncope/client/console/commons/status/StatusBean.java b/client/old_console/src/main/java/org/apache/syncope/client/console/commons/status/StatusBean.java new file mode 100644 index 0000000..47d0086 --- /dev/null +++ b/client/old_console/src/main/java/org/apache/syncope/client/console/commons/status/StatusBean.java @@ -0,0 +1,103 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.console.commons.status; + +import java.io.Serializable; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import org.apache.syncope.common.lib.to.AbstractAttributableTO; +import org.apache.syncope.common.lib.to.GroupTO; +import org.apache.syncope.common.lib.to.UserTO; + +public class StatusBean implements Serializable { + + private static final long serialVersionUID = -5207260204921071129L; + + private final Long attributableKey; + + private final String attributableName; + + private final String resourceName; + + private String accountLink = null; + + private Status status = Status.OBJECT_NOT_FOUND; + + private boolean linked = true; + + public StatusBean(final AbstractAttributableTO attributable, String resourceName) { + this.attributableKey = attributable.getKey(); + this.attributableName = attributable instanceof UserTO + ? ((UserTO) attributable).getUsername() : ((GroupTO) attributable).getName(); + this.resourceName = resourceName; + } + + public String getAccountLink() { + return accountLink; + } + + public void setAccountLink(final String accountLink) { + this.accountLink = accountLink; + } + + public String getResourceName() { + return resourceName; + } + + public Status getStatus() { + return status; + } + + public void setStatus(final Status status) { + this.status = status; + } + + public Long getAttributableId() { + return attributableKey; + } + + public String getAttributableName() { + return attributableName; + } + + public boolean isLinked() { + return linked; + } + + public void setLinked(boolean linked) { + this.linked = linked; + } + + @Override + public String toString() { + return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE); + } + + @Override + public boolean equals(final Object obj) { + return EqualsBuilder.reflectionEquals(this, obj); + } + + @Override + public int hashCode() { + return HashCodeBuilder.reflectionHashCode(this); + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/39f8a069/client/old_console/src/main/java/org/apache/syncope/client/console/commons/status/StatusUtils.java ---------------------------------------------------------------------- diff --git a/client/old_console/src/main/java/org/apache/syncope/client/console/commons/status/StatusUtils.java b/client/old_console/src/main/java/org/apache/syncope/client/console/commons/status/StatusUtils.java new file mode 100644 index 0000000..391d202 --- /dev/null +++ b/client/old_console/src/main/java/org/apache/syncope/client/console/commons/status/StatusUtils.java @@ -0,0 +1,324 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.console.commons.status; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import org.apache.syncope.client.console.commons.ConnIdSpecialAttributeName; +import org.apache.syncope.client.console.commons.Constants; +import org.apache.syncope.client.console.panels.ImagePanel; +import org.apache.syncope.client.console.panels.StatusPanel; +import org.apache.syncope.client.console.rest.AbstractSubjectRestClient; +import org.apache.syncope.common.lib.mod.StatusMod; +import org.apache.syncope.common.lib.to.AbstractAttributableTO; +import org.apache.syncope.common.lib.to.AbstractSubjectTO; +import org.apache.syncope.common.lib.to.AttrTO; +import org.apache.syncope.common.lib.to.ConnObjectTO; +import org.apache.wicket.Component; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.behavior.Behavior; +import org.apache.wicket.markup.ComponentTag; +import org.apache.wicket.markup.html.image.Image; +import org.apache.wicket.request.resource.ContextRelativeResource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class StatusUtils implements Serializable { + + private static final long serialVersionUID = 7238009174387184309L; + + /** + * Logger. + */ + private static final Logger LOG = LoggerFactory.getLogger(StatusUtils.class); + + private static final String IMG_PREFIX = "/img/statuses/"; + + private final AbstractSubjectRestClient restClient; + + public StatusUtils(final AbstractSubjectRestClient restClient) { + this.restClient = restClient; + } + + public List<ConnObjectWrapper> getConnectorObjects(final AbstractSubjectTO subject) { + final List<ConnObjectWrapper> objects = new ArrayList<>(); + objects.addAll(getConnectorObjects(subject, subject.getResources())); + return objects; + } + + public List<ConnObjectWrapper> getConnectorObjects( + final Collection<AbstractSubjectTO> subjects, final Collection<String> resources) { + + final List<ConnObjectWrapper> objects = new ArrayList<>(); + + for (AbstractSubjectTO subject : subjects) { + objects.addAll(getConnectorObjects(subject, resources)); + } + + return objects; + } + + private List<ConnObjectWrapper> getConnectorObjects( + final AbstractSubjectTO subject, final Collection<String> resources) { + + final List<ConnObjectWrapper> objects = new ArrayList<>(); + + for (String resourceName : resources) { + ConnObjectTO objectTO = null; + try { + objectTO = restClient.getConnectorObject(resourceName, subject.getKey()); + } catch (Exception e) { + LOG.warn("ConnObject '{}' not found on resource '{}'", subject.getKey(), resourceName); + } + + objects.add(new ConnObjectWrapper(subject, resourceName, objectTO)); + } + + return objects; + } + + public StatusBean getStatusBean( + final AbstractAttributableTO attributable, + final String resourceName, + final ConnObjectTO objectTO, + final boolean isGroup) { + + final StatusBean statusBean = new StatusBean(attributable, resourceName); + + if (objectTO != null) { + final Boolean enabled = isEnabled(objectTO); + + final Status status = enabled == null + ? (isGroup ? Status.ACTIVE : Status.UNDEFINED) + : enabled + ? Status.ACTIVE + : Status.SUSPENDED; + + final String accountLink = getAccountLink(objectTO); + + statusBean.setStatus(status); + statusBean.setAccountLink(accountLink); + } + + return statusBean; + } + + private Boolean isEnabled(final ConnObjectTO objectTO) { + final Map<String, AttrTO> attributeTOs = objectTO.getPlainAttrMap(); + + final AttrTO status = attributeTOs.get(ConnIdSpecialAttributeName.ENABLE); + + return status != null && status.getValues() != null && !status.getValues().isEmpty() + ? Boolean.parseBoolean(status.getValues().get(0)) + : null; + } + + private String getAccountLink(final ConnObjectTO objectTO) { + final Map<String, AttrTO> attributeTOs = objectTO == null + ? Collections.<String, AttrTO>emptyMap() + : objectTO.getPlainAttrMap(); + + final AttrTO name = attributeTOs.get(ConnIdSpecialAttributeName.NAME); + + return name != null && name.getValues() != null && !name.getValues().isEmpty() + ? name.getValues().get(0) + : null; + } + + public static StatusMod buildStatusMod(final Collection<StatusBean> statuses) { + return buildStatusMod(statuses, null); + } + + public static StatusMod buildStatusMod(final Collection<StatusBean> statuses, final Boolean enable) { + StatusMod statusMod = new StatusMod(); + statusMod.setOnSyncope(false); + + for (StatusBean status : statuses) { + if (enable == null + || (enable && !status.getStatus().isActive()) || (!enable && status.getStatus().isActive())) { + + if ("syncope".equalsIgnoreCase(status.getResourceName())) { + statusMod.setOnSyncope(true); + } else { + statusMod.getResourceNames().add(status.getResourceName()); + } + + } + } + + return statusMod; + } + + public static void update( + final AbstractAttributableTO attributable, + final StatusPanel statusPanel, + final AjaxRequestTarget target, + final Collection<String> resourcesToAdd, + final Collection<String> resourcesToRemove) { + + if (statusPanel != null) { + Map<String, StatusBean> statusMap = new LinkedHashMap<>(); + for (StatusBean statusBean : statusPanel.getStatusBeans()) { + statusMap.put(statusBean.getResourceName(), statusBean); + } + + for (String resourceName : resourcesToAdd) { + if (!statusMap.keySet().contains(resourceName)) { + StatusBean statusBean; + if (statusPanel.getInitialStatusBeanMap().containsKey(resourceName)) { + statusBean = statusPanel.getInitialStatusBeanMap().get(resourceName); + } else { + statusBean = new StatusBean(attributable, resourceName); + statusBean.setStatus(Status.NOT_YET_SUBMITTED); + } + + statusMap.put(statusBean.getResourceName(), statusBean); + } + } + + for (String resource : resourcesToRemove) { + statusMap.remove(resource); + } + + statusPanel.updateStatusBeans(new ArrayList<>(statusMap.values())); + target.add(statusPanel); + } + } + + public ConnObjectTO getConnObjectTO( + final Long attributableId, final String resourceName, final List<ConnObjectWrapper> objects) { + + for (ConnObjectWrapper object : objects) { + if (attributableId.equals(object.getAttributable().getKey()) + && resourceName.equalsIgnoreCase(object.getResourceName())) { + + return object.getConnObjectTO(); + } + } + + return null; + } + + public Image getStatusImage(final String componentId, final Status status) { + final String alt, title, statusName; + + switch (status) { + + case NOT_YET_SUBMITTED: + statusName = Status.UNDEFINED.toString(); + alt = "undefined icon"; + title = "Not yet submitted"; + break; + + case ACTIVE: + statusName = Status.ACTIVE.toString(); + alt = "active icon"; + title = "Enabled"; + break; + + case UNDEFINED: + statusName = Status.UNDEFINED.toString(); + alt = "undefined icon"; + title = "Undefined status"; + break; + + case OBJECT_NOT_FOUND: + statusName = Status.OBJECT_NOT_FOUND.toString(); + alt = "notfound icon"; + title = "Not found"; + break; + + default: + statusName = Status.SUSPENDED.toString(); + alt = "inactive icon"; + title = "Disabled"; + } + + final Image img = new Image(componentId, + new ContextRelativeResource(IMG_PREFIX + statusName + Constants.PNG_EXT)); + img.add(new Behavior() { + + private static final long serialVersionUID = 1469628524240283489L; + + @Override + public void onComponentTag(final Component component, final ComponentTag tag) { + tag.put("alt", alt); + tag.put("title", title); + } + }); + + return img; + } + + public ImagePanel getStatusImagePanel(final String componentId, final Status status) { + final String alt, title, statusName; + + switch (status) { + + case NOT_YET_SUBMITTED: + statusName = Status.UNDEFINED.toString(); + alt = "undefined icon"; + title = "Not yet submitted"; + break; + + case ACTIVE: + statusName = Status.ACTIVE.toString(); + alt = "active icon"; + title = "Enabled"; + break; + + case UNDEFINED: + statusName = Status.UNDEFINED.toString(); + alt = "undefined icon"; + title = "Undefined status"; + break; + + case OBJECT_NOT_FOUND: + statusName = Status.OBJECT_NOT_FOUND.toString(); + alt = "notfound icon"; + title = "Not found"; + break; + + default: + statusName = Status.SUSPENDED.toString(); + alt = "inactive icon"; + title = "Disabled"; + } + + final ImagePanel imagePanel = new ImagePanel(componentId, + new ContextRelativeResource(IMG_PREFIX + statusName + Constants.PNG_EXT)); + imagePanel.add(new Behavior() { + + private static final long serialVersionUID = 1469628524240283489L; + + @Override + public void onComponentTag(final Component component, final ComponentTag tag) { + tag.put("alt", alt); + tag.put("title", title); + } + }); + + return imagePanel; + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/39f8a069/client/old_console/src/main/java/org/apache/syncope/client/console/init/ConsoleInitializer.java ---------------------------------------------------------------------- diff --git a/client/old_console/src/main/java/org/apache/syncope/client/console/init/ConsoleInitializer.java b/client/old_console/src/main/java/org/apache/syncope/client/console/init/ConsoleInitializer.java new file mode 100644 index 0000000..ec51d3e --- /dev/null +++ b/client/old_console/src/main/java/org/apache/syncope/client/console/init/ConsoleInitializer.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.console.init; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.aop.support.AopUtils; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.BeanFactory; +import org.springframework.beans.factory.BeanFactoryAware; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.beans.factory.support.DefaultListableBeanFactory; +import org.springframework.stereotype.Component; + +/** + * Take care of all initializations needed by Syncope Console to run up and safe. + */ +@Component +public class ConsoleInitializer implements InitializingBean, BeanFactoryAware { + + private static final Logger LOG = LoggerFactory.getLogger(ConsoleInitializer.class); + + private DefaultListableBeanFactory beanFactory; + + @Override + public void setBeanFactory(final BeanFactory beanFactory) throws BeansException { + this.beanFactory = (DefaultListableBeanFactory) beanFactory; + } + + @Override + public void afterPropertiesSet() { + Map<String, SyncopeConsoleLoader> loaderMap = beanFactory.getBeansOfType(SyncopeConsoleLoader.class); + + List<SyncopeConsoleLoader> loaders = new ArrayList<>(loaderMap.values()); + Collections.sort(loaders, new Comparator<SyncopeConsoleLoader>() { + + @Override + public int compare(final SyncopeConsoleLoader o1, final SyncopeConsoleLoader o2) { + return o1.getPriority().compareTo(o2.getPriority()); + } + }); + + LOG.debug("Starting initialization..."); + for (SyncopeConsoleLoader loader : loaders) { + LOG.debug("Invoking {} with priority {}", AopUtils.getTargetClass(loader).getName(), loader.getPriority()); + loader.load(); + } + LOG.debug("Initialization completed"); + } + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/39f8a069/client/old_console/src/main/java/org/apache/syncope/client/console/init/ImplementationClassNamesLoader.java ---------------------------------------------------------------------- diff --git a/client/old_console/src/main/java/org/apache/syncope/client/console/init/ImplementationClassNamesLoader.java b/client/old_console/src/main/java/org/apache/syncope/client/console/init/ImplementationClassNamesLoader.java new file mode 100644 index 0000000..0ff7282 --- /dev/null +++ b/client/old_console/src/main/java/org/apache/syncope/client/console/init/ImplementationClassNamesLoader.java @@ -0,0 +1,109 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.console.init; + +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.syncope.client.console.panels.AbstractExtensionPanel; +import org.apache.syncope.client.console.BinaryPreview; +import org.apache.syncope.client.console.wicket.markup.html.form.preview.AbstractBinaryPreviewer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; +import org.springframework.core.type.filter.AssignableTypeFilter; +import org.springframework.stereotype.Component; +import org.springframework.util.ClassUtils; + +@Component +public class ImplementationClassNamesLoader implements SyncopeConsoleLoader { + + /** + * Logger. + */ + private static final Logger LOG = LoggerFactory.getLogger(ImplementationClassNamesLoader.class); + + private List<Class<? extends AbstractBinaryPreviewer>> previewers; + + private List<Class<? extends AbstractExtensionPanel>> extPanels; + + @Override + public Integer getPriority() { + return 0; + } + + @Override + @SuppressWarnings("unchecked") + public void load() { + previewers = new ArrayList<>(); + extPanels = new ArrayList<>(); + + ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false); + scanner.addIncludeFilter(new AssignableTypeFilter(AbstractBinaryPreviewer.class)); + scanner.addIncludeFilter(new AssignableTypeFilter(AbstractExtensionPanel.class)); + + for (BeanDefinition bd : scanner.findCandidateComponents(StringUtils.EMPTY)) { + try { + Class<?> clazz = ClassUtils.resolveClassName( + bd.getBeanClassName(), ClassUtils.getDefaultClassLoader()); + boolean isAbsractClazz = Modifier.isAbstract(clazz.getModifiers()); + + if (AbstractBinaryPreviewer.class.isAssignableFrom(clazz) && !isAbsractClazz) { + previewers.add((Class<? extends AbstractBinaryPreviewer>) clazz); + } else if (AbstractExtensionPanel.class.isAssignableFrom(clazz) && !isAbsractClazz) { + extPanels.add((Class<? extends AbstractExtensionPanel>) clazz); + } + + } catch (Throwable t) { + LOG.warn("Could not inspect class {}", bd.getBeanClassName(), t); + } + } + previewers = Collections.unmodifiableList(previewers); + extPanels = Collections.unmodifiableList(extPanels); + + LOG.debug("Binary previewers found: {}", previewers); + LOG.debug("Extension panels found: {}", extPanels); + } + + public Class<? extends AbstractBinaryPreviewer> getPreviewerClass(final String mimeType) { + LOG.debug("Searching for previewer class for MIME type: {}", mimeType); + Class<? extends AbstractBinaryPreviewer> previewer = null; + for (Class<? extends AbstractBinaryPreviewer> candidate : previewers) { + LOG.debug("Evaluating previewer class {} for MIME type {}", candidate.getName(), mimeType); + if (ArrayUtils.contains(candidate.getAnnotation(BinaryPreview.class).mimeTypes(), mimeType)) { + LOG.debug("Found existing previewer for MIME type {}: {}", mimeType, candidate.getName()); + previewer = candidate; + } + } + return previewer; + } + + public List<Class<? extends AbstractBinaryPreviewer>> getPreviewerClasses() { + return previewers; + } + + public List<Class<? extends AbstractExtensionPanel>> getExtPanelClasses() { + return extPanels; + } + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/39f8a069/client/old_console/src/main/java/org/apache/syncope/client/console/init/MIMETypesLoader.java ---------------------------------------------------------------------- diff --git a/client/old_console/src/main/java/org/apache/syncope/client/console/init/MIMETypesLoader.java b/client/old_console/src/main/java/org/apache/syncope/client/console/init/MIMETypesLoader.java new file mode 100644 index 0000000..7a2f878 --- /dev/null +++ b/client/old_console/src/main/java/org/apache/syncope/client/console/init/MIMETypesLoader.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.console.init; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import org.apache.commons.lang3.StringUtils; +import org.apache.wicket.util.io.IOUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +@Component +public class MIMETypesLoader implements SyncopeConsoleLoader { + + /** + * Logger. + */ + private static final Logger LOG = LoggerFactory.getLogger(MIMETypesLoader.class); + + private List<String> mimeTypes; + + @Override + public Integer getPriority() { + return 10; + } + + @Override + public void load() { + final Set<String> mediaTypes = new HashSet<>(); + this.mimeTypes = new ArrayList<>(); + try { + final String mimeTypesFile = IOUtils.toString(getClass().getResourceAsStream("/MIMETypes")); + for (String fileRow : mimeTypesFile.split("\n")) { + if (StringUtils.isNotBlank(fileRow) && !fileRow.startsWith("#")) { + mediaTypes.add(fileRow); + } + } + this.mimeTypes.addAll(mediaTypes); + Collections.sort(this.mimeTypes); + } catch (Exception e) { + LOG.error("Error reading file MIMETypes from resources", e); + } + } + + public List<String> getMimeTypes() { + LOG.debug("Returning loaded MIME types list {}", mimeTypes); + return mimeTypes; + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/39f8a069/client/old_console/src/main/java/org/apache/syncope/client/console/init/SyncopeConsoleLoader.java ---------------------------------------------------------------------- diff --git a/client/old_console/src/main/java/org/apache/syncope/client/console/init/SyncopeConsoleLoader.java b/client/old_console/src/main/java/org/apache/syncope/client/console/init/SyncopeConsoleLoader.java new file mode 100644 index 0000000..7c4d3d4 --- /dev/null +++ b/client/old_console/src/main/java/org/apache/syncope/client/console/init/SyncopeConsoleLoader.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.console.init; + +/** + * Marker interface for Syncope console initialization. + */ +public interface SyncopeConsoleLoader { + + /** + * @return the priority that the implementing class has in the initialization process. + */ + Integer getPriority(); + + /** + * Perform initialization operations. + */ + void load(); +} http://git-wip-us.apache.org/repos/asf/syncope/blob/39f8a069/client/old_console/src/main/java/org/apache/syncope/client/console/pages/AbstractBasePage.java ---------------------------------------------------------------------- diff --git a/client/old_console/src/main/java/org/apache/syncope/client/console/pages/AbstractBasePage.java b/client/old_console/src/main/java/org/apache/syncope/client/console/pages/AbstractBasePage.java new file mode 100644 index 0000000..830f369 --- /dev/null +++ b/client/old_console/src/main/java/org/apache/syncope/client/console/pages/AbstractBasePage.java @@ -0,0 +1,131 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.console.pages; + +import org.apache.syncope.client.console.commons.Constants; +import org.apache.syncope.client.console.commons.XMLRolesReader; +import org.apache.syncope.client.console.init.MIMETypesLoader; +import org.apache.syncope.client.console.panels.NotificationPanel; +import org.apache.syncope.client.console.rest.ConfigurationRestClient; +import org.apache.syncope.client.console.rest.ReportRestClient; +import org.apache.syncope.client.console.rest.ResourceRestClient; +import org.apache.syncope.client.console.rest.GroupRestClient; +import org.apache.syncope.client.console.rest.SchemaRestClient; +import org.apache.syncope.client.console.rest.TaskRestClient; +import org.apache.syncope.client.console.rest.UserRestClient; +import org.apache.syncope.client.console.rest.UserSelfRestClient; +import org.apache.syncope.client.console.wicket.markup.head.MetaHeaderItem; +import org.apache.wicket.markup.head.HeaderItem; +import org.apache.wicket.markup.head.IHeaderResponse; +import org.apache.wicket.markup.head.PriorityHeaderItem; +import org.apache.wicket.markup.html.WebPage; +import org.apache.wicket.request.mapper.parameter.PageParameters; +import org.apache.wicket.spring.injection.annot.SpringBean; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class AbstractBasePage extends WebPage { + + private static final long serialVersionUID = 8611724965544132636L; + + /** + * Logger. + */ + protected static final Logger LOG = LoggerFactory.getLogger(AbstractBasePage.class); + + protected static final String TASKS = "Tasks"; + + protected static final String FORM = "form"; + + protected static final String CANCEL = "cancel"; + + protected static final String SUBMIT = "submit"; + + protected static final String APPLY = "apply"; + + protected final HeaderItem meta = new MetaHeaderItem("X-UA-Compatible", "IE=edge"); + + @SpringBean + protected XMLRolesReader xmlRolesReader; + + @SpringBean + protected UserRestClient userRestClient; + + @SpringBean + protected UserSelfRestClient userSelfRestClient; + + @SpringBean + protected GroupRestClient groupRestClient; + + @SpringBean + protected TaskRestClient taskRestClient; + + @SpringBean + protected SchemaRestClient schemaRestClient; + + @SpringBean + protected ResourceRestClient resourceRestClient; + + @SpringBean + protected ReportRestClient reportRestClient; + + @SpringBean + protected ConfigurationRestClient confRestClient; + + @SpringBean + protected MIMETypesLoader mimeTypesInitializer; + + protected NotificationPanel feedbackPanel; + + /** + * Response flag set by the Modal Window after the operation is completed. + */ + protected boolean modalResult = false; + + public AbstractBasePage() { + this(null); + } + + public AbstractBasePage(final PageParameters parameters) { + super(parameters); + + feedbackPanel = new NotificationPanel(Constants.FEEDBACK); + feedbackPanel.setOutputMarkupId(true); + add(feedbackPanel); + } + + public NotificationPanel getFeedbackPanel() { + return feedbackPanel; + } + + public boolean isModalResult() { + return modalResult; + } + + public void setModalResult(final boolean operationResult) { + this.modalResult = operationResult; + } + + @Override + public void renderHead(final IHeaderResponse response) { + super.renderHead(response); + response.render(new PriorityHeaderItem(meta)); + } + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/39f8a069/client/old_console/src/main/java/org/apache/syncope/client/console/pages/AbstractSchedTaskModalPage.java ---------------------------------------------------------------------- diff --git a/client/old_console/src/main/java/org/apache/syncope/client/console/pages/AbstractSchedTaskModalPage.java b/client/old_console/src/main/java/org/apache/syncope/client/console/pages/AbstractSchedTaskModalPage.java new file mode 100644 index 0000000..78ca906 --- /dev/null +++ b/client/old_console/src/main/java/org/apache/syncope/client/console/pages/AbstractSchedTaskModalPage.java @@ -0,0 +1,132 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.console.pages; + +import org.apache.syncope.client.console.commons.Constants; +import org.apache.syncope.client.console.commons.DateFormatROModel; +import org.apache.syncope.client.console.wicket.markup.html.CrontabContainer; +import org.apache.syncope.client.console.wicket.markup.html.form.AjaxTextFieldPanel; +import org.apache.syncope.common.lib.SyncopeClientException; +import org.apache.syncope.common.lib.to.SchedTaskTO; +import org.apache.wicket.PageReference; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.ajax.markup.html.form.AjaxButton; +import org.apache.wicket.authroles.authorization.strategies.role.metadata.MetaDataRoleAuthorizationStrategy; +import org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxButton; +import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow; +import org.apache.wicket.markup.html.form.Form; +import org.apache.wicket.model.PropertyModel; +import org.apache.wicket.model.ResourceModel; +import org.springframework.util.StringUtils; + +/** + * Modal window with Task form (to stop and start execution). + */ +public abstract class AbstractSchedTaskModalPage extends TaskModalPage { + + private static final long serialVersionUID = 2892005971093059242L; + + protected CrontabContainer crontab; + + public AbstractSchedTaskModalPage(final ModalWindow window, final SchedTaskTO taskTO, + final PageReference pageRef) { + + super(taskTO); + + crontab = new CrontabContainer("crontab", new PropertyModel<String>(taskTO, "cronExpression"), + taskTO.getCronExpression()); + form.add(crontab); + + final AjaxTextFieldPanel name = + new AjaxTextFieldPanel("name", "name", new PropertyModel<String>(taskTO, "name")); + name.setEnabled(true); + profile.add(name); + + final AjaxTextFieldPanel description = new AjaxTextFieldPanel("description", "description", + new PropertyModel<String>(taskTO, "description")); + description.setEnabled(true); + profile.add(description); + + final AjaxTextFieldPanel lastExec = new AjaxTextFieldPanel("lastExec", getString("lastExec"), + new DateFormatROModel(new PropertyModel<String>(taskTO, "lastExec"))); + lastExec.setEnabled(false); + profile.add(lastExec); + + final AjaxTextFieldPanel nextExec = new AjaxTextFieldPanel("nextExec", getString("nextExec"), + new DateFormatROModel(new PropertyModel<String>(taskTO, "nextExec"))); + nextExec.setEnabled(false); + profile.add(nextExec); + + final AjaxButton submit = new IndicatingAjaxButton(APPLY, new ResourceModel(APPLY)) { + + private static final long serialVersionUID = -958724007591692537L; + + @Override + protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) { + SchedTaskTO taskTO = (SchedTaskTO) form.getModelObject(); + taskTO.setCronExpression(StringUtils.hasText(taskTO.getCronExpression()) + ? crontab.getCronExpression() + : null); + + try { + submitAction(taskTO); + + ((BasePage) pageRef.getPage()).setModalResult(true); + + window.close(target); + } catch (SyncopeClientException e) { + LOG.error("While creating or updating task", e); + error(getString(Constants.ERROR) + ": " + e.getMessage()); + feedbackPanel.refresh(target); + } + } + + @Override + protected void onError(final AjaxRequestTarget target, final Form<?> form) { + feedbackPanel.refresh(target); + } + }; + + final AjaxButton cancel = new IndicatingAjaxButton(CANCEL, new ResourceModel(CANCEL)) { + + private static final long serialVersionUID = -958724007591692537L; + + @Override + protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) { + window.close(target); + } + }; + + cancel.setDefaultFormProcessing(false); + + if (taskTO.getKey() > 0) { + MetaDataRoleAuthorizationStrategy.authorize( + submit, RENDER, xmlRolesReader.getEntitlement(TASKS, "update")); + } else { + MetaDataRoleAuthorizationStrategy.authorize( + submit, RENDER, xmlRolesReader.getEntitlement(TASKS, "create")); + } + + form.add(submit); + form.add(cancel); + } + + protected abstract void submitAction(SchedTaskTO taskTO); + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/39f8a069/client/old_console/src/main/java/org/apache/syncope/client/console/pages/AbstractSchemaModalPage.java ---------------------------------------------------------------------- diff --git a/client/old_console/src/main/java/org/apache/syncope/client/console/pages/AbstractSchemaModalPage.java b/client/old_console/src/main/java/org/apache/syncope/client/console/pages/AbstractSchemaModalPage.java new file mode 100644 index 0000000..1c1bd0f --- /dev/null +++ b/client/old_console/src/main/java/org/apache/syncope/client/console/pages/AbstractSchemaModalPage.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.console.pages; + +import org.apache.syncope.common.lib.to.AbstractSchemaTO; +import org.apache.syncope.common.lib.types.AttributableType; +import org.apache.wicket.PageReference; +import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow; + +/** + * Modal window with Schema form. + */ +public abstract class AbstractSchemaModalPage<T extends AbstractSchemaTO> extends BaseModalPage { + + private static final long serialVersionUID = 7369215690388444748L; + + protected AttributableType kind; + + public AbstractSchemaModalPage(final AttributableType kind) { + this.kind = kind; + } + + public abstract void setSchemaModalPage(PageReference callerPageRef, ModalWindow window, T schema, + boolean createFlag); + + public AttributableType getKind() { + return kind; + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/39f8a069/client/old_console/src/main/java/org/apache/syncope/client/console/pages/AbstractStatusModalPage.java ---------------------------------------------------------------------- diff --git a/client/old_console/src/main/java/org/apache/syncope/client/console/pages/AbstractStatusModalPage.java b/client/old_console/src/main/java/org/apache/syncope/client/console/pages/AbstractStatusModalPage.java new file mode 100644 index 0000000..f5dfbca --- /dev/null +++ b/client/old_console/src/main/java/org/apache/syncope/client/console/pages/AbstractStatusModalPage.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.console.pages; + +import org.apache.wicket.markup.html.panel.Fragment; + +public class AbstractStatusModalPage extends BaseModalPage { + + private static final long serialVersionUID = 6633408683036028540L; + + public AbstractStatusModalPage() { + add(new Fragment("pwdMgtFields", "emptyFragment", this)); + } +}
