Skip to content
This repository has been archived by the owner on Feb 9, 2021. It is now read-only.

Commit

Permalink
BZ-1060747: remove weld extensions by using @Alternative
Browse files Browse the repository at this point in the history
Conflicts:
	uberfire-api/src/main/java/org/uberfire/rpc/impl/SessionInfoImpl.java
	uberfire-security/uberfire-security-server/src/main/java/org/uberfire/security/server/auth/HttpAuthenticationManager.java
	uberfire-security/uberfire-security-server/src/main/resources/META-INF/beans.xml
  • Loading branch information
porcelli committed Feb 10, 2014
1 parent 051ffeb commit 775dba3
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 49 deletions.
@@ -1,11 +1,13 @@
package org.uberfire.rpc.impl;

import static org.uberfire.commons.validation.PortablePreconditions.checkNotEmpty;
import static org.uberfire.commons.validation.PortablePreconditions.checkNotNull;
import javax.enterprise.inject.Alternative;

import org.uberfire.rpc.SessionInfo;
import org.uberfire.security.Identity;

import static org.uberfire.commons.validation.PortablePreconditions.*;

@Alternative
public class SessionInfoImpl implements SessionInfo {

private String id;
Expand Down Expand Up @@ -66,7 +68,7 @@ public int hashCode() {

@Override
public String toString() {
return "SessionInfoImpl [id=" + id + ", identity=" + identity + "]";
return "SessionInfoImpl [id=" + id + ", identity=" + identity + "]";
}

}
9 changes: 1 addition & 8 deletions uberfire-api/src/main/resources/META-INF/beans.xml
@@ -1,13 +1,6 @@
<beans xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:weld="http://jboss.org/schema/weld/beans"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee http://docs.jboss.org/cdi/beans_1_0.xsd
http://jboss.org/schema/weld/beans http://jboss.org/schema/weld/beans_1_1.xsd">
http://java.sun.com/xml/ns/javaee http://docs.jboss.org/cdi/beans_1_0.xsd">

<weld:scan>

<weld:exclude name="org.uberfire.rpc.impl.SessionInfoImpl"/>

</weld:scan>
</beans>
Expand Up @@ -16,6 +16,8 @@

package org.uberfire.backend.server.security;

import javax.enterprise.inject.Alternative;

import org.uberfire.backend.repositories.Repository;
import org.uberfire.backend.server.repositories.RepositoryServiceImpl;
import org.uberfire.java.nio.file.FileSystem;
Expand All @@ -33,6 +35,7 @@
import static org.uberfire.commons.validation.PortablePreconditions.*;
import static org.uberfire.security.authz.AuthorizationResult.*;

@Alternative
public class RepositoryAuthorizationManager implements AuthorizationManager {

private final RuntimeResourceDecisionManager decisionManager = new RuntimeResourceDecisionManager( new RuntimeResourceManager() );
Expand Down
Expand Up @@ -21,6 +21,7 @@
import static org.uberfire.security.authz.AuthorizationResult.ACCESS_GRANTED;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Alternative;

import org.uberfire.security.Resource;
import org.uberfire.security.Subject;
Expand All @@ -30,29 +31,31 @@
import org.uberfire.security.authz.RoleDecisionManager;

@ApplicationScoped
@Alternative
public class RuntimeAuthorizationManager implements AuthorizationManager {

private final RuntimeResourceManager resourceManager = new RuntimeResourceManager();
private final RuntimeResourceDecisionManager decisionManager = new RuntimeResourceDecisionManager(resourceManager);
private final RuntimeResourceDecisionManager decisionManager = new RuntimeResourceDecisionManager( resourceManager );
private final RoleDecisionManager roleDecisionManager = new DefaultRoleDecisionManager();

@Override
public boolean supports(final Resource resource) {
return resourceManager.supports(resource);
public boolean supports( final Resource resource ) {
return resourceManager.supports( resource );
}

@Override
public boolean authorize(final Resource resource, final Subject subject)
public boolean authorize( final Resource resource,
final Subject subject )
throws AuthorizationException {
if (!resourceManager.requiresAuthentication(resource)) {
if ( !resourceManager.requiresAuthentication( resource ) ) {
return true;
}

checkNotNull("subject", subject);
checkNotNull( "subject", subject );

final AuthorizationResult finalResult = decisionManager.decide(resource, subject, roleDecisionManager);
final AuthorizationResult finalResult = decisionManager.decide( resource, subject, roleDecisionManager );

if (finalResult.equals(ACCESS_ABSTAIN) || finalResult.equals(ACCESS_GRANTED)) {
if ( finalResult.equals( ACCESS_ABSTAIN ) || finalResult.equals( ACCESS_GRANTED ) ) {
return true;
}

Expand Down
Expand Up @@ -16,18 +16,11 @@

package org.uberfire.security.server.auth;

import static org.uberfire.commons.validation.PortablePreconditions.checkNotEmpty;
import static org.uberfire.commons.validation.PortablePreconditions.checkNotNull;
import static org.uberfire.commons.validation.Preconditions.checkInstanceOf;
import static org.uberfire.security.Role.ROLE_REMEMBER_ME;
import static org.uberfire.security.auth.AuthenticationStatus.FAILED;
import static org.uberfire.security.auth.AuthenticationStatus.SUCCESS;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.enterprise.inject.Alternative;
import javax.servlet.RequestDispatcher;

import org.uberfire.security.ResourceManager;
Expand All @@ -50,6 +43,13 @@
import org.uberfire.security.server.SecurityConstants;
import org.uberfire.security.server.cdi.SecurityFactory;

import static org.uberfire.commons.validation.PortablePreconditions.checkNotEmpty;
import static org.uberfire.commons.validation.PortablePreconditions.checkNotNull;
import static org.uberfire.commons.validation.Preconditions.*;
import static org.uberfire.security.Role.*;
import static org.uberfire.security.auth.AuthenticationStatus.*;

@Alternative
public class HttpAuthenticationManager implements AuthenticationManager {

private final List<AuthenticationScheme> authSchemes;
Expand Down Expand Up @@ -109,7 +109,7 @@ public Subject authenticate( final SecurityContext context ) throws Authenticati

String preservedQueryStr = httpContext.getRequest().getQueryString();

if (preservedQueryStr == null) {
if ( preservedQueryStr == null ) {
preservedQueryStr = "";
} else {
preservedQueryStr = "?" + preservedQueryStr;
Expand All @@ -126,7 +126,7 @@ public Subject authenticate( final SecurityContext context ) throws Authenticati

// prepend context path for context-relative forceURLs
String contextPrefix = "";
if (forceURL.startsWith( "/" )) {
if ( forceURL.startsWith( "/" ) ) {
contextPrefix = httpContext.getRequest().getContextPath();
}

Expand Down Expand Up @@ -228,11 +228,10 @@ private boolean useRedirect( String originalRequest ) {

@Override
public String toString() {
return "HttpAuthenticationManager [authSchemes=" + authSchemes + ", authProviders=" + authProviders
+ ", roleProviders=" + roleProviders + ", subjectPropertiesProviders=" + subjectPropertiesProviders
+ ", authStorageProviders=" + authStorageProviders + ", resourceManager=" + resourceManager
+ ", requestCache=" + requestCache + ", forceURL=" + forceURL + "]";
return "HttpAuthenticationManager [authSchemes=" + authSchemes + ", authProviders=" + authProviders
+ ", roleProviders=" + roleProviders + ", subjectPropertiesProviders=" + subjectPropertiesProviders
+ ", authStorageProviders=" + authStorageProviders + ", resourceManager=" + resourceManager
+ ", requestCache=" + requestCache + ", forceURL=" + forceURL + "]";
}


}
Expand Up @@ -2,12 +2,15 @@

import java.util.HashMap;

import javax.enterprise.inject.Alternative;

import org.uberfire.security.auth.SubjectPropertiesProvider;
import org.uberfire.security.server.auth.BasicUserPassAuthenticationScheme;
import org.uberfire.security.server.auth.source.JAASAuthenticationSource;

import static org.uberfire.security.server.SecurityConstants.*;

@Alternative
public class JAASAuthenticationManager extends SimpleUserPassAuthenticationManager {

public JAASAuthenticationManager() {
Expand Down
Expand Up @@ -2,10 +2,13 @@

import java.util.Collections;

import javax.enterprise.inject.Alternative;

import org.uberfire.security.auth.SubjectPropertiesProvider;
import org.uberfire.security.server.auth.BasicUserPassAuthenticationScheme;
import org.uberfire.security.server.auth.source.PropertyUserSource;

@Alternative
public class PropertyAuthenticationManager extends SimpleUserPassAuthenticationManager {

public PropertyAuthenticationManager( final SubjectPropertiesProvider propertiesProvider ) {
Expand Down
Expand Up @@ -5,6 +5,8 @@
import java.util.List;
import java.util.Map;

import javax.enterprise.inject.Alternative;

import org.uberfire.security.Role;
import org.uberfire.security.SecurityContext;
import org.uberfire.security.Subject;
Expand All @@ -24,6 +26,7 @@
import static org.uberfire.commons.validation.Preconditions.*;
import static org.uberfire.security.auth.AuthenticationStatus.*;

@Alternative
public class SimpleUserPassAuthenticationManager implements AuthenticationManager {

private final AuthenticationScheme scheme;
Expand Down
Expand Up @@ -29,7 +29,6 @@
import org.uberfire.security.authz.AuthorizationManager;
import org.uberfire.security.impl.IdentityImpl;
import org.uberfire.security.impl.RoleImpl;
import org.uberfire.security.impl.authz.RuntimeAuthorizationManager;

public class SecurityFactory {

Expand All @@ -38,13 +37,13 @@ public class SecurityFactory {
}};
private static final ThreadLocal<Subject> subjects = new ThreadLocal<Subject>();

static private RuntimeAuthorizationManager authzManager = null;
static private AuthorizationManager authzManager = null;

public static void setSubject( final Subject subject ) {
subjects.set( subject );
}

public static void setAuthzManager( final RuntimeAuthorizationManager authzManager ) {
public static void setAuthzManager( final AuthorizationManager authzManager ) {
SecurityFactory.authzManager = authzManager;
}

Expand All @@ -59,7 +58,7 @@ public static Identity getIdentity() {

@Produces
@ApplicationScoped
public static RuntimeAuthorizationManager getAuthzManager() {
public static AuthorizationManager getAuthzManager() {
return authzManager;
}

Expand Down
@@ -1,17 +1,7 @@
<beans xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:weld="http://jboss.org/schema/weld/beans"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee http://docs.jboss.org/cdi/beans_1_0.xsd
http://jboss.org/schema/weld/beans http://jboss.org/schema/weld/beans_1_1.xsd">

<weld:scan>
<weld:exclude name="org.uberfire.security.server.auth.HttpAuthenticationManager"/>
<weld:exclude name="org.uberfire.security.server.auth.impl.JAASAuthenticationManager"/>
<weld:exclude name="org.uberfire.security.server.auth.impl.PropertyAuthenticationManager"/>
<weld:exclude name="org.uberfire.security.server.auth.impl.SimpleUserPassAuthenticationManager"/>
<weld:exclude name="org.uberfire.backend.server.security.RepositoryAuthorizationManager"/>
</weld:scan>
http://java.sun.com/xml/ns/javaee http://docs.jboss.org/cdi/beans_1_0.xsd">

<interceptors>
<class>org.uberfire.security.server.authz.cdi.RolesInterceptor</class>
Expand Down

0 comments on commit 775dba3

Please sign in to comment.