Skip to content

Commit

Permalink
fix #15
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur Gregorio committed Aug 6, 2019
1 parent cae9bcc commit 9037857
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 58 deletions.
12 changes: 0 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,6 @@
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.5.1</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@

import br.eti.arthurgregorio.shiroee.config.jdbc.UserDetails;
import br.eti.arthurgregorio.shiroee.config.jdbc.UserDetailsProvider;
import br.eti.arthurgregorio.shiroee.config.messages.Messages;
import org.apache.shiro.authc.AuthenticationException;

import java.util.Set;

import static br.eti.arthurgregorio.shiroee.config.messages.Messages.ACCOUNT_NOT_FOUND;
import static com.google.common.base.Preconditions.checkNotNull;

/**
Expand Down Expand Up @@ -59,9 +56,7 @@ public DatabaseAuthenticationMechanism(UserDetailsProvider userDetailsProvider)
*/
@Override
public UserDetails getAccount(String username) {
return this.userDetailsProvider.findUserDetailsByUsername(username)
.orElseThrow(() -> new AuthenticationException(
ACCOUNT_NOT_FOUND.format(username)));
return this.userDetailsProvider.findByUsername(username);
}

/**
Expand All @@ -72,12 +67,7 @@ public UserDetails getAccount(String username) {
*/
@Override
public Set<String> getPermissions(String username) {

final UserDetails userDetails = this.userDetailsProvider
.findUserDetailsByUsername(username)
.orElseThrow(() -> new AuthenticationException(
Messages.ACCOUNT_NOT_FOUND.format(username)));

final UserDetails userDetails = this.userDetailsProvider.findByUsername(username);
return userDetails.getPermissions();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected WebEnvironment createEnvironment(ServletContext servletContext) {
final DefaultWebEnvironment environment = (DefaultWebEnvironment) super.createEnvironment(servletContext);

environment.setSecurityManager(this.configuration.configureSecurityManager());
environment.setFilterChainResolver(this.configuration.configurteFilterChainResolver());
environment.setFilterChainResolver(this.configuration.configureFilterChainResolver());

return environment;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package br.eti.arthurgregorio.shiroee.config.jdbc;

import org.apache.shiro.authc.UnknownAccountException;

import java.util.Optional;

/**
Expand All @@ -35,14 +37,16 @@ public interface UserDetailsProvider {
* @param username the username to search for the {@link UserDetails}
* @return a {@link Optional} with the details
*/
@Deprecated
Optional<UserDetails> findUserDetailsByUsername(String username);
@Deprecated(since = "1.5.0", forRemoval = true)
default Optional<UserDetails> findUserDetailsByUsername(String username) {
return Optional.of(this.findByUsername(username));
}

/**
* Get the {@link UserDetails} for an account
*
* @param username to search for details
* @return {@link UserDetails} for the given username
*/
UserDetails findByUsername(String username);
UserDetails findByUsername(String username) throws UnknownAccountException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,12 @@
*/
public enum Messages implements MessageFormatter {

LDAP_REPOSITORY_ERROR() {
@Override
public String format(Object... values) {
return "Can't create a connection to the LDAP/AD repository";
}
},
LDAP_CONFIGURATION_INCOMPLETE() {
@Override
public String format(Object... values) {
return "Ldap url, bind user/password was not provided, check your configurations";
}
},
NO_REALM_ERROR() {
@Override
public String format(Object... values) {
return "No realm provided for configuration";
}
},
CANT_LOAD_CONFIGURATION() {
@Override
public String format(Object... values) {
return String.format("Can't load %s configuration file from classpath", values);
}
},
CONFIGURATION_ERROR() {
@Override
public String format(Object... values) {
Expand All @@ -61,18 +43,6 @@ public String format(Object... values) {
return String.format("Tha configuration class %s has a unsatisfied or ambiguous dependency", values);
}
},
ACCOUNT_NOT_FOUND() {
@Override
public String format(Object... values) {
return String.format("Can't find local user with username", values);
}
},
ACCOUNT_BLOCKED() {
@Override
public String format(Object... values) {
return String.format("User %s is blocked on local accounts", values);
}
},
AUTHENTICATION_ERROR() {
@Override
public String format(Object... values) {
Expand Down

0 comments on commit 9037857

Please sign in to comment.