forked from seam/security
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
partial refactor of authentication api for openid
- Loading branch information
Showing
17 changed files
with
411 additions
and
80 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
api/src/main/java/org/jboss/seam/security/AuthenticationException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.jboss.seam.security; | ||
|
||
/** | ||
* Thrown if there is an error during the authentication process | ||
* | ||
* @author Shane Bryzak | ||
* | ||
*/ | ||
public class AuthenticationException extends SecurityException | ||
{ | ||
private static final long serialVersionUID = -7486433031372506270L; | ||
|
||
public AuthenticationException(String message) | ||
{ | ||
super(message); | ||
} | ||
|
||
public AuthenticationException(String message, Throwable cause) | ||
{ | ||
super(message, cause); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
external/src/main/java/org/jboss/seam/security/external/openid/OpenIdAuthenticator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package org.jboss.seam.security.external.openid; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
import javax.enterprise.inject.Model; | ||
import javax.faces.context.FacesContext; | ||
import javax.inject.Inject; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import org.jboss.seam.security.Authenticator; | ||
import org.jboss.seam.security.external.openid.api.OpenIdRelyingPartyApi; | ||
import org.jboss.seam.security.external.openid.api.OpenIdRequestedAttribute; | ||
import org.jboss.seam.security.external.openid.providers.OpenIdProvider; | ||
|
||
/** | ||
* | ||
* @author Shane Bryzak | ||
* | ||
*/ | ||
public @Model class OpenIdAuthenticator implements Authenticator | ||
{ | ||
private String openIdProviderUrl; | ||
|
||
//private OpenIdProvider provider; | ||
|
||
@Inject private OpenIdRelyingPartyApi openIdApi; | ||
|
||
@Inject List<OpenIdProvider> providers; | ||
|
||
private String providerCode; | ||
|
||
public String getProviderCode() | ||
{ | ||
return providerCode; | ||
} | ||
|
||
public void setProviderCode(String providerCode) | ||
{ | ||
this.providerCode = providerCode; | ||
} | ||
|
||
public String getOpenIdProviderUrl() | ||
{ | ||
return openIdProviderUrl; | ||
} | ||
|
||
public void setOpenIdProviderUrl(String openIdProviderUrl) | ||
{ | ||
this.openIdProviderUrl = openIdProviderUrl; | ||
} | ||
|
||
protected OpenIdProvider getSelectedProvider() | ||
{ | ||
if (providerCode != null) | ||
{ | ||
for (OpenIdProvider provider : providers) | ||
{ | ||
if (providerCode.equals(provider.getCode())) return provider; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public AuthStatus authenticate() | ||
{ | ||
List<OpenIdRequestedAttribute> attributes = new LinkedList<OpenIdRequestedAttribute>(); | ||
attributes.add(openIdApi.createOpenIdRequestedAttribute("email", "http://schema.openid.net/contact/email", false, null)); | ||
|
||
OpenIdProvider selectedProvider = getSelectedProvider(); | ||
|
||
openIdApi.login(selectedProvider != null ? selectedProvider.getUrl() : getOpenIdProviderUrl(), | ||
attributes, (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse()); | ||
|
||
return AuthStatus.DEFERRED; | ||
} | ||
|
||
public List<OpenIdProvider> getProviders() | ||
{ | ||
return providers; | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
...src/main/java/org/jboss/seam/security/external/openid/providers/GoogleOpenIdProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.jboss.seam.security.external.openid.providers; | ||
|
||
/** | ||
* Open ID provider for Google accounts | ||
* | ||
* @author Shane Bryzak | ||
* | ||
*/ | ||
public class GoogleOpenIdProvider implements OpenIdProvider | ||
{ | ||
public static final String CODE = "google"; | ||
|
||
public String getCode() | ||
{ | ||
return CODE; | ||
} | ||
|
||
public String getName() | ||
{ | ||
return "Google"; | ||
} | ||
|
||
public String getUrl() | ||
{ | ||
return "https://www.google.com/accounts/o8/id"; | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
...nal/src/main/java/org/jboss/seam/security/external/openid/providers/MyOpenIdProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.jboss.seam.security.external.openid.providers; | ||
|
||
/** | ||
* Open ID provider for myopenid.com | ||
* | ||
* @author Shane Bryzak | ||
* | ||
*/ | ||
public class MyOpenIdProvider implements OpenIdProvider | ||
{ | ||
public static final String CODE = "myopenid"; | ||
|
||
public String getCode() | ||
{ | ||
return CODE; | ||
} | ||
|
||
public String getName() | ||
{ | ||
return "MyOpenID"; | ||
} | ||
|
||
public String getUrl() | ||
{ | ||
return "https://myopenid.com"; | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
external/src/main/java/org/jboss/seam/security/external/openid/providers/OpenIdProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.jboss.seam.security.external.openid.providers; | ||
|
||
/** | ||
* Base interface for defining a set of built in Open ID providers | ||
* | ||
* @author Shane Bryzak | ||
* | ||
*/ | ||
public interface OpenIdProvider | ||
{ | ||
String getCode(); | ||
String getName(); | ||
String getUrl(); | ||
} |
39 changes: 39 additions & 0 deletions
39
...in/java/org/jboss/seam/security/external/openid/providers/OpenIdProviderListProducer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.jboss.seam.security.external.openid.providers; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.inject.Instance; | ||
import javax.enterprise.inject.Produces; | ||
import javax.inject.Inject; | ||
import javax.inject.Named; | ||
|
||
/** | ||
* A producer that returns a list of open id providers, useful for building | ||
* web interfaces | ||
* | ||
* @author Shane Bryzak | ||
* | ||
*/ | ||
public @ApplicationScoped class OpenIdProviderListProducer | ||
{ | ||
@Inject Instance<OpenIdProvider> providerInstances; | ||
|
||
private List<OpenIdProvider> providers; | ||
|
||
@Inject public void init() | ||
{ | ||
providers = new ArrayList<OpenIdProvider>(); | ||
|
||
for (OpenIdProvider provider : providerInstances) | ||
{ | ||
providers.add(provider); | ||
} | ||
} | ||
|
||
@Produces public List<OpenIdProvider> listProviders() | ||
{ | ||
return providers; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
.../src/main/java/org/jboss/seam/security/external/openid/providers/YahooOpenIdProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.jboss.seam.security.external.openid.providers; | ||
|
||
/** | ||
* Open ID provider for Yahoo accounts | ||
* | ||
* @author Shane Bryzak | ||
* | ||
*/ | ||
public class YahooOpenIdProvider implements OpenIdProvider | ||
{ | ||
public static final String CODE = "yahoo"; | ||
|
||
public String getCode() | ||
{ | ||
return CODE; | ||
} | ||
|
||
public String getName() | ||
{ | ||
return "Yahoo"; | ||
} | ||
|
||
public String getUrl() | ||
{ | ||
return "https://me.yahoo.com"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.