Skip to content

Commit 3ceb8d5

Browse files
Murali reddyMurali reddy
authored andcommitted
moving out plaintext authenticator to plugins/user-authenticators
1 parent eb5e02e commit 3ceb8d5

5 files changed

Lines changed: 252 additions & 91 deletions

File tree

build/build-cloud-plugins.xml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,19 +236,25 @@
236236

237237
<!-- ===================== User Authenticators ================== -->
238238

239-
<target name="compile-user-authenticators" depends="compile-user-authenticator-ldap, compile-user-authenticator-md5" description="Compile all user authenicators"/>
240-
<target name="build-user-authenticators" depends="build-user-authenticator-ldap, build-user-authenticator-md5" description="builds all user authenticators"/>
239+
<target name="compile-user-authenticators" depends="compile-user-authenticator-ldap, compile-user-authenticator-md5, compile-user-authenticator-plaintext" description="Compile all user authenicators"/>
240+
<target name="build-user-authenticators" depends="build-user-authenticator-ldap, build-user-authenticator-md5, build-user-authenticator-plaintext" description="builds all user authenticators"/>
241241

242-
<target name="compile-user-authenticator-ldap" depends="-init, compile-server" description="Compile ">
242+
<target name="compile-user-authenticator-ldap" depends="-init, compile-server" description="Compiles LDAP user authenticator">
243243
<ant antfile="${base.dir}/plugins/user-authenticators/ldap/build.xml" target="build"/>
244244
</target>
245245
<target name="build-user-authenticator-ldap" depends="compile-user-authenticator-ldap" />
246246

247-
<target name="compile-user-authenticator-md5" depends="-init, compile-server" description="Compile ">
247+
<target name="compile-user-authenticator-md5" depends="-init, compile-server" description="Compiles MD5 user authenticator">
248248
<ant antfile="${base.dir}/plugins/user-authenticators/md5/build.xml" target="build"/>
249249
</target>
250250
<target name="build-user-authenticator-md5" depends="compile-user-authenticator-md5" />
251251

252+
<target name="compile-user-authenticator-plaintext" depends="-init, compile-server" description="Compiles plaintext user authenticator">
253+
<ant antfile="${base.dir}/plugins/user-authenticators/plain-text/build.xml" target="build"/>
254+
</target>
255+
<target name="build-user-authenticator-plaintext" depends="compile-user-authenticator-plaintext" />
256+
257+
252258
<!-- ===================== Network Elements ===================== -->
253259

