Commit fbb2a21c authored by Raj Shah's avatar Raj Shah
Browse files

Release 3.2.51

parent 7f5e9d2c
......@@ -85,7 +85,7 @@ public class PolicyIdUtil {
if (URN_POLICY_PATTERN.matcher(urn).matches()) {
setILPAttributesByUrn(urn, instance);
} else {
throw new IllegalArgumentException("URN " + " " + urn + " does not match the pattern " + URN_POLICY_PATTERN);
throw new IllegalArgumentException("URN " + urn + " does not match the pattern " + URN_POLICY_PATTERN);
}
}
......
......@@ -33,8 +33,8 @@ import java.lang.reflect.Type;
/**
* A value of a certain {@link DataType} that is currently supported by IND2UCE.
*
* @author Fraunhofer IESE
* @param <T> the type of the value. Must be one of {@link DataType}.
* @author Fraunhofer IESE
*/
public class DataObject<T> extends Ind2uceEntity {
......@@ -48,6 +48,11 @@ public class DataObject<T> extends Ind2uceEntity {
*/
private static final Logger log = LoggerFactory.getLogger("DataObject<T>");
/**
* Indicates a complex type.
*/
boolean isComplex = false;
/**
* The value.
*/
......@@ -58,12 +63,18 @@ public class DataObject<T> extends Ind2uceEntity {
*/
private String type;
/** Indicates a complex type. */
boolean isComplex = false;
/** *. */
/**
* .
*/
private transient Type javaType;
/**
* Used for JAXB
*/
public DataObject() {
}
/**
* Instantiates a new data object.
*
......@@ -148,13 +159,22 @@ public class DataObject<T> extends Ind2uceEntity {
return true;
}
// /**
// * Gets the java type.
// *
// * @return the java type
// */
// public Type internJavaType() {
// return this.javaType;
// }
/**
* Gets the java type.
* Sets the java type.
*
* @return the java type
* @param javaType the new java type
*/
public Type getJavaType() {
return this.javaType;
public void setJavaType(Type javaType) {
this.javaType = javaType;
}
/**
......@@ -171,6 +191,15 @@ public class DataObject<T> extends Ind2uceEntity {
}
}
/**
* Sets the type.
*
* @param type the type to set
*/
public void setType(String type) {
this.type = type;
}
/**
* Gets the type name.
*
......@@ -189,6 +218,18 @@ public class DataObject<T> extends Ind2uceEntity {
return this.value;
}
/**
* Sets the value.
*
* @param value the new value
*/
public void setValue(T value) {
this.value = value;
if (this.value != null) {
this.type = value.getClass().getCanonicalName();
}
}
/*
* (non-Javadoc)
* @see java.lang.Object#hashCode()
......@@ -210,54 +251,24 @@ public class DataObject<T> extends Ind2uceEntity {
return this.isComplex;
}
/**
* Primitive types matches.
*
* @param value the value
* @param clazz the clazz
* @return true, if successful
*/
private boolean primitiveTypesMatches(T value, Class<T> clazz) {
return Primitives.isWrapperType(value.getClass()) && Primitives.unwrap(value.getClass()) == clazz || Primitives.isWrapperType(clazz) && Primitives.unwrap(clazz) == value.getClass();
}
/**
* Sets the complex.
*
* @param b the new complex
*/
public void setComplex(boolean b) {
this.isComplex = true;
this.isComplex = b;
}
/**
* Sets the java type.
*
* @param javaType the new java type
*/
public void setJavaType(Type javaType) {
this.javaType = javaType;
}
/**
* Sets the type.
*
* @param type the type to set
*/
public void setType(String type) {
this.type = type;
}
/**
* Sets the value.
* Primitive types matches.
*
* @param value the new value
* @param value the value
* @param clazz the clazz
* @return true, if successful
*/
public void setValue(T value) {
this.value = value;
if (this.value != null) {
this.type = value.getClass().getCanonicalName();
}
private boolean primitiveTypesMatches(T value, Class<T> clazz) {
return Primitives.isWrapperType(value.getClass()) && Primitives.unwrap(value.getClass()) == clazz || Primitives.isWrapperType(clazz) && Primitives.unwrap(clazz) == value.getClass();
}
/*
......
......@@ -126,8 +126,8 @@ public class ModifierList extends ArrayList<Modifier> {
public void setParameters(ModifierList params) {
if (params != null) {
this.clear();
this.addAll(params);
}
this.addAll(params);
}
/*
......
......@@ -143,14 +143,14 @@ public class Parameter<T> extends Ind2uceEntity {
return true;
}
/**
* Gets the data object java type.
*
* @return the data object java type
*/
public Type getDataObjectJavaType() {
return this.value.getJavaType();
}
// /**
// * Gets the data object java type.
// *
// * @return the data object java type
// */
// public Type getDataObjectJavaType() {
// return this.value.internJavaType();
// }
/**
* Gets the name of the parameter.
......
/*-
* =================================LICENSE_START=================================
* IND2UCE
* %%
* Copyright (C) 2017 Fraunhofer IESE (www.iese.fraunhofer.de)
* %%
* Licensed 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.
* =================================LICENSE_END=================================
*/
package de.fraunhofer.iese.ind2uce.connectors;
/**
* Authentication Token
*/
public interface Authentication {
/**
* The identity of the principal being authenticated. In the case of an authentication
* request with username and password, this would be the username. Callers are
* expected to populate the principal for an authentication request.
* <p>
*
* @return the <code>Principal</code> being authenticated or the authenticated
* principal after authentication.
*/
Object getPrincipal();
/**
* The credentials that prove the principal is correct. This is usually a password,
* but could be anything relevant to authentication System. Callers
* are expected to populate the credentials.
*
* @return the credentials that prove the identity of the <code>Principal</code>
*/
Object getCredentials();
}
......@@ -44,9 +44,4 @@ public @interface Connector {
*/
ComponentType type();
/**
* Connector version as a string.
*/
String version();
}
......@@ -44,11 +44,15 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/**
* Helper class for establishing connections to the IND²UCE components by using
* a URI. It uses reflection to determine the type of the connector needed for a
......@@ -98,7 +102,11 @@ public final class ConnectorFactory {
}
public static IComponent getComponent(final ComponentBase base, final String preferredConnectorType) {
LOG.debug("Entering getConnector(base={}, preferredConnectorType={})", base, preferredConnectorType);
return getComponent(base, preferredConnectorType, null);
}
public static IComponent getComponent(final ComponentBase base, final String preferredConnectorType, Map<String, Authentication> protocolToAuthentication) {
LOG.trace("Entering getConnector(base={}, preferredConnectorType={})", base, preferredConnectorType);
if (null == base) {
return null;
}
......@@ -106,7 +114,7 @@ public final class ConnectorFactory {
final IComponent component;
switch (base.getType()) {
case PDP:
component = getPdp((Component)base, preferredConnectorType);
component = getPdp((Component)base, preferredConnectorType, protocolToAuthentication);
break;
case PEP:
......@@ -134,11 +142,12 @@ public final class ConnectorFactory {
break;
default:
LOG.warn("Unknown Component type {}", base.getType());
component = null;
break;
}
LOG.debug("Returning from getConnector(component={})", component);
LOG.trace("Returning from getConnector(component={})", component);
return component;
}
......@@ -156,15 +165,16 @@ public final class ConnectorFactory {
* @return A connector suitable for the specified protocol and component type,
* null in case of an error
*/
private static <T extends IComponent> T getConnector(final ComponentBase component, final ComponentType type, final String preferredConnectorType) {
LOG.debug("Entering getConnector(component={}, type={})", component, type);
private static <T extends IComponent> T getConnector(final ComponentBase component, final ComponentType type, final String preferredConnectorType,
Map<String, Authentication> protocolToAuthentication) {
LOG.info("Entering getConnector(component={}, type={})", component, type);
if (component.getUrls() == null || component.getUrls().isEmpty()) {
return null;
}
if (component.getUrls().size() == 1) {
return getConnector(component.getUrls().get(0), type,null);
return getConnector(component.getUrls().get(0), type, null);
}
URI connectorURI = null;
......@@ -194,8 +204,13 @@ public final class ConnectorFactory {
connectorURI = component.getUrls().get(0);
}
final IComponent componentConnector = getConnector(connectorURI, type, null);
LOG.debug("Leaving getConnector(): {}", componentConnector);
Authentication authenticationForConnector = null;
if (protocolToAuthentication != null && protocolToAuthentication.containsKey(connectorURI.getScheme())) {
authenticationForConnector = protocolToAuthentication.get(connectorURI.getScheme());
}
final IComponent componentConnector = getConnector(connectorURI, type, authenticationForConnector);
LOG.trace("Leaving getConnector(): {}", componentConnector);
return (T)componentConnector;
}
......@@ -211,8 +226,8 @@ public final class ConnectorFactory {
* @return A connector suitable for the specified protocol and component type,
* null in case of an error
*/
private static <T extends IComponent> T getConnector(URI url, ComponentType type, OAuthCredentials credentials) {
LOG.debug("Entering getConnector(url={}, type={})", url, type);
private static <T extends IComponent> T getConnector(@Nonnull URI url, @Nonnull ComponentType type, @Nullable Authentication authentication) {
LOG.trace("Entering getConnector(url={}, type={})", url, type);
loadClasses();
final String protocol = url.getScheme();
......@@ -231,15 +246,14 @@ public final class ConnectorFactory {
for (final Class<?> connector : connectorClasses) {
final Connector annotation = connector.getAnnotation(Connector.class);
final boolean annotationOk = annotation.type() == type;
final boolean versionOk = version == null || version.equals(annotation.version());
final boolean protocolOk = contains(annotation.protocol(), protocol);
if (annotationOk && versionOk && protocolOk) {
if (annotationOk && protocolOk) {
try {
Constructor<?> constructor = getConstructor(connector, credentials);
final T result = createInstance(url, credentials, constructor);
LOG.debug("Leaving getConnector(): {}", result);
final Constructor<?> constructor = getConstructor(connector, authentication);
final T result = createInstance(url, authentication, constructor);
LOG.trace("Leaving getConnector(): {}", result);
return result;
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
LOG.warn("Could not instantiate connector", e);
......@@ -247,16 +261,17 @@ public final class ConnectorFactory {
}
}
LOG.debug("Leaving getConnector(): null");
LOG.info("Cannot find connector for (url={}, type={})", url, type);
return null;
}
private static <T extends IComponent> T createInstance(URI url, OAuthCredentials credentials, Constructor<?> constructor) throws InstantiationException, IllegalAccessException, InvocationTargetException {
return (T) (credentials != null ? constructor.newInstance(url,credentials) : constructor.newInstance(url));
private static <T extends IComponent> T createInstance(URI url, Authentication credentials, Constructor<?> constructor)
throws InstantiationException, IllegalAccessException, InvocationTargetException {
return (T)(credentials != null ? constructor.newInstance(url, credentials) : constructor.newInstance(url));
}
private static Constructor<?> getConstructor(Class<?> connector, OAuthCredentials credentials) throws NoSuchMethodException {
return credentials != null ? connector.getConstructor(URI.class, OAuthCredentials.class) : connector.getConstructor(URI.class);
private static Constructor<?> getConstructor(Class<?> connector, Authentication credentials) throws NoSuchMethodException {
return credentials != null ? connector.getConstructor(URI.class, Authentication.class) : connector.getConstructor(URI.class);
}
/**
......@@ -271,8 +286,8 @@ public final class ConnectorFactory {
* @return A connector suitable for the specified protocol, null in case of an
* error
*/
public static IPolicyDecisionPoint getPdp(Component component, final String preferredConnectorType) {
return getConnector(component, ComponentType.PDP, preferredConnectorType);
public static IPolicyDecisionPoint getPdp(Component component, final String preferredConnectorType, Map<String, Authentication> protocolToAuthentication) {
return getConnector(component, ComponentType.PDP, preferredConnectorType, protocolToAuthentication);
}
/**
......@@ -284,7 +299,7 @@ public final class ConnectorFactory {
* error
*/
public static IPolicyDecisionPoint getPdp(URI url) {
return getConnector(url, ComponentType.PDP,null);
return getConnector(url, ComponentType.PDP, null);
}
/**
......@@ -296,8 +311,8 @@ public final class ConnectorFactory {
* @return A connector suitable for the specified protocol, null in case of an
* error
*/
public static IPolicyDecisionPoint getPdp(URI url, OAuthCredentials credentials) {
return getConnector(url, ComponentType.PDP,credentials);
public static IPolicyDecisionPoint getPdp(URI url, Authentication credentials) {
return getConnector(url, ComponentType.PDP, credentials);
}
/**
......@@ -313,7 +328,7 @@ public final class ConnectorFactory {
* error
*/
public static IPolicyEnforcementPoint getPep(PepComponent component, final String preferredConnectorType) {
return getConnector(component, ComponentType.PEP, preferredConnectorType);
return getConnector(component, ComponentType.PEP, preferredConnectorType, null);
}
/**
......@@ -325,7 +340,7 @@ public final class ConnectorFactory {
* error
*/
public static IPolicyEnforcementPoint getPep(URI url) {
return getConnector(url, ComponentType.PEP,null);
return getConnector(url, ComponentType.PEP, null);
}
/**
......@@ -341,7 +356,7 @@ public final class ConnectorFactory {
* error
*/
public static IPolicyInformationPoint getPip(Component component, final String preferredConnectorType) {
return getConnector(component, ComponentType.PIP, preferredConnectorType);
return getConnector(component, ComponentType.PIP, preferredConnectorType, null);
}
/**
......@@ -370,7 +385,7 @@ public final class ConnectorFactory {
* error
*/
public static IPolicyManagementPoint getPmpClient(Component component, final String preferredConnectorType) {
return getConnector(component, ComponentType.PMP, preferredConnectorType);
return getConnector(component, ComponentType.PMP, preferredConnectorType, null);
}
/**
......@@ -387,7 +402,6 @@ public final class ConnectorFactory {
return getConnector(url, ComponentType.PMP, oAuthCredentials);
}
/**
* Tries to establish a connection to a PMP client by using the passed url
* variable.
......@@ -415,7 +429,7 @@ public final class ConnectorFactory {
* error
*/
public static IRootPolicyManagementPoint getPmpServer(Component component, final String preferredConnectorType) {
return getConnector(component, ComponentType.PMP_SERVER, preferredConnectorType);
return getConnector(component, ComponentType.PMP_SERVER, preferredConnectorType, null);
}
/**
......@@ -444,7 +458,7 @@ public final class ConnectorFactory {
* error
*/
public static IPolicyRetrievalPoint getPrp(Component component, final String preferredConnectorType) {
return getConnector(component, ComponentType.PRP, preferredConnectorType);
return getConnector(component, ComponentType.PRP, preferredConnectorType, null);
}
/**
......@@ -472,7 +486,7 @@ public final class ConnectorFactory {
* error
*/
public static IPolicyExecutionPoint getPxp(Component component, final String preferredConnectorType) {
return getConnector(component, ComponentType.PXP, preferredConnectorType);
return getConnector(component, ComponentType.PXP, preferredConnectorType, null);
}
/**
......@@ -488,14 +502,9 @@ public final class ConnectorFactory {
}
protected static void loadClasses() {
LOG.debug("Entering loadClasses()");
if (connectorClasses == null) {
LOG.debug("Loading classes");
final Reflections reflections = new Reflections("de");
connectorClasses = reflections.getTypesAnnotatedWith(Connector.class);
} else {
LOG.debug("Classes already loaded");
}
LOG.debug("Leaving loadClasses()");
}
}
......@@ -17,14 +17,21 @@
* limitations under the License.
* =================================LICENSE_END=================================
*/
package de.fraunhofer.iese.ind2uce.connectors;
import java.io.Serializable;
import java.net.URI;
/**
* DTO to provide the infos to authenticate via OAuth.
*/
public class OAuthCredentials {
public class OAuthCredentials implements Authentication, Serializable {
/**
*
*/
private static final long serialVersionUID = -5742179074145102251L;
private String clientId;
......@@ -41,8 +48,18 @@ public class OAuthCredentials {
this.clientSecret = clientSecret;
}
@Override
public Object getPrincipal() {
return this.getClientId();
}
@Override
public Object getCredentials() {
return this.getClientSecret();
}
public String getClientId() {
return clientId;
return this.clientId;
}
public void setClientId(String clientId) {
......@@ -50,7 +67,7 @@ public class OAuthCredentials {
}
public String getClientSecret() {