(Martin Fowler)
mercoledì 16 settembre 2015
POJO
"We wondered why people were so against using regular objects in their
systems and concluded that it was because simple objects lacked a fancy
name. So we gave them one, and it's caught on very nicely."
venerdì 11 settembre 2015
Association - Aggregation - Composition
Association is a relationship where all objects have
their own lifecycle and there is no owner. Let’s take an example of
Teacher and Student. Multiple students can associate with single teacher
and single student can associate with multiple teachers, but there is
no ownership between the objects and both have their own lifecycle. Both
can create and delete independently.
Aggregation is a specialised form of Association where all objects have their own lifecycle, but there is ownership and child objects can not belong to another parent object. Let’s take an example of Department and teacher. A single teacher can not belong to multiple departments, but if we delete the department teacher object will not be destroyed. We can think about it as a “has-a” relationship.
Composition is again specialised form of Aggregation and we can call this as a “death” relationship. It is a strong type of Aggregation. Child object does not have its lifecycle and if parent object is deleted, all child objects will also be deleted. Let’s take again an example of relationship between House and Rooms. House can contain multiple rooms - there is no independent life of room and any room can not belong to two different houses. If we delete the house - room will automatically be deleted. Let’s take another example relationship between Questions and Options. Single questions can have multiple options and option can not belong to multiple questions. If we delete questions options will automatically be deleted.
( magnifica risposta, from stackoverflow)
Aggregation is a specialised form of Association where all objects have their own lifecycle, but there is ownership and child objects can not belong to another parent object. Let’s take an example of Department and teacher. A single teacher can not belong to multiple departments, but if we delete the department teacher object will not be destroyed. We can think about it as a “has-a” relationship.
Composition is again specialised form of Aggregation and we can call this as a “death” relationship. It is a strong type of Aggregation. Child object does not have its lifecycle and if parent object is deleted, all child objects will also be deleted. Let’s take again an example of relationship between House and Rooms. House can contain multiple rooms - there is no independent life of room and any room can not belong to two different houses. If we delete the house - room will automatically be deleted. Let’s take another example relationship between Questions and Options. Single questions can have multiple options and option can not belong to multiple questions. If we delete questions options will automatically be deleted.
( magnifica risposta, from stackoverflow)
mercoledì 2 settembre 2015
venerdì 12 giugno 2015
List All Entries in a LDAP Directory with JSP/JNDI
<%@page import="java.util.*" %>
<%@page import="javax.naming.ldap.*" %>
<%@page import="javax.naming.directory.*"%>
<%@page import="javax.naming.directory.InitialDirContext"%>
<%@page import="javax.naming.directory.DirContext"%>
<%@page import="javax.naming.Context" %>
<%@page import="javax.naming.InitialContext" %>
<%@page import="javax.naming.NamingException" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@page import="java.util.*" %>
<%@page import="javax.naming.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h3>Rubrica:</h3>
<%
//CREATING AN INITIAL CONTEXT for search function:
//context = objects whose state is a set of bindings (=ldap entries), that have distinct atomic names.
//The Hashtable class represents the environments properties parameters
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://localhost:1389/o=Rubrica,dc=example,dc=com");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "cn=Directory Manager");
env.put(Context.SECURITY_CREDENTIALS, "secret");
//create initial context
DirContext ctx = new InitialDirContext(env);
try {
//get listing of context
NamingEnumeration list = ctx.list(""); //class Context.list: contains object name + class name
// NamingEnumeration bindings = ctx.listBindings(""); //class Context.listbindings: contains object name + class name + object
while (list.hasMore()) {
NameClassPair ncPair = (NameClassPair) list.next(); //ClassPair= name + class name
out.print("<b>" + ncPair.getName() + "</b> </br>");
Attributes attrs = ctx.getAttributes(ncPair.getName());
for (NamingEnumeration ae = attrs.getAll(); ae.hasMore();) {
Attribute attr = (Attribute) ae.next();
out.println(attr.getID());
for (NamingEnumeration e = attr.getAll(); e.hasMore();) {
out.println(": " + e.next() + "<br>");
}
}
out.println("------------------------------------------------------<br><br>");
// Binding bd = (Binding)bindings.next();
// out.println(bd.getName() + ":</br></br> " + bd.getObject());
}
ctx.close();
} catch (NamingException e) {
out.println("List failed: " + e);
}
%>
<br><br><br>
</body>
</html>
giovedì 11 giugno 2015
JNDI / JSP Ldap Search, Add, Remove Entry.
<%@page import="javax.naming.NamingEnumeration"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@page import="java.util.*" %>
<%@page import="javax.naming.ldap.*" %>
<%@page import="javax.naming.directory.*"%>
<%@page import="javax.naming.directory.InitialDirContext"%>
<%@page import="javax.naming.directory.DirContext"%>
<%@page import="javax.naming.Context" %>
<%@page import="javax.naming.InitialContext" %>
<%@page import="javax.naming.NamingException" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h3>Rubrica:</h3>
<!-- SEARCH ENTRY -->
<h3>Search Entry:</h3>
<form method="post">
Search Entry: <input type="text" name="search""><br>
<input type="submit" value="search">
</form>
<br><br>
<%
//CREATING AN INITIAL CONTEXT for search function:
//context = objects whose state is a set of bindings (=ldap entries), that have distinct atomic names.
//The Hashtable class represents the environments properties parameters
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://localhost:1389/o=Rubrica,dc=example,dc=com");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL,"cn=Directory Manager");
env.put(Context.SECURITY_CREDENTIALS,"secret");
DirContext ctx = new InitialDirContext(env);
String searchName = (String)request.getParameter("search");
try{
request.getParameter("search");
Attributes attrs = ctx.getAttributes("cn = " + searchName);
out.println(attrs.get("cn").get());
out.println(" telephone number: "+attrs.get("telephonenumber").get());
}
catch (Exception e){
out.println("An exception occurred: " + e.getMessage());
}
%>
<br>------------------------------------</br>
<!-- ADD ENTRY -->
<h3>Add Entry:</h3>
<form method="post">
Add Entry:<br><br>
Full Name: <input type="text" name="addcn"><br>
Surname: <input type="text" name="surname"><br>
PhoneNumber: <input type="text" name="pn"><br>
<input type="submit" value="addEntry">
</form><br><br>
<%
String addcn = (String)request.getParameter("addcn");
String surname = (String)request.getParameter("surname");
String pn = (String)request.getParameter("pn");
try{
//Create new set of attributes
BasicAttributes attrs1 = new BasicAttributes();
//(The item is a person)
Attribute classes = new BasicAttribute("objectClass");
// classes.add("top");
classes.add("person");
// classes.add("organizationalPerson");
// Add the objectClass attribute to the attribute set
attrs1.put(classes);
// Store the other attributes in the attribute set
attrs1.put("sn", surname);
attrs1.put("telephonenumber", pn);
// Add the new entry to the directory server
ctx.createSubcontext("ldap://localhost:1389/cn="+addcn+",o=Rubrica,dc=example,dc=com", attrs1);
}
catch (Exception e){
out.println("An exception occurred: " + e.getMessage());
}
%>
<br>------------------------------------</br>
<!-- REMOVE ENTRY -->
<h3>Remove Entry:</h3>
<form method="post">
Insert Entry To Remove: <input type="text" name="delUser""><br>
<input type="submit" value="Remove">
</form><br><br>
<%
String delUser = (String)request.getParameter("delUser");
try
{
ctx.destroySubcontext("cn="+delUser);
}
catch (Exception e){
out.println("An exception occurred: " + e.getMessage());
}
%>
<br><br><br>
</body>
</html>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@page import="java.util.*" %>
<%@page import="javax.naming.ldap.*" %>
<%@page import="javax.naming.directory.*"%>
<%@page import="javax.naming.directory.InitialDirContext"%>
<%@page import="javax.naming.directory.DirContext"%>
<%@page import="javax.naming.Context" %>
<%@page import="javax.naming.InitialContext" %>
<%@page import="javax.naming.NamingException" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h3>Rubrica:</h3>
<!-- SEARCH ENTRY -->
<h3>Search Entry:</h3>
<form method="post">
Search Entry: <input type="text" name="search""><br>
<input type="submit" value="search">
</form>
<br><br>
<%
//CREATING AN INITIAL CONTEXT for search function:
//context = objects whose state is a set of bindings (=ldap entries), that have distinct atomic names.
//The Hashtable class represents the environments properties parameters
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://localhost:1389/o=Rubrica,dc=example,dc=com");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL,"cn=Directory Manager");
env.put(Context.SECURITY_CREDENTIALS,"secret");
DirContext ctx = new InitialDirContext(env);
String searchName = (String)request.getParameter("search");
try{
request.getParameter("search");
Attributes attrs = ctx.getAttributes("cn = " + searchName);
out.println(attrs.get("cn").get());
out.println(" telephone number: "+attrs.get("telephonenumber").get());
}
catch (Exception e){
out.println("An exception occurred: " + e.getMessage());
}
%>
<br>------------------------------------</br>
<!-- ADD ENTRY -->
<h3>Add Entry:</h3>
<form method="post">
Add Entry:<br><br>
Full Name: <input type="text" name="addcn"><br>
Surname: <input type="text" name="surname"><br>
PhoneNumber: <input type="text" name="pn"><br>
<input type="submit" value="addEntry">
</form><br><br>
<%
String addcn = (String)request.getParameter("addcn");
String surname = (String)request.getParameter("surname");
String pn = (String)request.getParameter("pn");
try{
//Create new set of attributes
BasicAttributes attrs1 = new BasicAttributes();
//(The item is a person)
Attribute classes = new BasicAttribute("objectClass");
// classes.add("top");
classes.add("person");
// classes.add("organizationalPerson");
// Add the objectClass attribute to the attribute set
attrs1.put(classes);
// Store the other attributes in the attribute set
attrs1.put("sn", surname);
attrs1.put("telephonenumber", pn);
// Add the new entry to the directory server
ctx.createSubcontext("ldap://localhost:1389/cn="+addcn+",o=Rubrica,dc=example,dc=com", attrs1);
}
catch (Exception e){
out.println("An exception occurred: " + e.getMessage());
}
%>
<br>------------------------------------</br>
<!-- REMOVE ENTRY -->
<h3>Remove Entry:</h3>
<form method="post">
Insert Entry To Remove: <input type="text" name="delUser""><br>
<input type="submit" value="Remove">
</form><br><br>
<%
String delUser = (String)request.getParameter("delUser");
try
{
ctx.destroySubcontext("cn="+delUser);
}
catch (Exception e){
out.println("An exception occurred: " + e.getMessage());
}
%>
<br><br><br>
</body>
</html>
mercoledì 3 giugno 2015
OpenDJ Multi-Master Replication
dpkg -i opendj....
./setup
1- Enable:
./bin/dsreplication enable --host1 Host1 --port1 4444 --bindDN1 "cn=Directory Manager" --bindPassword1 pass --replicationPort1 8989 --host2 Host2 --port2 4444 --bindDN2 "cn=Directory Manager" --bindPassword2 pass --replicationPort2 8989 --adminUID admin --adminPassword pass --baseDN "dc=example,dc=com"
oppure: ./bin/dsreplication -> enable
2- Initialize:
./bin/dsreplication initialize --baseDN "dc=example,dc=com" --adminUID admin --adminPassword pass --hostSource Host1 --portSource 4444 --hostDestination Host2 --portDestination 4444 -X -n
oppure: ./bin/dsreplication-> initialize all
-----
..if everything's fine:
create new entry "o=Rubrica Telefonica",
create MichaelMyers.ldif:
dn: cn=Mychael Myers, o=Rubrica Telefonica, dc=example, dc=com
cn: Mychael Myers
sn: Myers
ObjectClass: person
and add the second one:
ldapadd -h workstation -p 1389 -D "cn=Directory Manager" -w secret -f MichaelMyers.ldif
And search for it.
ldapsearch -p 1389 -h workstation -b "dc=example,dc=com" -w secret -D "cn=Directory Manager" -LLL "(sn=Myers)"
./setup
1- Enable:
./bin/dsreplication enable --host1 Host1 --port1 4444 --bindDN1 "cn=Directory Manager" --bindPassword1 pass --replicationPort1 8989 --host2 Host2 --port2 4444 --bindDN2 "cn=Directory Manager" --bindPassword2 pass --replicationPort2 8989 --adminUID admin --adminPassword pass --baseDN "dc=example,dc=com"
oppure: ./bin/dsreplication -> enable
2- Initialize:
./bin/dsreplication initialize --baseDN "dc=example,dc=com" --adminUID admin --adminPassword pass --hostSource Host1 --portSource 4444 --hostDestination Host2 --portDestination 4444 -X -n
oppure: ./bin/dsreplication-> initialize all
-----
..if everything's fine:
create new entry "o=Rubrica Telefonica",
create MichaelMyers.ldif:
dn: cn=Mychael Myers, o=Rubrica Telefonica, dc=example, dc=com
cn: Mychael Myers
sn: Myers
ObjectClass: person
and add the second one:
ldapadd -h workstation -p 1389 -D "cn=Directory Manager" -w secret -f MichaelMyers.ldif
And search for it.
ldapsearch -p 1389 -h workstation -b "dc=example,dc=com" -w secret -D "cn=Directory Manager" -LLL "(sn=Myers)"
lunedì 25 maggio 2015
Configuring Tomcat - SSL
#genera il certificato CA
openssl genrsa -out server_t.key 1024
openssl req -new -key server_t.key -out server_t.csr
openssl x509 -req -days 365 -in server_t.csr -signkey server_t.key -out server_t.crt
#genera il keystore e cert. server (tomcat.crt, CN=hostname.domainname)
keytool -genkey -alias tomcat -keyalg RSA -keystore tomcat.ks
keytool -keystore tomcat.ks -alias tomcat -certreq -file tomcat.csr
echo 02 > serial.txt
#sign cert. server
openssl x509 -CA server_t.crt -CAkey server_t.key -CAserial serial.txt -req -in tomcat.csr -out tomcat.crt -days 365
#importa il certificato server nel keystore
keytool -import -alias serverCA -file server_t.crt -keystore tomcat.ks
keytool -import -alias tomcat -file tomcat.crt -keystore tomcat.ks
keytool -list -v -keystore tomcat.ks
openssl genrsa -out server_t.key 1024
openssl req -new -key server_t.key -out server_t.csr
openssl x509 -req -days 365 -in server_t.csr -signkey server_t.key -out server_t.crt
#genera il keystore e cert. server (tomcat.crt, CN=hostname.domainname)
keytool -genkey -alias tomcat -keyalg RSA -keystore tomcat.ks
keytool -keystore tomcat.ks -alias tomcat -certreq -file tomcat.csr
echo 02 > serial.txt
#sign cert. server
openssl x509 -CA server_t.crt -CAkey server_t.key -CAserial serial.txt -req -in tomcat.csr -out tomcat.crt -days 365
#importa il certificato server nel keystore
keytool -import -alias serverCA -file server_t.crt -keystore tomcat.ks
keytool -import -alias tomcat -file tomcat.crt -keystore tomcat.ks
keytool -list -v -keystore tomcat.ks
giovedì 21 maggio 2015
Disinstallare manualmente un pacchetto gravemente inconsistente - Debian
Nonostante ultimamente la situazione dei pacchetti nel mio sistema sia incasinatissima, prima di una necessaria pulizia mi sono imbattuto nel problema di dover rimuovere un pacchetto definito inconsistente e che non mi permetteva di installarne altri. Se ricordo bene l'errore è:
Il pacchetto "brokenpackage" deve essere reinstallato, ma non è possibile trovarne un archivio.
la soluzione che ho trovato e mi ha salvato la giornata è:
mv /var/lib/dpkg/info/brokenpackage.* /tmp/
dpkg --remove --force-remove-reinstreq brokenpackage
Il pacchetto "brokenpackage" deve essere reinstallato, ma non è possibile trovarne un archivio.
la soluzione che ho trovato e mi ha salvato la giornata è:
mv /var/lib/dpkg/info/brokenpackage.* /tmp/
dpkg --remove --force-remove-reinstreq brokenpackage
Iscriviti a:
Post (Atom)
How to deploy Podman images to OpenShift Container Platform (CRC on localhost)
I have a microservice on localhost and I want to deploy its Podman image on OCP, which I am running using CRC on localhost. 1. Get the...
-
Precondizione: La precondizione di un metodo e' una condizione che deve essere verificata prima che quel metodo sia invocato. Le preco...
-
My intent is to configure SSO on Keycloak and Liferay. I have createad a docker-compose environment with Keycloak: #####################...