254260
<target name="compile-network-elements" depends="compile-netscaler, compile-f5, compile-srx" description="Compile all network elements"/>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
5+
<classpathentry combineaccessrules="false" kind="src" path="/api"/>
6+
<classpathentry combineaccessrules="false" kind="src" path="/core"/>
7+
<classpathentry combineaccessrules="false" kind="src" path="/server"/>
8+
<classpathentry combineaccessrules="false" kind="src" path="/utils"/>
9+
<classpathentry kind="output" path="bin"/>
10+
</classpath>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>plaintext-user-authenticator</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to You under the Apache License, Version 2.0
7+
(the "License"); you may not use this file except in compliance with
8+
the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
19+
20+
<project name="Cloud Stack LDAP User Authenticator" default="help" basedir=".">
21+
<description>
22+
Cloud Stack ant build file
23+
</description>
24+
25+
<dirname property="user-authenticator-plaintext.base.dir" file="${ant.file.Cloud Stack LDAP User Authenticator}/"/>
26+
<!-- This directory must be set -->
27+
<property name="top.dir" location="${user-authenticator-plaintext.base.dir}/../../.."/>
28+
<property name="build.dir" location="${top.dir}/build"/>
29+
30+
<echo message="build.dir=${build.dir}; top.dir=${top.dir}; user-authenticator-plaintext.base.dir=${user-authenticator-plaintext.base.dir}"/>
31+
32+
<!-- Import anything that the user wants to set-->
33+
<!-- Import properties files and environment variables here -->
34+
35+
<property environment="env" />
36+
37+
<condition property="build-cloud.properties.file" value="${build.dir}/override/build-cloud.properties" else="${build.dir}/build-cloud.properties">
38+
<available file="${build.dir}/override/build-cloud.properties" />
39+
</condition>
40+
41+
<condition property="cloud.properties.file" value="${build.dir}/override/cloud.properties" else="${build.dir}/cloud.properties">
42+
<available file="${build.dir}/override/cloud.properties" />
43+
</condition>
44+
45+
<condition property="override.file" value="${build.dir}/override/replace.properties" else="${build.dir}/replace.properties">
46+
<available file="${build.dir}/override/replace.properties" />
47+
</condition>
48+
49+
<echo message="Using build parameters from ${build-cloud.properties.file}" />
50+
<property file="${build-cloud.properties.file}" />
51+
52+
<echo message="Using company info from ${cloud.properties.file}" />
53+
<property file="${cloud.properties.file}" />
54+
55+
<echo message="Using override file from ${override.file}" />
56+
<property file="${override.file}" />
57+
58+
<property file="${build.dir}/build.number" />
59+
60+
<!-- In case these didn't get defined in the build-cloud.properties -->
61+
<property name="branding.name" value="default" />
62+
<property name="deprecation" value="off" />
63+
<property name="target.compat.version" value="1.6" />
64+
<property name="source.compat.version" value="1.6" />
65+
<property name="debug" value="true" />
66+
<property name="debuglevel" value="lines,source"/>
67+
68+
<echo message="target.dir=${target.dir}; top.dir=${top.dir}"/>
69+
<!-- directories for build and distribution -->
70+
<property name="target.dir" location="${top.dir}/target" />
71+
<property name="classes.dir" location="${target.dir}/classes" />
72+
<property name="jar.dir" location="${target.dir}/jar" />
73+
<property name="dep.cache.dir" location="${target.dir}/dep-cache" />
74+
<property name="build.log" location="${target.dir}/ant_verbose.txt" />
75+
76+
<property name="deps.dir" location="${top.dir}/deps" />
77+
78+
<property name="user-authenticator-plaintext.jar" value="cloud-user-authenticator-plaintext.jar" />
79+
<property name="user-authenticator-plaintext-scripts.dir" location="${user-authenticator-plaintext.base.dir}/scripts" />
80+
81+
<import file="${build.dir}/build-common.xml"/>
82+
83+
<echo message="target.dir=${target.dir}; top.dir=${top.dir}"/>
84+
85+
<!-- This section needs to be replaced by some kind of dependency library-->
86+
<path id="deps.classpath">
87+
<!--filelist files="${deps.classpath}" /-->
88+
<fileset dir="${deps.dir}" erroronmissingdir="false">
89+
<include name="*.jar" />
90+
</fileset>
91+
</path>
92+
93+
<path id="cloudstack.classpath">
94+
<fileset dir="${jar.dir}">
95+
<include name="*.jar"/>
96+
</fileset>
97+
</path>
98+
99+
<path id="user-authenticator-plaintext.classpath">
100+
<path refid="deps.classpath"/>
101+
<path refid="cloudstack.classpath"/>
102+
</path>
103+
104+
<!-- This section needs to be replaced by some kind of dependency library-->
105+
106+
107+
<target name="init" description="Initialize binaries directory">
108+
<mkdir dir="${classes.dir}/${user-authenticator-plaintext.jar}"/>
109+
<mkdir dir="${jar.dir}"/>
110+
</target>
111+
112+
<target name="compile-user-authenticator-plaintext" depends="init" description="Compile user-authenticator-plaintext">
113+
<compile-java jar.name="${user-authenticator-plaintext.jar}" top.dir="${user-authenticator-plaintext.base.dir}" classpath="user-authenticator-plaintext.classpath" />
114+
</target>
115+
116+
<target name="help" description="help">
117+
<echo level="info" message="This is the build file for user-authenticator-plaintext"/>
118+
<echo level="info" message="You can do a build by doing ant build or clean by ant clean" />
119+
</target>
120+
121+
<target name="clean-user-authenticator-plaintext">
122+
<delete dir="${classes.dir}/${user-authenticator-plaintext.jar}"/>
123+
</target>
124+
125+
<target name="build" depends="compile-user-authenticator-plaintext"/>
126+
<target name="clean" depends="clean-user-authenticator-plaintext"/>
127+
128+
</project>

