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

Commit

Permalink
Merge remote-tracking branch 'origin/integration/master' into new-ope…
Browse files Browse the repository at this point in the history
…nid-login-screen

Conflicts:
	pom.xml
  • Loading branch information
Carlos A. Munoz committed Sep 10, 2013
2 parents c5fec15 + aa73a8d commit 729567f
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 32 deletions.
35 changes: 35 additions & 0 deletions .gitattributes
@@ -0,0 +1,35 @@
# See https://help.github.com/articles/dealing-with-line-endings

# Handle line endings automatically for files detected as text
# and leave all files detected as binary untouched.
* text=auto

# Explicitly declare text files we want to always be normalized and converted
# to native line endings on checkout.
*.c text
*.css text
*.csv text
*.groovy text
*.h text
*.html text
*.ini text
*.java text
*.js text
*.launch text
*.po text
*.pot text
*.properties text
*.sh text
*.sql text
*.txt text
*.xhtml text
*.xml text

# Declare files that will always have CRLF line endings on checkout.
*.sln text eol=crlf

# Denote all files that are truly binary and should not be modified.
*.gif binary
*.jar binary
*.jpg binary
*.png binary
11 changes: 7 additions & 4 deletions functional-test/src/main/java/org/zanata/page/AbstractPage.java
Expand Up @@ -82,11 +82,14 @@ protected void clickAndCheckErrors(WebElement button)
protected void clickAndExpectErrors(WebElement button)
{
button.click();
List<String> errors = getErrors();
if (errors.isEmpty())
refreshPageUntil(this, new Predicate<WebDriver>()
{
throw new RuntimeException("Errors expected, none found.");
}
@Override
public boolean apply(WebDriver input)
{
return getErrors().size() > 0;
}
});
}

public List<String> getErrors()
Expand Down
6 changes: 6 additions & 0 deletions functional-test/src/test/resources/conf/standalone.xml
Expand Up @@ -218,6 +218,7 @@
<subsystem xmlns="urn:jboss:domain:naming:1.3">
<bindings>
<simple name="java:global/zanata/security/auth-policy-names/internal" value="zanata.internal"/>
<simple name="java:global/zanata/security/auth-policy-names/openid" value="zanata.openid"/>
<simple name="java:global/zanata/security/admin-users" value="admin"/>
<simple name="java:global/zanata/email/default-from-address" value="no-reply@zanata.org" />
<simple name="java:global/zanata/files/document-storage-directory" value="${project.build.directory}/zanata-documents"/>
Expand Down Expand Up @@ -262,6 +263,11 @@
<login-module code="org.jboss.seam.security.jaas.SeamLoginModule" flag="required"/>
</authentication>
</security-domain>
<security-domain name="zanata.openid">
<authentication>
<login-module code="org.zanata.security.OpenIdLoginModule" flag="required"/>
</authentication>
</security-domain>
</security-domains>
</subsystem>
<subsystem xmlns="urn:jboss:domain:threads:1.1"/>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -28,7 +28,7 @@
<icu4j.version>4.8</icu4j.version>
<lombok.source.dir>${project.build.sourceDirectory}/org/zanata</lombok.source.dir>
<lucene.version>3.6.2</lucene.version>
<seam.version>2.3.0.Final</seam.version>
<seam.version>2.3.1.Final</seam.version>
<gwteventservice.version>1.2.1</gwteventservice.version>
<okapi.version>0.22</okapi.version>

Expand Down
30 changes: 20 additions & 10 deletions zanata-war/src/main/java/org/zanata/action/ProfileAction.java
Expand Up @@ -22,6 +22,7 @@

import java.io.Serializable;

import javax.faces.event.ValueChangeEvent;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

Expand Down Expand Up @@ -63,10 +64,11 @@ public class ProfileAction implements Serializable
private String username;
private String activationKey;
private boolean valid;
private boolean newUser;

@In
ApplicationConfiguration applicationConfiguration;

@Logger
Log log;

Expand All @@ -93,24 +95,24 @@ public class ProfileAction implements Serializable

@In
RegisterService registerServiceImpl;

@In
EmailChangeService emailChangeService;

private void validateEmail(String email)
{
HPerson person = personDAO.findByEmail(email);

if( person != null && !person.getAccount().equals( authenticatedAccount ) )
{
valid = false;
FacesMessages.instance().addToControl("email", "This email address is already taken");
}
}

private void validateUsername()
private void validateUsername(String username)
{
HAccount account = accountDAO.getByUsername(this.username);
HAccount account = accountDAO.getByUsername(username);

if( account != null && !account.equals( authenticatedAccount ) )
{
Expand All @@ -119,19 +121,26 @@ private void validateUsername()
}
}

public void verifyUsernameAvailable(ValueChangeEvent e)
{
String username = (String) e.getNewValue();
validateUsername(username);
}

