Hey guys,
I am using AEM 6.5 and I've deployed a custom OSGI service config. I was expecting to find the config under http://localhost:4502/system/console/configMgr
Here is my Service.
MyService.java
public interface MyService {
/**
* This method returns the entered password into a hash equivalent with some
* properties passed by the user
*
* @Param type
* @Return {@link String}
*/
String getPassword(String type);
}
MyServiceImpl.java
@Component(service = MyService.class,
property = {
"label=My Service Implementation"
}
)
@Designate(ocd = MyConfiguration.class)
public class MyServiceImpl implements MyService {
private final Logger log = LoggerFactory.getLogger(this.getClass());
// Two properties to be read
private String propertyOne;
private String propertyTwo;
@Activate
protected void activate(MyConfiguration config) {
// Reading properties from the configuration
propertyOne = config.getPropertyOne();
propertyTwo = config.getPropertyTwo();
}
@Override
public String getPassword(String type) {
// MD5 equivalent of password string
String passwordHash = null;
try {
type = type + propertyOne + propertyTwo;
log.info("Resulant password: " + type);
// Convert string to bytes - this is for the sample implementation (for show casing)
byte[] passwordByte = type.getBytes("UTF-8");
// Getting instance of MessageDigest
MessageDigest md = MessageDigest.getInstance("MD5");
// Convert bytes array to hash using MD5 algorithm
byte[] digest = md.digest(passwordByte);
passwordHash = new String(digest);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return passwordHash;
}
}
MyConfiguration.java
import org.osgi.service.metatype.annotations.AttributeDefinition;
import org.osgi.service.metatype.annotations.AttributeType;
import org.osgi.service.metatype.annotations.ObjectClassDefinition;
@ObjectClassDefinition(name = "My Configuration",
description = "This configuration will be used to read the value of properties.")
public @interface MyConfiguration {
@AttributeDefinition(name = "Property One", description = "Read property one", type = AttributeType.STRING)
public String getPropertyOne() default "Property One";
@AttributeDefinition(name = "Property Two", description = "Read property two", type = AttributeType.STRING)
public String getPropertyTwo() default "Property Two";
}