-
Notifications
You must be signed in to change notification settings - Fork 827
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/uaa-ldap-authentication' into develop
- Loading branch information
Showing
61 changed files
with
2,610 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
.../org/cloudfoundry/identity/uaa/authentication/AuthenticationPolicyRejectionException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* ****************************************************************************** | ||
* Cloud Foundry | ||
* Copyright (c) [2009-2014] Pivotal Software, Inc. All Rights Reserved. | ||
* | ||
* This product is licensed to you under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this product except in compliance with the License. | ||
* | ||
* This product includes a number of subcomponents with | ||
* separate copyright notices and license terms. Your use of these | ||
* subcomponents is subject to the terms and conditions of the | ||
* subcomponent's license, as noted in the LICENSE file. | ||
* ****************************************************************************** | ||
*/ | ||
|
||
package org.cloudfoundry.identity.uaa.authentication; | ||
|
||
import org.springframework.security.core.AuthenticationException; | ||
|
||
public class AuthenticationPolicyRejectionException extends AuthenticationException { | ||
public AuthenticationPolicyRejectionException(String msg, Throwable t) { | ||
super(msg, t); | ||
} | ||
|
||
public AuthenticationPolicyRejectionException(String msg) { | ||
super(msg); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
162 changes: 162 additions & 0 deletions
162
...va/org/cloudfoundry/identity/uaa/authentication/manager/ChainedAuthenticationManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
/* | ||
* ****************************************************************************** | ||
* Cloud Foundry | ||
* Copyright (c) [2009-2014] Pivotal Software, Inc. All Rights Reserved. | ||
* | ||
* This product is licensed to you under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this product except in compliance with the License. | ||
* | ||
* This product includes a number of subcomponents with | ||
* separate copyright notices and license terms. Your use of these | ||
* subcomponents is subject to the terms and conditions of the | ||
* subcomponent's license, as noted in the LICENSE file. | ||
* ****************************************************************************** | ||
*/ | ||
|
||
package org.cloudfoundry.identity.uaa.authentication.manager; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.springframework.security.authentication.AuthenticationManager; | ||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.AuthenticationException; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Chained authentication manager that works of simple conditions | ||
*/ | ||
public class ChainedAuthenticationManager implements AuthenticationManager { | ||
public static final String IF_PREVIOUS_FALSE = "ifPreviousFalse"; | ||
public static final String IF_PREVIOUS_TRUE = "ifPreviousTrue"; | ||
|
||
protected final Log logger = LogFactory.getLog(getClass()); | ||
|
||
private AuthenticationManagerConfiguration[] delegates; | ||
|
||
public ChainedAuthenticationManager() { | ||
} | ||
|
||
public AuthenticationManagerConfiguration[] getDelegates() { | ||
return delegates; | ||
} | ||
|
||
public void setDelegates(AuthenticationManagerConfiguration[] delegates) { | ||
this.delegates = delegates; | ||
} | ||
|
||
@Override | ||
public Authentication authenticate(Authentication authentication) throws AuthenticationException { | ||
if (authentication == null) { | ||
return authentication; | ||
} | ||
UsernamePasswordAuthenticationToken output = null; | ||
if (authentication instanceof UsernamePasswordAuthenticationToken) { | ||
output = (UsernamePasswordAuthenticationToken) authentication; | ||
} else { | ||
output = new UsernamePasswordAuthenticationToken(authentication.getPrincipal(), authentication.getCredentials(), | ||
authentication.getAuthorities()); | ||
output.setAuthenticated(authentication.isAuthenticated()); | ||
output.setDetails(authentication.getDetails()); | ||
} | ||
boolean authenticated = false; | ||
Authentication auth = null; | ||
AuthenticationException lastException = null; | ||
boolean lastResult = false; | ||
boolean shallContinue = true; | ||
for (int i=0; shallContinue && i<delegates.length; i++) { | ||
|
||
boolean shallAuthenticate = (i==0) || | ||
(lastResult && IF_PREVIOUS_TRUE.equals(delegates[i].getRequired())) || | ||
((!lastResult) && IF_PREVIOUS_FALSE.equals(delegates[i].getRequired())); | ||
|
||
if (shallAuthenticate) { | ||
if (logger.isDebugEnabled()) { | ||
logger.debug("Attempting chained authentication of " + output + " with manager:" + delegates[i].getAuthenticationManager() + " required:" + delegates[i].getRequired()); | ||
} | ||
Authentication thisAuth = null; | ||
try { | ||
thisAuth = delegates[i].getAuthenticationManager().authenticate(auth!=null ? auth : output); | ||
} catch (AuthenticationException x) { | ||
if (logger.isDebugEnabled()) { | ||
logger.debug("Chained authentication exception:", x); | ||
} | ||
lastException = x; | ||
if (delegates[i].getStopIf()!=null && delegates[i].getStopIf().isAssignableFrom(x.getClass())) { | ||
shallContinue = false; | ||
} | ||
} | ||
lastResult = thisAuth != null && thisAuth.isAuthenticated(); | ||
|
||
if (lastResult) { | ||
authenticated = true; | ||
auth = thisAuth; | ||
} | ||
} else { | ||
lastResult = false; | ||
} | ||
if (logger.isDebugEnabled()) { | ||
logger.debug("Chained Authentication status of "+output+ " with manager:"+delegates[i]+"; Authenticated:"+authenticated); | ||
} | ||
} | ||
if (authenticated) { | ||
return auth; | ||
} else if (lastException!=null) { | ||
//we had at least one authentication exception, throw it | ||
throw lastException; | ||
} else { | ||
//not authenticated, but return the last of the result | ||
return auth; | ||
} | ||
} | ||
|
||
public static class AuthenticationManagerConfiguration { | ||
private AuthenticationManager authenticationManager; | ||
private String required = null; | ||
private Class<? extends AuthenticationException> stopIf; | ||
|
||
public Class<? extends AuthenticationException> getStopIf() { | ||
return stopIf; | ||
} | ||
|
||
public void setStopIf(Class<? extends AuthenticationException> stopIf) { | ||
this.stopIf = stopIf; | ||
} | ||
|
||
public AuthenticationManagerConfiguration() { | ||
} | ||
|
||
public AuthenticationManagerConfiguration(AuthenticationManager authenticationManager, String required) { | ||
this.authenticationManager = authenticationManager; | ||
this.required = required; | ||
} | ||
|
||
public AuthenticationManager getAuthenticationManager() { | ||
return authenticationManager; | ||
} | ||
|
||
public void setAuthenticationManager(AuthenticationManager authenticationManager) { | ||
this.authenticationManager = authenticationManager; | ||
} | ||
|
||
public String getRequired() { | ||
return required; | ||
} | ||
|
||
public void setRequired(String required) { | ||
boolean valid = false; | ||
if (IF_PREVIOUS_FALSE.equals(required) || | ||
IF_PREVIOUS_TRUE.equals(required)) { | ||
valid = true; | ||
} | ||
|
||
if (!valid) { | ||
throw new IllegalArgumentException(required+ " is not a valid value for property 'required'"); | ||
} | ||
|
||
this.required = required; | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.