-
Notifications
You must be signed in to change notification settings - Fork 2
Open Infinity Core Documentation V1.3.X.RELEASE
Open Infinity Core framework is a solution accelerator providing best practices patterns and tactics to overcome cross-cutting concerns like audit trail, logging, standardized and localized exception hierarchy, validation, security and quality.
Package | Explanation |
---|---|
org.openinfinity.core.annotation | Package includes platform specific annotations. Annotations are used as an metadata for aspects. |
org.openinfinity.core.aspect | Package includes platform specific aspects removing boilerplate code and providing better quality through reusability. |
org.openinfinity.core.exception | Package includes platform specific exception mechanism. Exceptions have three layerd mechanism to provide information about the application state. Exception level has also been defined. |
org.openinfinity.core.util | Package includes platform specific utilities and helper classes. |
org.openinfinity.core.validation | Package includes platform specific security validation modules. |
org.openinfinity.core.spring | Package includes Spring framework specific helper classes. |
The package includes the following functionality.
This annotation represents the metadata added to the runtime method. The metadata executes the org.openinfinity.core.aspect.AuditTrailAspect -aspect when defined. Annotation can be defined in the method level.
@AudiTrail
public SomeObject someMethod(AnotherObject anotherObject() {...}
@AuditTrail(
isUsernameEnabled=true,
isRolesEnabled=false,
isTimeStampEnabled=true,
value={"auto/tire/screw","personId"},
argumentStrategy=CUSTOM
)
public SomeObject someMethod(AnotherObject anotherObject() {...}
This annotation represents the metadata added to the runtime method. The metadata executes the org.openinfinity.core.aspect.CryptoAspect -aspect when defined. Annotation can be defined in the method level. Annotation can be utilized to encrypt data graphs attributes.
@Encrypt
public SomeObject someMethod(AnotherObject anotherObject() {...}
@Encrypt(
value={"auto/tire/screw","personId"},
argumentStrategy=CUSTOM
)
public SomeObject someMethod(AnotherObject anotherObject() {...}
This annotation represents the metadata added to the runtime method. The metadata executes the org.openinfinity.core.aspect.CryptoAspect -aspect when defined. Annotation can be defined in the method level. Annotation can be utilized to decrypt data graphs attributes.
@Decrypt
public SomeObject someMethod(AnotherObject anotherObject() {...}
@Decrypt(
value={"auto/tire/screw","personId"},
argumentStrategy=CUSTOM
)
public SomeObject someMethod(AnotherObject anotherObject() {...}
This annotation represents the metadata added to the runtime method. The metadata executes the org.openinfinity.core.aspect.LogAspect-aspect when defined. Annotation can be defined in the method level.
@Log
public SomeObject someMethod(AnotherObject anotherObject() {...}
@Log(level=LogLevel.INFO)
public SomeObject someMethod(AnotherObject anotherObject() {...}
@Log(
value={"auto/tire/screw","personId"},
argumentStrategy=CUSTOM
level=LogLevel.INFO
)
public SomeObject someMethod(AnotherObject anotherObject() {...}
Field validator for validating XSS attacks.
@NotScript
private String someField;
@NotScript(allowedInputPattern=Person.SSN_XSS)
private String someField;
The package includes the following functionality.
Class is responsible for creating audit trail information. Audit trail storage system can be defined through Log4j property files (JDBCAppender, FileAppender, JMSAppender etc).
<context:component-scan base-package=“org.openinfinity.core">
<aop:aspectj-autoproxy>
<aop:include name="auditTrailAspect“ />
</aop:aspectj-autoproxy>
<bean
id="auditTrailAspect"
class=“org.openinfinity.core.aspect.AuditTrailAspect" />
Aspect for handling controller and service level exception translation. Service level exceptions should always be instance of org.openinfinity.core.exception.ApplicationException,org.openinfinity.core.exception.SystemException or org.openinfinity.core.exception.BusinessViolationException. Unknown exceptions will be translated to org.openinfinity.core.exception.SystemException.
<context:component-scan base-package=“org.openinfinity.core">
<aop:aspectj-autoproxy>
<aop:include name=“exceptionTranslatorAspect"/>
</aop:aspectj-autoproxy>
<bean
id="exceptionTranslatorAspect"
class="org.openinfinity.core.aspect.ExceptionTranslatorAspect” />
This class is responsible of the encrypting and decrypting data entity's fields. All the incoming parameters will be encrypted or decrypted based on the defined annotation (@Encrypt or @Decrypt).
<context:component-scan base-package=“org.openinfinity.core">
<aop:aspectj-autoproxy>
<aop:include name=“cryptoAspect"/>
</aop:aspectj-autoproxy>
<bean id="cryptoAspect" class="org.openinfinity.core.aspect.CryptoAspect">
<property name="cryptoSupport" ref="cryptoSupport" />
<property name="encoding" value="${crypto.character.encoding}"/>
</bean>
<bean id ="cryptoSupport" class="org.openinfinity.core.crypto.CryptoSupport">
<constructor-arg name="asymmetricPublicKeyPath" value="${asymmetric.public.key.path}"/>
<constructor-arg name="asymmetricPrivateKeyPath" value="${asymmetric.private.key.path}"/>
</bean>
This class is responsible of the logging. All the incoming parameters will be logged (based on toString() method). Logging storage system can be defined through Log4j property files (JDBCAppender, FileAppender, JMSAppender etc).
<context:component-scan base-package=“org.openinfinity.core">
<aop:aspectj-autoproxy>
<aop:include name=“logAspect"/>
</aop:aspectj-autoproxy>
<bean
id="logAspect"
class="org.openinfinity.core.aspect.LogAspect" />
The package includes the following functionality.
This object supports encryption and decryption of the entity fields. It handles the base 64 encoding and decoding of java.util.String fields.
CryptoSupport example usage for encryption:
@Autowired
CryptoSupport cryptoSupport;
public SomeObject someMethod(Object plainArgument) {
byte[] plainBytes = IOUtil.getBytes(plainArgument);
byte[] encryptedBytes = cryptoSupport.encrypt(plainBytes);
}
public SomeObject someMethod(Object argument) {
byte[] plainBytes = IOUtil.getBytes(field.get(object));
String encryptedBase64Presentation = cryptoSupport.encryptAndReturnBase64Presentation(plainBytes, "ISO-8859-1");
}
CryptoSupport example usage for decryption:
@Autowired
CryptoSupport cryptoSupport;
public SomeObject someMethod(Object encryptedArgument) {
byte[] plainBytes = IOUtil.getBytes(argument);
byte[] encryptedBytes = cryptoSupport.encrypt(plainBytes);
}
public SomeObject someMethod(Object encryptedArgument) {
byte[] encryptedBytes = IOUtil.getBytes(field.get(encryptedArgument));
String decryptedBase64Presentation = cryptoSupport.decryptAndReturnBase64Presentation(encryptedBytes, "ISO-8859-1");
}
Context configuration:
<context:component-scan base-package=“org.openinfinity.core">
# Asymmetric algorithm configuration
<bean id ="cryptoSupport" class="org.openinfinity.core.crypto.CryptoSupport">
<constructor-arg name="asymmetricPublicKeyPath" value="${asymmetric.public.key.path}"/>
<constructor-arg name="asymmetricPrivateKeyPath" value="${asymmetric.private.key.path}"/>
</bean>
# Symmetric algorithm configuration
<bean id ="cryptoSupport" class="org.openinfinity.core.crypto.CryptoSupport">
<constructor-arg name="symmetricKeyPath" value="${symmetric.key.path}"/>
</bean>
The package includes the following functionality.
Business violation exception is thrown when business rule fails. This kind of behaviour has a fatal impact for the business. Exception is derived from org.openinfinity.core.exception.AbstractCoreException.
Service interface mapped to error properties:
private static final UNIQUE_EXCEPTION = ”bve.exception.not.found”;
Service implementation using localized properties:
if (product.isNotFound()) {
BusinessViolationException bve = new BusinessViolationException
(
”Product not found”,
ExceptionLevel.ERROR,
UNIQUE_EXCEPTION
);
throw bve;
}
or simply using core utilities:
if (product.isNotFound()) {
ExceptionUtil.throwBusinessViolationException(
”Product not found”,
ExceptionLevel.ERROR,
UNIQUE_EXCEPTION);
}
This class holds information about the system errors.This exception will be thrown when system level exception occurs (connection failure etc). Exception is derived from org.openinfinity.core.exception.AbstractCoreException.
private static final UNIQUE_EXCEPTION = ”se.exception.cf”;
if (connection.isInFailureState()) {
SystemException se = new SystemException
(
”Connection failure occurred”,
ExceptionLevel.WARNING,
UNIQUE_EXCEPTION
);
throw se;
}
or:
if (product.isNotFound()) {
ExceptionUtil.throwSystemException
(
”Connection failure occurred”,
ExceptionLevel.WARNING,
UNIQUE_EXCEPTION
);
}
This class holds information about application error. This exception should be thrown when application (use cases) specific problems occurs. Exception is derived from org.openinfinity.core.exception.AbstractCoreException.
if (product.ifContainsIllegalInformation()) {
ExceptionUtil.throwApplicationException
(
”Product contains illegal information”,
ExceptionLevel.INFORMATIVE,
UNIQUE_EXCEPTION
);
}
The package includes the following functionality.
Utility for handling aspect specific features.
Log logAnnotation = AspectUtil.getAnnotation(joinPoint, Log.class);
CollectionUtil enables element callbacks on java.util.Collection and java.util.Map interfaces unifying their API usage.
Collection<String> expected = new ArrayList<String>();
expected.add("foo");
expected.add("bar");
CollectionElementUtil.iterate(expected, new CollectionElementCallback<String>() {
public void callback(String callbackObject) {
System.out.println(callbackObject);
}
});
Map<String, String> expected = new HashMap<String, String>();
expected.put("foo","me1");
expected.put("bar", "me2");
CollectionElementUtil.iterate(expected, new MapElementCallback<String, String>() {
public void callback(String key, String value) {
System.out.println(key + ":" + value);
}
});
Exception utility class which offers basic methods for exception throwing and stack trace resolving.
String stackTrace = ExceptionUtil.getStackTraceString(throwable);
or:
ExceptionUtil.throwBusinessViolationException(cause);
Utility for handling stream, reader and writer objects.
IOUtil.copyStream(inputStream, outputStream);
IOUtil.getBytes(object);
IOUtil.closeReader(reader);
IOUtil.closeWriter(writer);
IOUtil.closeStream(stream);
Helper class for handling Strings.
@Override
Public String toString() {
StringUtil.toString(this);
}
Utility for key-value properties from JDBC datasource.
<import resource=“classpath:datasource-definitions.xml"/>
<bean class=” org.openinfinity.core.aspect.JdbcPropertyPlaceholderConfigurer">
<constructor-arg ref=”dataSource” />
<property name="locations">
<list>
<value>
classpath:/META-INF/properties/logging.properties
</value>
</list>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true" />
</bean>