| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
package org.itracker.services.authentication.adsson; |
| 5 |
|
|
| 6 |
|
import java.io.IOException; |
| 7 |
|
import java.io.InputStream; |
| 8 |
|
import java.security.AccessControlException; |
| 9 |
|
import java.util.Properties; |
| 10 |
|
|
| 11 |
|
import javax.security.auth.Subject; |
| 12 |
|
import javax.security.auth.login.LoginContext; |
| 13 |
|
import javax.security.auth.login.LoginException; |
| 14 |
|
|
| 15 |
|
import org.apache.log4j.Logger; |
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
@author |
| 21 |
|
|
|
|
|
| 0% |
Uncovered Elements: 32 (32) |
Complexity: 10 |
Complexity Density: 0.48 |
|
| 22 |
|
public class ADIntegration { |
| 23 |
|
|
| 24 |
|
private static final String AD_AUTH_PROPERTIES_FILE = "adauth.properties"; |
| 25 |
|
private static final String PASSWORD = "password"; |
| 26 |
|
private static final String USERNAME = "username"; |
| 27 |
|
private static final String BASE_BRANCH = "basebranch"; |
| 28 |
|
private static final String PROVIDER_URL = "url"; |
| 29 |
|
|
| 30 |
|
private final Logger logger; |
| 31 |
|
private LoginContext lc = null; |
| 32 |
|
private Properties adAuth; |
| 33 |
|
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
| 34 |
0
|
public ADIntegration() throws IOException {... |
| 35 |
0
|
this.logger = Logger.getLogger(getClass()); |
| 36 |
0
|
adAuth = new Properties(); |
| 37 |
0
|
InputStream is = getClass().getResourceAsStream( "/" + AD_AUTH_PROPERTIES_FILE); |
| 38 |
0
|
if( is == null) { |
| 39 |
0
|
String message = "Can't find " + AD_AUTH_PROPERTIES_FILE + " to get A.D. auth properties. This file should be in the root of your classpath or EAR file"; |
| 40 |
0
|
logger.error( message ); |
| 41 |
0
|
throw new IOException( message ); |
| 42 |
|
} |
| 43 |
0
|
adAuth.load( is ); |
| 44 |
|
} |
| 45 |
|
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 46 |
0
|
public void login() throws LoginException {... |
| 47 |
0
|
try { |
| 48 |
|
|
| 49 |
|
|
| 50 |
0
|
lc = new LoginContext("Helpdesk", new SimpleCallbackHandler( getUsername(), getPassword() ) ); |
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 |
0
|
lc.login(); |
| 55 |
|
} catch (IOException e) { |
| 56 |
0
|
throw new LoginException( e.getMessage() ); |
| 57 |
|
} |
| 58 |
|
} |
| 59 |
|
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 60 |
0
|
public Object getUserInfo(String login) throws AccessControlException {... |
| 61 |
|
|
| 62 |
0
|
Object userInfo = Subject.doAs(lc.getSubject(), new GetUserModelFromADPrivilegedAction( login, getBaseBranch(), getProviderUrl() )); |
| 63 |
|
|
| 64 |
0
|
if( userInfo == null ) { |
| 65 |
0
|
logger.error("Can't get info on " + login + " from A.D."); |
| 66 |
0
|
throw new AccessControlException("Can't get info on " + login + " from A.D."); |
| 67 |
|
} |
| 68 |
|
|
| 69 |
0
|
return( userInfo ); |
| 70 |
|
} |
| 71 |
|
|
| 72 |
|
|
| 73 |
|
@return |
| 74 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 75 |
0
|
private String getProviderUrl() {... |
| 76 |
0
|
return( adAuth.getProperty( PROVIDER_URL ) ); |
| 77 |
|
} |
| 78 |
|
|
| 79 |
|
|
| 80 |
|
@return |
| 81 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 82 |
0
|
private String getPassword() throws IOException {... |
| 83 |
0
|
return( adAuth.getProperty( PASSWORD ) ); |
| 84 |
|
} |
| 85 |
|
|
| 86 |
|
|
| 87 |
|
@return |
| 88 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 89 |
0
|
private String getUsername() throws IOException {... |
| 90 |
0
|
return( adAuth.getProperty( USERNAME ) ); |
| 91 |
|
} |
| 92 |
|
|
| 93 |
|
|
| 94 |
|
@return |
| 95 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 96 |
0
|
private String getBaseBranch() {... |
| 97 |
0
|
return( adAuth.getProperty( BASE_BRANCH ) ); |
| 98 |
|
} |
| 99 |
|
} |