Primavera Security 3.0 di Google Apps aperto segno id nell'uso openid4java
-
26-09-2019 - |
Domanda
cerco di accedere utilizzando Google Apps aperte ID con biblioteca openid4java.
scopro servizio dell'utente utilizzando il seguente codice nella classe di consumatori:
try
{
discoveries = consumerManager.discover(identityUrl);
}
catch (DiscoveryException e)
{
throw new OpenIDConsumerException("Error during discovery", e);
}
DiscoveryInformation information = consumerManager.associate(discoveries);
HttpSession session = req.getSession(true);
session.setAttribute(DiscoveryInformation.class.getName(), information);
AuthRequest authReq;
try
{
authReq = consumerManager.authenticate(information, returnToUrl, realm);
// check for OpenID Simple Registration request needed
if (attributesByProvider != null || defaultAttributes != null)
{
//I set the attributes needed for getting the email of the user
}
}
catch (Exception e)
{
throw new OpenIDConsumerException("Error processing ConumerManager authentication", e);
}
return authReq.getDestinationUrl(true);
Poi ho ottenere i parametri dalla richiesta HTTP e nella proprietà openid.claimed_id ricevo " http: // domain.com/openid?id= ...." e se provo a verificare il consumerManager.verify(receivingURL.toString(), openidResp, discovered);
risposta viene generata un'eccezione:. org.openid4java.discovery.yadis.YadisException: 0x706: GET failed on http://domain.com/openid?id=... : 404:Not Found
Per evitare l'eccezione ho cercato di modificare l'elenco dei parametri che cambia il valore " http://domain.com/ ? OpenID id = .... "a" https: / /www.google.com/a/domain.com/openid?id= .... "
// extract the receiving URL from the HTTP request
StringBuffer receivingURL = request.getRequestURL();
String queryString = request.getQueryString();
// extract the parameters from the authentication response
// (which comes in as a HTTP request from the OpenID provider)
ParameterList openidResp = new ParameterList(request.getParameterMap());
Parameter endPoint = openidResp.getParameter("openid.op_endpoint");
if (endPoint != null && endPoint.getValue().startsWith("https://www.google.com/a/"))
{
Parameter parameter = openidResp.getParameter("openid.claimed_id");
if (parameter != null)
{
String value = "https://www.google.com/a/" + parameter.getValue().replaceAll("http://", "");
openidResp.set(new Parameter("openid.claimed_id", value));
queryString = queryString.replaceAll("openid.claimed_id=http%3A%2F%2F", "openid.claimed_id=https%3A%2F%2Fwww.google.com%2Fa%2F");
}
parameter = openidResp.getParameter("openid.identity");
if (parameter != null)
{
String value = "https://www.google.com/a/" + parameter.getValue().replaceAll("http://", "");
openidResp.set(new Parameter("openid.identity", value));
queryString = queryString.replaceAll("openid.claimed_id=http%3A%2F%2F", "openid.claimed_id=https%3A%2F%2Fwww.google.com%2Fa%2F");
}
}
if ((queryString != null) && (queryString.length() > 0))
{
receivingURL.append("?").append(queryString);
}
// retrieve the previously stored discovery information
DiscoveryInformation discovered = (DiscoveryInformation) request.getSession().getAttribute(DiscoveryInformation.class.getName());
// verify the response
VerificationResult verification;
Map userDetails = new HashMap();
try
{
verification = consumerManager.verify(receivingURL.toString(), openidResp, discovered);
// check for OpenID Simple Registration request needed
if (attributesByProvider != null || defaultAttributes != null)
{
//Here I get the value of requested attributes
}
}
catch (Exception e)
{
throw new OpenIDConsumerException("Error verifying openid response", e);
}
// examine the verification result and extract the verified identifier
Identifier verified = null;
if (verification != null)
{
verified = verification.getVerifiedId();
}
OpenIDAuthenticationToken returnToken;
List attributes = null;
if (verified != null)
returnToken = new OpenIDAuthenticationToken(OpenIDAuthenticationStatus.SUCCESS, verified.getIdentifier(), "some message", attributes);
else
{
Identifier id = discovered.getClaimedIdentifier();
return new OpenIDAuthenticationToken(OpenIDAuthenticationStatus.FAILURE, id == null ? "Unknown" : id.getIdentifier(), "Verification status message: [" + verification.getStatusMsg() + "]", attributes);
}
Ora il metodo consumerManager.verify
è non buttare più un'eccezione, ma il suo stato viene modificato in fallito. Nel registro i seguenti errori appaiono
09:46:45,424 ERROR ConsumerManager,http-80-1:1759 - No service element found to match the ClaimedID / OP-endpoint in the assertion.
09:46:45,428 ERROR ConsumerManager,http-80-1:1183 - Discovered information verification failed.
Ho visto su un forum un problema simile, ma la soluzione era quello di cambiare consumerManager.verify
a consumerManager.verifyNonce
. Non sono sicuro se si utilizza questo metodo non creerà un problema di sicurezza. Avete qualche idea di cosa devo cambiare per fare il mio aperte ID consumatore di lavoro con Google Apps OpenID?
Soluzione
Google Apps utilizza un processo di scoperta un po 'diverso da quello che è supportato nella versione base del openid4java. C'è un add-on biblioteca http://code.google.com/p/step2/ che si potrebbe combattere utile (e un involucro di livello più alto a http://code.google.com / p / OpenID-filtro / .)
Io non sono a conoscenza di qualcuno che ha fatto l'integrazione Primavera di sicurezza con le classi Step2 modificate, ma non dovrebbe essere troppo difficile da modificare il codice per impostare in modo appropriato Step2. E 'costruito sul openid4java e il codice per scrivere un utente utilizzatore è in gran parte la stessa.