Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/Evolveum/midpoint
- Loading branch information
Showing
22 changed files
with
941 additions
and
196 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,4 +50,5 @@ | |
<type>UserType</type> | ||
</object> | ||
</authorization> | ||
<delegable>true</delegable> | ||
</role> |
65 changes: 65 additions & 0 deletions
65
...in/java/com/evolveum/midpoint/model/impl/security/MidPointLdapAuthenticationProvider.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,65 @@ | ||
package com.evolveum.midpoint.model.impl.security; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.ldap.core.DirContextOperations; | ||
import org.springframework.security.authentication.BadCredentialsException; | ||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.userdetails.UserDetails; | ||
import org.springframework.security.ldap.authentication.LdapAuthenticationProvider; | ||
import org.springframework.security.ldap.authentication.LdapAuthenticator; | ||
|
||
import com.evolveum.midpoint.schema.constants.SchemaConstants; | ||
import com.evolveum.midpoint.security.api.ConnectionEnvironment; | ||
import com.evolveum.midpoint.security.api.MidPointPrincipal; | ||
import com.evolveum.midpoint.util.logging.Trace; | ||
import com.evolveum.midpoint.util.logging.TraceManager; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType; | ||
|
||
public class MidPointLdapAuthenticationProvider extends LdapAuthenticationProvider{ | ||
|
||
private static final Trace LOGGER = TraceManager.getTrace(MidPointLdapAuthenticationProvider.class); | ||
|
||
@Autowired private SecurityHelper securityHelper; | ||
|
||
public MidPointLdapAuthenticationProvider(LdapAuthenticator authenticator) { | ||
super(authenticator); | ||
} | ||
|
||
|
||
@Override | ||
protected DirContextOperations doAuthentication(UsernamePasswordAuthenticationToken authentication) { | ||
|
||
try { | ||
return super.doAuthentication(authentication); | ||
} catch (RuntimeException e) { | ||
LOGGER.error("Failed to authenticate user {}. Error: {}", authentication.getName(), e.getMessage(), e); | ||
securityHelper.auditLoginFailure(authentication.getName(), null, ConnectionEnvironment.create(SchemaConstants.CHANNEL_GUI_USER_URI), "bad credentials"); | ||
throw e; | ||
} | ||
} | ||
|
||
|
||
@Override | ||
protected Authentication createSuccessfulAuthentication(UsernamePasswordAuthenticationToken authentication, | ||
UserDetails user) { | ||
Authentication authNCtx = super.createSuccessfulAuthentication(authentication, user); | ||
|
||
Object principal = authNCtx.getPrincipal(); | ||
if (!(principal instanceof MidPointPrincipal)) { | ||
throw new BadCredentialsException("LdapAuthentication.incorrect.value"); | ||
} | ||
MidPointPrincipal midPointPrincipal = (MidPointPrincipal) principal; | ||
UserType userType = midPointPrincipal.getUser(); | ||
|
||
if (userType == null) { | ||
throw new BadCredentialsException("LdapAuthentication.bad.user"); | ||
} | ||
|
||
securityHelper.auditLoginSuccess(userType, ConnectionEnvironment.create(SchemaConstants.CHANNEL_GUI_USER_URI)); | ||
return authNCtx; | ||
} | ||
|
||
|
||
|
||
} |
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
Oops, something went wrong.