@Create
public void onCreate()
{
username = identity.getCredentials().getUsername();
if (identityStore.isNewUser(username))
newUser = identityStore.isNewUser(username);
if (newUser)
{
name = identity.getCredentials().getUsername();
String domain = applicationConfiguration.getDomainName();
if( domain == null )
{
email = "";
}
else
else
{
if( applicationConfiguration.isOpenIdAuth() )
{
Expand Down Expand Up @@ -188,7 +197,7 @@ public String getUsername()
public void setUsername(String username)
{
this.username = username;
validateUsername();
validateUsername(username);
}

public String getActivationKey()
Expand All @@ -206,7 +215,7 @@ public String edit()
{
this.valid = true;
validateEmail(this.email);
validateUsername();
validateUsername(username);

if( !this.isValid() )
{
Expand Down Expand Up @@ -267,7 +276,8 @@ public boolean isValid()

public boolean isNewUser()
{
return identityStore.isNewUser(username);
// in case someone else has registered in the middle
return newUser || identityStore.isNewUser(username);
}

}
Expand Up @@ -231,7 +231,7 @@ else if (identity.isLoggedIn())
{
if (userRedirect != null)
{
if(userRedirect.isRedirect() && !userRedirect.isRedirectToHome())
if(userRedirect.isRedirect() && !userRedirect.isRedirectToHome() && !userRedirect.isRedirectToRegister())
{
return "redirect";
}
Expand Down
27 changes: 21 additions & 6 deletions zanata-war/src/main/java/org/zanata/security/UserRedirectBean.java
Expand Up @@ -29,8 +29,6 @@
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.faces.Redirect;
import org.jboss.seam.security.Identity;
import org.jboss.seam.web.ServletContexts;

/**
Expand All @@ -51,6 +49,7 @@
public class UserRedirectBean implements Serializable
{
private static final String HOME_URL = "/";
private static final String REGISTER_URL = "/register";
private static final String ERROR_URL = "/error";

/**
Expand Down Expand Up @@ -177,17 +176,33 @@ public boolean isRedirect()
}

public boolean isRedirectToHome()
{
return isRedirectTo(HOME_URL);
}

public boolean isRedirectToRegister()
{
return isRedirectTo(REGISTER_URL);
}

// provided user is logged in, they should be redirect to dashboard
public boolean shouldRedirectToDashboard()
{
return isRedirectToHome() || isRedirectToRegister();
}

private boolean isRedirectTo(String url)
{
if (isRedirect())
{
String url = getUrl();
int qsIndex = url.indexOf('?');
String redirectingUrl = getUrl();
int qsIndex = redirectingUrl.indexOf('?');
if (qsIndex > 0)
{
url = url.substring(0, qsIndex);
redirectingUrl = redirectingUrl.substring(0, qsIndex);
}

if (url.endsWith(HOME_URL))
if (redirectingUrl.endsWith(url))
{
return true;
}
Expand Down
15 changes: 6 additions & 9 deletions zanata-war/src/main/webapp/WEB-INF/pages.xml
Expand Up @@ -10,8 +10,11 @@
<redirect view-id="/home.xhtml" />
</rule>
</navigation>
<navigation from-action="#{projectSearch.search}">
<redirect view-id="/search.xhtml"/>
</navigation>
</page>

<page view-id="/dashboard/*" login-required="true">
<restrict>#{identity.loggedIn}</restrict>
</page>
Expand All @@ -35,12 +38,6 @@
<action execute="#{breadcrumbs.addLocation('', messages['jsf.SearchProjects'])}"/>
</page>

<page view-id="*">
<navigation from-action="#{projectSearch.search}">
<redirect view-id="/search.xhtml"/>
</navigation>
</page>

<!-- Landing page for open id authentication -->
<page view-id="/openid.xhtml">
<navigation>
Expand All @@ -53,7 +50,7 @@
<rule if="#{!identity.loggedIn}">
<redirect view-id="/account/login.xhtml" />
</rule>
<rule if="#{authenticationManager.authenticated and !authenticationManager.newUser and userRedirect.redirectToHome}">
<rule if="#{authenticationManager.authenticated and !authenticationManager.newUser and userRedirect.userRedirect.shouldRedirectToDashboard()}}">
<redirect view-id="/dashboard/home.xhtml" />
</rule>
<rule if="#{authenticationManager.authenticated and !authenticationManager.newUser and userRedirect.redirect}">
Expand Down Expand Up @@ -105,7 +102,7 @@
<begin-conversation/>
<redirect view-id="/account/inactive_account.xhtml"/>
</rule>
<rule if="#{authenticationManager.authenticated and !authenticationManager.newUser and userRedirect.redirectToHome}">
<rule if="#{authenticationManager.authenticated and !authenticationManager.newUser and userRedirect.shouldRedirectToDashboard()}">
<redirect view-id="/dashboard/home.xhtml" />
</rule>
<rule if="#{authenticationManager.authenticated and !authenticationManager.newUser and userRedirect.redirect}">
Expand Down
3 changes: 2 additions & 1 deletion zanata-war/src/main/webapp/profile/edit.xhtml
Expand Up @@ -36,7 +36,8 @@
</ui:remove>
<s:decorate id="usernameField" template="../WEB-INF/layout/edit.xhtml" rendered="#{profileAction.newUser}" enclose="true">
<ui:define name="label">#{messages['jsf.Username']}</ui:define>
<h:inputText id="username" value="#{profileAction.username}" required="true" >
<h:inputText id="username" value="#{profileAction.username}" required="true"
valueChangeListener="#{profileAction.verifyUsernameAvailable}" onchange="submit()" >
<a4j:ajax event="blur" render="usernameField" execute="@this"/>
</h:inputText>

Expand Down

0 comments on commit 729567f

Please sign in to comment.