Skip to content

Commit 0115522

Browse files
committed
improve OpenID integration with security API
1 parent d232b2d commit 0115522

File tree

11 files changed

+77
-34
lines changed

11 files changed

+77
-34
lines changed

api/src/main/java/org/jboss/seam/security/Identity.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
package org.jboss.seam.security;
22

3-
import java.security.Principal;
43
import java.util.Collection;
54
import java.util.Set;
65

7-
import javax.security.auth.Subject;
8-
96
import org.picketlink.idm.api.Group;
107
import org.picketlink.idm.api.Role;
118
import org.picketlink.idm.api.User;

examples/openid-rp/pom.xml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,62 @@
2929
<artifactId>validation-api</artifactId>
3030
<groupId>javax.validation</groupId>
3131
</exclusion>
32+
<exclusion>
33+
<groupId>org.jboss.seam.solder</groupId>
34+
<artifactId>seam-solder-api</artifactId>
35+
</exclusion>
36+
<exclusion>
37+
<groupId>org.jboss.seam.solder</groupId>
38+
<artifactId>seam-solder-impl</artifactId>
39+
</exclusion>
40+
<exclusion>
41+
<groupId>org.jboss.logging</groupId>
42+
<artifactId>jboss-logging</artifactId>
43+
</exclusion>
3244
</exclusions>
3345
</dependency>
3446

3547
<dependency>
3648
<groupId>org.jboss.seam.security</groupId>
3749
<artifactId>seam-security-impl</artifactId>
3850
<version>${project.version}</version>
51+
<exclusions>
52+
<exclusion>
53+
<groupId>org.jboss.seam.solder</groupId>
54+
<artifactId>seam-solder-api</artifactId>
55+
</exclusion>
56+
<exclusion>
57+
<groupId>org.jboss.seam.solder</groupId>
58+
<artifactId>seam-solder-impl</artifactId>
59+
</exclusion>
60+
<exclusion>
61+
<groupId>org.jboss.logging</groupId>
62+
<artifactId>jboss-logging</artifactId>
63+
</exclusion>
64+
</exclusions>
3965
</dependency>
4066

4167
<dependency>
4268
<groupId>org.jboss.seam.servlet</groupId>
4369
<artifactId>seam-servlet</artifactId>
4470
</dependency>
4571

72+
<dependency>
73+
<groupId>org.jboss.seam.config</groupId>
74+
<artifactId>seam-config-xml</artifactId>
75+
<version>3.0.0.Beta2</version>
76+
<exclusions>
77+
<exclusion>
78+
<groupId>org.jboss.seam.solder</groupId>
79+
<artifactId>seam-solder-api</artifactId>
80+
</exclusion>
81+
<exclusion>
82+
<groupId>org.jboss.seam.solder</groupId>
83+
<artifactId>seam-solder-impl</artifactId>
84+
</exclusion>
85+
</exclusions>
86+
</dependency>
87+
4688
<dependency>
4789
<groupId>javax.enterprise</groupId>
4890
<artifactId>cdi-api</artifactId>

examples/openid-rp/src/main/resources/META-INF/seam-beans.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
xsi:schemaLocation="
77
http://java.sun.com/xml/ns/javaee http://jboss.org/schema/cdi/beans_1_0.xsd">
88

9-
<security:Identity>
10-
<s:replaces/>
9+
<security:IdentityImpl>
10+
<s:modifies/>
1111
<security:authenticatorName>openIdAuthenticator</security:authenticatorName>
12-
</security>
12+
</security:IdentityImpl>
1313

1414
</beans>

external/src/main/java/org/jboss/seam/security/external/openid/OpenIdAuthenticator.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
import java.util.LinkedList;
44
import java.util.List;
55

6-
import javax.enterprise.inject.Model;
6+
import javax.enterprise.context.RequestScoped;
77
import javax.faces.context.FacesContext;
88
import javax.inject.Inject;
9+
import javax.inject.Named;
910
import javax.servlet.http.HttpServletResponse;
1011

