Skip to content

Commit

Permalink
Empty username is not allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
oharsta committed Oct 4, 2018
1 parent a79ec39 commit b8ecfd1
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion mujina-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<groupId>org.openconext</groupId>
<artifactId>mujina</artifactId>
<version>7.0.2</version>
<version>7.0.3</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion mujina-idp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<groupId>org.openconext</groupId>
<artifactId>mujina</artifactId>
<version>7.0.2</version>
<version>7.0.3</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.util.StringUtils;

import java.util.Arrays;

Expand All @@ -20,6 +21,9 @@ public AuthenticationProvider(IdpConfiguration idpConfiguration) {

@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
if (StringUtils.isEmpty(authentication.getPrincipal())) {
throw new InvalidAuthenticationException("Principal may not be empty");
}
if (idpConfiguration.getAuthenticationMethod().equals(ALL)) {
return new FederatedUserAuthenticationToken(
authentication.getPrincipal(),
Expand All @@ -33,7 +37,7 @@ public Authentication authenticate(Authentication authentication) throws Authent
.findFirst().map(userAuthenticationToken ->
//need to copy or else credentials are erased for future logins
userAuthenticationToken.clone())
.orElseThrow(() -> new AuthenticationException("User not found or bad credentials") {
.orElseThrow(() -> new InvalidAuthenticationException("User not found or bad credentials") {
});
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package mujina.idp;

import org.springframework.security.core.AuthenticationException;

public class InvalidAuthenticationException extends AuthenticationException {

public InvalidAuthenticationException(String msg) {
super(msg);
}
}
2 changes: 1 addition & 1 deletion mujina-idp/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ idp:
# Number of seconds after a message issue instant after which the message is considered expired
expires: 300
# Authentication method ALL for every username / password combination and USER for the configured users
auth_method: USER
auth_method: ALL
# Are endpoints compared. If so then pay notice to the base_url when behind a load balancer
compare_endpoints: true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import static org.apache.http.HttpStatus.SC_OK;

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = {"idp.auth_method=USER"})
public abstract class AbstractIntegrationTest {

@Autowired
Expand Down
2 changes: 1 addition & 1 deletion mujina-sp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<groupId>org.openconext</groupId>
<artifactId>mujina</artifactId>
<version>7.0.2</version>
<version>7.0.3</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<groupId>org.openconext</groupId>
<artifactId>mujina</artifactId>
<version>7.0.2</version>
<version>7.0.3</version>
<packaging>pom</packaging>

<properties>
Expand Down

0 comments on commit b8ecfd1

Please sign in to comment.