Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master'
- Loading branch information
Showing
24 changed files
with
537 additions
and
93 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
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
33 changes: 33 additions & 0 deletions
33
model/model-api/src/main/java/com/evolveum/midpoint/model/api/ModelAuditRecorder.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,33 @@ | ||
/* | ||
* Copyright (c) 2010-2017 Evolveum | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.evolveum.midpoint.model.api; | ||
|
||
import com.evolveum.midpoint.security.api.ConnectionEnvironment; | ||
import com.evolveum.midpoint.task.api.Task; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType; | ||
|
||
/** | ||
* Created by Viliam Repan (lazyman). | ||
*/ | ||
public interface ModelAuditRecorder { | ||
|
||
void auditLoginSuccess(UserType user, ConnectionEnvironment connEnv); | ||
|
||
void auditLoginFailure(String username, UserType user, ConnectionEnvironment connEnv, String message); | ||
|
||
void auditLogout(ConnectionEnvironment connEnv, Task task); | ||
} |
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
77 changes: 77 additions & 0 deletions
77
...va/com/evolveum/midpoint/model/api/authentication/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,77 @@ | ||
/* | ||
* Copyright (c) 2010-2017 Evolveum | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.evolveum.midpoint.model.api.authentication; | ||
|
||
import com.evolveum.midpoint.model.api.ModelAuditRecorder; | ||
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; | ||
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; | ||
|
||
public class MidPointLdapAuthenticationProvider extends LdapAuthenticationProvider { | ||
|
||
private static final Trace LOGGER = TraceManager.getTrace(MidPointLdapAuthenticationProvider.class); | ||
|
||
@Autowired | ||
private ModelAuditRecorder auditProvider; | ||
|
||
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); | ||
auditProvider.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"); | ||
} | ||
|
||
auditProvider.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.