12+
import org.jboss.logging.Logger;
1113
import org.jboss.seam.security.Authenticator;
1214
import org.jboss.seam.security.external.openid.api.OpenIdRelyingPartyApi;
1315
import org.jboss.seam.security.external.openid.api.OpenIdRequestedAttribute;
@@ -18,14 +20,16 @@
1820
* @author Shane Bryzak
1921
*
2022
*/
21-
public @Model class OpenIdAuthenticator implements Authenticator
23+
public @Named("openIdAuthenticator") @RequestScoped class OpenIdAuthenticator implements Authenticator
2224
{
2325
private String openIdProviderUrl;
2426

2527
@Inject private OpenIdRelyingPartyApi openIdApi;
2628

2729
@Inject List<OpenIdProvider> providers;
2830

31+
@Inject Logger log;
32+
2933
private String providerCode;
3034

3135
public String getProviderCode()
@@ -66,9 +70,12 @@ public AuthStatus authenticate()
6670
attributes.add(openIdApi.createOpenIdRequestedAttribute("email", "http://schema.openid.net/contact/email", false, null));
6771

6872
OpenIdProvider selectedProvider = getSelectedProvider();
73+
String url = selectedProvider != null ? selectedProvider.getUrl() : getOpenIdProviderUrl();
74+
75+
if (log.isDebugEnabled()) log.debug("Logging in using OpenID url: " + url);
6976

70-
openIdApi.login(selectedProvider != null ? selectedProvider.getUrl() : getOpenIdProviderUrl(),
71-
attributes, (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse());
77+
openIdApi.login(url, attributes,
78+
(HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse());
7279

7380
return AuthStatus.DEFERRED;
7481
}

external/src/main/java/org/jboss/seam/security/external/openid/OpenIdRpAuthenticationService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ public void handleIncomingMessage(HttpServletRequest httpRequest, HttpServletRes
8888

8989
// retrieve the previously stored discovery information
9090
DiscoveryInformation discovered = openIdRequest.getDiscoveryInformation();
91+
if (discovered == null)
92+
{
93+
throw new IllegalStateException("No discovery information found in OpenID request");
94+
}
9195

9296
// extract the receiving URL from the HTTP request
9397
StringBuffer receivingURL = httpRequest.getRequestURL();

impl/pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,14 @@
5959
<groupId>org.drools</groupId>
6060
<artifactId>drools-core</artifactId>
6161
<version>${drools.version}</version>
62+
<optional>true</optional>
6263
</dependency>
6364

6465
<dependency>
6566
<groupId>org.drools</groupId>
6667
<artifactId>drools-compiler</artifactId>
6768
<version>${drools.version}</version>
69+
<optional>true</optional>
6870
</dependency>
6971

7072
<!--dependency>
@@ -144,7 +146,6 @@
144146
<dependency>
145147
<groupId>org.jboss.seam.persistence</groupId>
146148
<artifactId>seam-persistence</artifactId>
147-
<optional>true</optional>
148149
</dependency>
149150

150151
<dependency>

impl/src/main/java/org/jboss/seam/security/IdentityImpl.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import javax.enterprise.context.SessionScoped;
1414
import javax.enterprise.inject.AmbiguousResolutionException;
15+
import javax.enterprise.inject.Any;
1516
import javax.enterprise.inject.Instance;
1617
import javax.enterprise.inject.UnsatisfiedResolutionException;
1718
import javax.enterprise.inject.spi.BeanManager;
@@ -64,7 +65,7 @@
6465
@Inject private PermissionMapper permissionMapper;
6566

6667
@Inject Instance<RequestSecurityState> requestSecurityState;
67-
@Inject Instance<Authenticator> authenticators;
68+
@Inject @Any Instance<Authenticator> authenticators;
6869

6970
private User user;
7071

@@ -276,7 +277,7 @@ protected boolean authenticate() throws AuthenticationException
276277

277278
if (authenticator == null)
278279
{
279-
throw new AuthenticationException("No Authenticator could be located");
280+
throw new AuthenticationException("An Authenticator could be located");
280281
}
281282

282283
if (AuthStatus.SUCCESS.equals(authenticator.authenticate()))
@@ -313,26 +314,25 @@ protected Authenticator lookupAuthenticator() throws AuthenticationException
313314
{
314315
if (!Strings.isEmpty(authenticatorName))
315316
{
316-
try
317+
Instance<Authenticator> selected = authenticators.select(new NamedLiteral(authenticatorName));
318+
if (selected.isAmbiguous())
317319
{
318-
return authenticators.select(new NamedLiteral(authenticatorName)).get();
320+
log.error("Multiple Authenticators found with configured name [" + authenticatorName + "]");
321+
return null;
319322
}
320-
catch (UnsatisfiedResolutionException ex)
321-
{
322-
throw new AuthenticationException("The specified Authenticator [" +
323-
authenticatorName + "] cannot be located");
324-
}
325-
catch (AmbiguousResolutionException ex)
323+
324+
if (selected.isUnsatisfied())
326325
{
327-
throw new AuthenticationException("Multiple Authenticator instances named [" +
328-
authenticatorName + "] were located");
326+
log.error("No authenticator with name [" + authenticatorName + "] was found");
327+
return null;
329328
}
329+
330+
return selected.get();
330331
}
331-
332-
332+
333333
for (Authenticator auth : authenticators)
334334
{
335-
// auth.
335+
log.debug("Found authenticator: " + auth);
336336
}
337337

338338
return null;

impl/src/main/java/org/jboss/seam/security/management/action/ChangePasswordAction.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@
77

88
import org.jboss.seam.persistence.transaction.Transactional;
99
import org.jboss.seam.security.Identity;
10-
import org.jboss.seam.solder.core.Requires;
1110
import org.picketlink.idm.api.Credential;
1211
import org.picketlink.idm.api.IdentitySession;
1312
import org.picketlink.idm.common.exception.IdentityException;
1413
import org.picketlink.idm.impl.api.PasswordCredential;
1514

16-
@Requires("org.jboss.seam.persistence.transaction.TransactionInterceptor")
1715
public @Transactional @Model class ChangePasswordAction implements Serializable
1816
{
1917
private static final long serialVersionUID = -8727330690588109980L;

impl/src/main/java/org/jboss/seam/security/management/action/GroupAction.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import org.jboss.seam.persistence.transaction.Transactional;
1212
import org.jboss.seam.security.GroupImpl;
13-
import org.jboss.seam.solder.core.Requires;
1413
import org.picketlink.idm.api.Group;
1514
import org.picketlink.idm.api.IdentitySession;
1615
import org.picketlink.idm.common.exception.IdentityException;
@@ -20,7 +19,6 @@
2019
*
2120
* @author Shane Bryzak
2221
*/
23-
@Requires("org.jboss.seam.persistence.transaction.TransactionInterceptor")
2422
public @Named @ConversationScoped class GroupAction implements Serializable
2523
{
2624
private static final long serialVersionUID = -1553124158319503903L;

impl/src/main/java/org/jboss/seam/security/management/action/RoleAction.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import javax.inject.Named;
99

1010
import org.jboss.seam.persistence.transaction.Transactional;
11-
import org.jboss.seam.solder.core.Requires;
1211
import org.picketlink.idm.api.IdentitySession;
1312
import org.picketlink.idm.common.exception.FeatureNotSupportedException;
1413
import org.picketlink.idm.common.exception.IdentityException;
@@ -18,7 +17,6 @@
1817
*
1918
* @author Shane Bryzak
2019
*/
21-
@Requires("org.jboss.seam.persistence.transaction.TransactionInterceptor")
2220
public @Named @ConversationScoped class RoleAction implements Serializable
2321
{
2422
private static final long serialVersionUID = -4215849488301658353L;

0 commit comments

Comments
 (0)