Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Michail Gagauz committed Jul 15, 2015
1 parent c6bc106 commit 398dcf0
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 279 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package org.gagauz.tapestry.security;

import java.util.List;

import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.ApplicationStateManager;
import org.apache.tapestry5.services.Request;
import org.apache.tapestry5.services.Session;
import org.gagauz.tapestry.security.api.Credentials;
import org.gagauz.tapestry.security.api.LoginHandler;
import org.gagauz.tapestry.security.api.LogoutHandler;
import org.gagauz.tapestry.security.api.AuthenticationHandler;
import org.gagauz.tapestry.security.api.LoginDetails;
import org.gagauz.tapestry.security.api.User;
import org.gagauz.tapestry.security.api.UserProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

public class AuthenticationService {

private static final Logger log = LoggerFactory.getLogger(AuthenticationService.class);
Expand All @@ -25,25 +24,19 @@ public class AuthenticationService {
private ApplicationStateManager applicationStateManager;

@Inject
private List<LoginHandler> loginHandlers;

@Inject
private List<LogoutHandler> logoutHandlers;
private List<AuthenticationHandler> handlers;

@Inject
private Request request;

public User login(Credentials credentials) {
public User login(LoginDetails credentials) {
User newUser = userProvider.findByCredentials(credentials);

LoginResult result = null;

if (null != newUser) {
User oldUser = applicationStateManager.getIfExists(newUser.getClass());
Class clz = newUser.getClass();
applicationStateManager.set(clz, newUser);
}
for (LoginHandler handler : loginHandlers) {
for (AuthenticationHandler handler : handlers) {
handler.handleLogin(newUser, credentials);
}

Expand All @@ -54,7 +47,7 @@ public void logout() {

User user = applicationStateManager.getIfExists(User.class);

for (LogoutHandler handler : logoutHandlers) {
for (AuthenticationHandler handler : handlers) {
handler.handleLogout(user);
}

Expand Down
14 changes: 0 additions & 14 deletions src/main/java/org/gagauz/tapestry/security/LoginFailedResult.java

This file was deleted.

69 changes: 0 additions & 69 deletions src/main/java/org/gagauz/tapestry/security/LoginResult.java

This file was deleted.

27 changes: 0 additions & 27 deletions src/main/java/org/gagauz/tapestry/security/LoginSuccessResult.java

This file was deleted.

127 changes: 0 additions & 127 deletions src/main/java/org/gagauz/tapestry/security/SecurityEncryptor.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.gagauz.tapestry.security.api;

public interface AccessAttribute {

public static final AccessAttribute EMPTY_ATTRIBUTE = new AccessAttribute() {
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.gagauz.tapestry.security.api;

public interface AuthenticationHandler<T extends LoginDetails> {
void handleLogin(User newUser, T credentials);

void handleLogout(User user);
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.gagauz.tapestry.security.api;

public interface LoginDetails {

}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.gagauz.tapestry.security.api;

public interface UserProvider<T extends User> {

T findByCredentials(Credentials credentials);
public interface UserProvider<T extends LoginDetails> {
User findByCredentials(T credentials);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
import org.gagauz.tapestry.security.api.AccessAttribute;
import org.gagauz.tapestry.security.api.AccessAttributeChecker;

// TODO: Auto-generated Javadoc
/**
* The Class IfAuthorized.
*/
public class IfAuthorized extends AbstractConditional {

/** The roles. */
Expand All @@ -22,8 +18,11 @@ public class IfAuthorized extends AbstractConditional {

@Override
protected boolean test() {
AccessAttribute accessAttribute = null == attribute
? AccessAttribute.EMPTY_ATTRIBUTE
: attribute;
try {
accessAttributeChecker.check(attribute);
accessAttributeChecker.check(accessAttribute);
} catch (AccessDeniedException e) {
return false;
}
Expand Down

0 comments on commit 398dcf0

Please sign in to comment.