Skip to content
Permalink
Browse files
[FIXED JENKINS-9163] fixed a bug in persistence
  • Loading branch information
kohsuke committed Mar 27, 2011
1 parent 4f65777 commit ef86e32420b5cbd866a96d5b00adc1f659aa53d0
Showing with 16 additions and 5 deletions.
  1. +16 −5 src/main/java/hudson/plugins/openid/OpenIdSsoSecurityRealm.java
@@ -42,6 +42,7 @@
import org.kohsuke.stapler.HttpResponse;
import org.kohsuke.stapler.StaplerRequest;
import org.openid4java.OpenIDException;
import org.openid4java.consumer.ConsumerException;
import org.openid4java.consumer.ConsumerManager;
import org.openid4java.consumer.InMemoryConsumerAssociationStore;
import org.openid4java.consumer.InMemoryNonceVerifier;
@@ -58,7 +59,7 @@
* @author Kohsuke Kawaguchi
*/
public class OpenIdSsoSecurityRealm extends SecurityRealm {
private final ConsumerManager manager;
private /*almost final*/ transient volatile ConsumerManager manager;
// private final DiscoveryInformation endpoint;

// for example, https://login.launchpad.net/+openid
@@ -69,13 +70,23 @@ public class OpenIdSsoSecurityRealm extends SecurityRealm {

@DataBoundConstructor
public OpenIdSsoSecurityRealm(String endpoint) throws IOException, OpenIDException {
manager = new ConsumerManager();
manager.setAssociations(new InMemoryConsumerAssociationStore());
manager.setNonceVerifier(new InMemoryNonceVerifier(5000));
this.endpoint = endpoint;
getDiscoveredEndpoint();
}

private ConsumerManager getManager() throws ConsumerException {
if (manager!=null) return manager;

synchronized (this) {
if (manager==null) {
manager = new ConsumerManager();
manager.setAssociations(new InMemoryConsumerAssociationStore());
manager.setNonceVerifier(new InMemoryNonceVerifier(5000));
}
}
return manager;
}

private DiscoveryInformation getDiscoveredEndpoint() throws IOException, OpenIDException {
if (discoveredEndpoint==null) {
// pretend that the endpoint URL is by itself an OpenID and find out an endpoint
@@ -123,7 +134,7 @@ public Authentication authenticate(Authentication authentication) throws Authent
* The login process starts from here.
*/
public HttpResponse doCommenceLogin(@Header("Referer") final String referer) throws IOException, OpenIDException {
return new OpenIdSession(manager,endpoint,"securityRealm/finishLogin") {
return new OpenIdSession(getManager(),endpoint,"securityRealm/finishLogin") {
@Override
protected HttpResponse onSuccess(Identity id) throws IOException {
// logs this user in.

0 comments on commit ef86e32

Please sign in to comment.