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

Commit

Permalink
migrate pages.xml restrict and require-login to jsf backed bean
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Huang committed Jul 21, 2015
1 parent 039807e commit e29c41a
Show file tree
Hide file tree
Showing 27 changed files with 650 additions and 137 deletions.
13 changes: 4 additions & 9 deletions zanata-model/src/main/java/org/zanata/model/HAccount.java
Expand Up @@ -50,11 +50,6 @@
import org.hibernate.annotations.NaturalId;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Indexed;
import org.jboss.seam.annotations.security.management.UserEnabled;
import org.jboss.seam.annotations.security.management.UserPassword;
import org.jboss.seam.annotations.security.management.UserPrincipal;
import org.jboss.seam.annotations.security.management.UserRoles;
import org.jboss.seam.security.management.PasswordHash;
import org.zanata.model.security.HCredentials;
import org.zanata.model.type.UserApiKey;
import org.zanata.rest.dto.Account;
Expand Down Expand Up @@ -108,7 +103,7 @@ public HPerson getPerson() {
}

@NaturalId
@UserPrincipal
// @UserPrincipal
@Field()
public String getUsername() {
return username;
Expand All @@ -119,12 +114,12 @@ public boolean isPersonAccount() {
return person != null;
}

@UserPassword(hash = PasswordHash.ALGORITHM_MD5)
// @UserPassword(hash = PasswordHash.ALGORITHM_MD5)
public String getPasswordHash() {
return passwordHash;
}

@UserEnabled
// @UserEnabled
public boolean isEnabled() {
return enabled;
}
Expand All @@ -136,7 +131,7 @@ public String getApiKey() {
}

@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@UserRoles
// @UserRoles
@ManyToMany(targetEntity = HAccountRole.class)
@JoinTable(name = "HAccountMembership", joinColumns = @JoinColumn(
name = "accountId"), inverseJoinColumns = @JoinColumn(
Expand Down
Expand Up @@ -28,6 +28,7 @@
import lombok.Setter;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Create;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
Expand All @@ -37,6 +38,7 @@
import org.zanata.dao.AccountDAO;
import org.zanata.model.HAccount;
import org.zanata.security.AuthenticationManager;
import org.zanata.security.ZanataIdentity;
import org.zanata.security.openid.OpenIdAuthCallback;
import org.zanata.security.openid.OpenIdAuthenticationResult;
import org.zanata.security.openid.OpenIdProviderType;
Expand Down Expand Up @@ -76,6 +78,11 @@ public class AccountMergeAction implements Serializable {

private boolean accountsValid;

@Create
public void onCreate() {
ZanataIdentity.instance().checkLoggedIn();
}

public boolean getAccountsValid() {
return accountsValid;
}
Expand Down
Expand Up @@ -22,6 +22,8 @@
import org.zanata.i18n.Messages;
import org.zanata.model.HLocale;
import org.zanata.rest.dto.Glossary;
import org.zanata.security.annotations.CheckLoggedIn;
import org.zanata.security.annotations.ZanataSecured;
import org.zanata.service.GlossaryFileService;
import org.zanata.ui.AbstractListFilter;
import org.zanata.ui.InMemoryListFilter;
Expand All @@ -38,6 +40,8 @@

@Name("glossaryAction")
@Scope(ScopeType.PAGE)
@ZanataSecured
@CheckLoggedIn
@Slf4j
public class GlossaryAction implements Serializable {
private static final long serialVersionUID = 1L;
Expand Down
Expand Up @@ -8,10 +8,12 @@
import org.apache.commons.lang.StringUtils;
import org.hibernate.validator.constraints.Email;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Create;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.Transactional;
import org.jboss.seam.security.AuthorizationException;
import org.zanata.action.validator.NotDuplicateEmail;
import org.zanata.dao.AccountActivationKeyDAO;
import org.zanata.dao.AccountDAO;
Expand All @@ -20,6 +22,7 @@
import org.zanata.model.HAccount;
import org.zanata.model.HAccountActivationKey;
import org.zanata.model.HPerson;
import org.zanata.security.AuthenticationManager;
import org.zanata.security.AuthenticationType;
import org.zanata.security.ZanataCredentials;
import org.zanata.security.ZanataOpenId;
Expand Down Expand Up @@ -53,6 +56,9 @@ public class InactiveAccountAction implements Serializable {
@In
private AccountActivationKeyDAO accountActivationKeyDAO;

@In
private AuthenticationManager authenticationManager;

@Getter
@Setter
@Email
Expand All @@ -63,6 +69,14 @@ public class InactiveAccountAction implements Serializable {

private static final long serialVersionUID = 1L;


@Create
public void onCreate() {
if (!authenticationManager.isAuthenticatedAccountWaitingForActivation()) {
throw new AuthorizationException("Account is not waiting for activation");
}
}

private HAccount getAccount() {
if(account == null) {
if (credentials.getAuthType() == AuthenticationType.OPENID) {
Expand Down
Expand Up @@ -29,6 +29,7 @@
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.Transactional;
import org.jboss.seam.security.AuthorizationException;
import org.zanata.ApplicationConfiguration;
import org.zanata.i18n.Messages;
import org.zanata.security.AuthenticationType;
Expand Down Expand Up @@ -67,6 +68,9 @@ public class NewProfileAction extends AbstractProfileAction implements Serializa

@Create
public void onCreate() {
if (!identity.isPreAuthenticated()) {
throw new AuthorizationException("Need to be in pre authenticated state");
}
if (identity.getCredentials().getAuthType() != AuthenticationType.OPENID) {
// Open id user names are url's so they don't make good defaults
username = identity.getCredentials().getUsername();
Expand Down
Expand Up @@ -18,6 +18,8 @@
import org.jboss.seam.security.NotLoggedInException;
import org.jboss.seam.security.RunAsOperation;
import org.jboss.seam.security.management.IdentityManager;
import org.jboss.seam.ui.UnauthorizedCommandException;
import org.zanata.ApplicationConfiguration;
import org.zanata.exception.KeyNotFoundException;
import org.zanata.i18n.Messages;
import org.zanata.model.HAccountResetPasswordKey;
Expand All @@ -42,6 +44,9 @@ public class PasswordResetAction implements Serializable {
@In
private Messages msgs;

@In
private ApplicationConfiguration applicationConfiguration;

@Getter
private String activationKey;

Expand Down Expand Up @@ -81,6 +86,10 @@ public void setActivationKey(String activationKey) {

@Begin(join = true)
public void validateActivationKey() {
if (!applicationConfiguration.isInternalAuth()) {
throw new AuthorizationException(
"Password reset is only available for server using internal authentication");
}

if (getActivationKey() == null)
throw new KeyNotFoundException();
Expand Down
Expand Up @@ -259,6 +259,7 @@ protected boolean include(HPerson elem, String filter) {
};

public void createNew() {
identity.checkPermission(getInstance(), "insert");
getInstance().setDefaultProjectType(ProjectType.File);
selectedProjectType = getInstance().getDefaultProjectType().name();
enteredLocaleAliases.putAll(getLocaleAliases());
Expand Down
Expand Up @@ -66,6 +66,7 @@
@Scope(ScopeType.PAGE)
@Slf4j
public class TranslationMemoryAction implements Serializable {
private static final long serialVersionUID = -6791743907133760028L;
@In("jsfMessages")
private FacesMessages facesMessages;

Expand Down
Expand Up @@ -47,6 +47,7 @@
@CheckRole("admin")
@Slf4j
public class TranslationMemoryHome extends EntityHome<TransMemory> {
private static final long serialVersionUID = -8557363011909155662L;
@In
private SlugEntityService slugEntityServiceImpl;

Expand Down

0 comments on commit e29c41a

Please sign in to comment.