server/src/com/cloud/server/auth/PlainTextUserAuthenticator.java renamed to plugins/user-authenticators/plain-text/src/com/cloud/server/auth/PlainTextUserAuthenticator.java

Lines changed: 87 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,87 @@
1-
// Copyright 2012 Citrix Systems, Inc. Licensed under the
2-
// Apache License, Version 2.0 (the "License"); you may not use this
3-
// file except in compliance with the License. Citrix Systems, Inc.
4-
// reserves all rights not expressly granted by the License.
5-
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6-
// Unless required by applicable law or agreed to in writing, software
7-
// distributed under the License is distributed on an "AS IS" BASIS,
8-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9-
// See the License for the specific language governing permissions and
10-
// limitations under the License.
11-
//
12-
// Automatically generated by addcopyright.py at 04/03/2012
13-
package com.cloud.server.auth;
14-
15-
import java.math.BigInteger;
16-
import java.security.MessageDigest;
17-
import java.security.NoSuchAlgorithmException;
18-
import java.util.Map;
19-
20-
import javax.ejb.Local;
21-
import javax.naming.ConfigurationException;
22-
23-
import org.apache.log4j.Logger;
24-
25-
import com.cloud.server.ManagementServer;
26-
import com.cloud.user.UserAccount;
27-
import com.cloud.user.dao.UserAccountDao;
28-
import com.cloud.utils.component.ComponentLocator;
29-
import com.cloud.utils.exception.CloudRuntimeException;
30-
31-
32-
@Local(value={UserAuthenticator.class})
33-
public class PlainTextUserAuthenticator extends DefaultUserAuthenticator {
34-
public static final Logger s_logger = Logger.getLogger(PlainTextUserAuthenticator.class);
35-
36-
private UserAccountDao _userAccountDao;
37-
38-
@Override
39-
public boolean authenticate(String username, String password, Long domainId, Map<String, Object[]> requestParameters ) {
40-
if (s_logger.isDebugEnabled()) {
41-
s_logger.debug("Retrieving user: " + username);
42-
}
43-
UserAccount user = _userAccountDao.getUserAccount(username, domainId);
44-
if (user == null) {
45-
s_logger.debug("Unable to find user with " + username + " in domain " + domainId);
46-
return false;
47-
}
48-
49-
50-
MessageDigest md5;
51-
try {
52-
md5 = MessageDigest.getInstance("MD5");
53-
} catch (NoSuchAlgorithmException e) {
54-
throw new CloudRuntimeException("Error", e);
55-
}
56-
md5.reset();
57-
BigInteger pwInt = new BigInteger(1, md5.digest(password.getBytes()));
58-
59-
// make sure our MD5 hash value is 32 digits long...
60-
StringBuffer sb = new StringBuffer();
61-
String pwStr = pwInt.toString(16);
62-
int padding = 32 - pwStr.length();
63-
for (int i = 0; i < padding; i++) {
64-
sb.append('0');
65-
}
66-
sb.append(pwStr);
67-
68-
69-
// Will: The MD5Authenticator is now a straight pass-through comparison of the
70-
// the passwords because we will not assume that the password passed in has
71-
// already been MD5 hashed. I am keeping the above code in case this requirement changes
72-
// or people need examples of how to MD5 hash passwords in java.
73-
if (!user.getPassword().equals(sb.toString())) {
74-
s_logger.debug("Password does not match");
75-
return false;
76-
}
77-
return true;
78-
}
79-
80-
public boolean configure(String name, Map<String, Object> params)
81-
throws ConfigurationException {
82-
super.configure(name, params);
83-
ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name);
84-
_userAccountDao = locator.getDao(UserAccountDao.class);
85-
return true;
86-
}
87-
}
1+
// Copyright 2012 Citrix Systems, Inc. Licensed under the
2+
// Apache License, Version 2.0 (the "License"); you may not use this
3+
// file except in compliance with the License. Citrix Systems, Inc.
4+
// reserves all rights not expressly granted by the License.
5+
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
// Unless required by applicable law or agreed to in writing, software
7+
// distributed under the License is distributed on an "AS IS" BASIS,
8+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
// See the License for the specific language governing permissions and
10+
// limitations under the License.
11+
//
12+
// Automatically generated by addcopyright.py at 04/03/2012
13+
package com.cloud.server.auth;
14+
15+
import java.math.BigInteger;
16+
import java.security.MessageDigest;
17+
import java.security.NoSuchAlgorithmException;
18+
import java.util.Map;
19+
20+
import javax.ejb.Local;
21+
import javax.naming.ConfigurationException;
22+
23+
import org.apache.log4j.Logger;
24+
25+
import com.cloud.server.ManagementServer;
26+
import com.cloud.user.UserAccount;
27+
import com.cloud.user.dao.UserAccountDao;
28+
import com.cloud.utils.component.ComponentLocator;
29+
import com.cloud.utils.exception.CloudRuntimeException;
30+
31+
32+
@Local(value={UserAuthenticator.class})
33+
public class PlainTextUserAuthenticator extends DefaultUserAuthenticator {
34+
public static final Logger s_logger = Logger.getLogger(PlainTextUserAuthenticator.class);
35+
36+
private UserAccountDao _userAccountDao;
37+
38+
@Override
39+
public boolean authenticate(String username, String password, Long domainId, Map<String, Object[]> requestParameters ) {
40+
if (s_logger.isDebugEnabled()) {
41+
s_logger.debug("Retrieving user: " + username);
42+
}
43+
UserAccount user = _userAccountDao.getUserAccount(username, domainId);
44+
if (user == null) {
45+
s_logger.debug("Unable to find user with " + username + " in domain " + domainId);
46+
return false;
47+
}
48+
49+
50+
MessageDigest md5;
51+
try {
52+
md5 = MessageDigest.getInstance("MD5");
53+
} catch (NoSuchAlgorithmException e) {
54+
throw new CloudRuntimeException("Error", e);
55+
}
56+
md5.reset();
57+
BigInteger pwInt = new BigInteger(1, md5.digest(password.getBytes()));
58+
59+
// make sure our MD5 hash value is 32 digits long...
60+
StringBuffer sb = new StringBuffer();
61+
String pwStr = pwInt.toString(16);
62+
int padding = 32 - pwStr.length();
63+
for (int i = 0; i < padding; i++) {
64+
sb.append('0');
65+
}
66+
sb.append(pwStr);
67+
68+
69+
// Will: The MD5Authenticator is now a straight pass-through comparison of the
70+
// the passwords because we will not assume that the password passed in has
71+
// already been MD5 hashed. I am keeping the above code in case this requirement changes
72+
// or people need examples of how to MD5 hash passwords in java.
73+
if (!user.getPassword().equals(sb.toString())) {
74+
s_logger.debug("Password does not match");
75+
return false;
76+
}
77+
return true;
78+
}
79+
80+
public boolean configure(String name, Map<String, Object> params)
81+
throws ConfigurationException {
82+
super.configure(name, params);
83+
ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name);
84+
_userAccountDao = locator.getDao(UserAccountDao.class);
85+
return true;
86+
}
87+
}

0 commit comments

Comments
 (0)