Skip to content

Commit 31758ed

Browse files
committed
Fix codestyle/formatting within plugins/userauthenticators/ldap
1 parent 917ea33 commit 31758ed

22 files changed

Lines changed: 1231 additions & 1230 deletions

plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapAddConfigurationCmd.java

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -33,67 +33,67 @@
3333

3434
@APICommand(name = "addLdapConfiguration", description = "Add a new Ldap Configuration", responseObject = LdapConfigurationResponse.class, since = "4.2.0")
3535
public class LdapAddConfigurationCmd extends BaseCmd {
36-
public static final Logger s_logger = Logger
37-
.getLogger(LdapAddConfigurationCmd.class.getName());
38-
private static final String s_name = "ldapconfigurationresponse";
39-
40-
@Inject
41-
private LdapManager _ldapManager;
42-
43-
@Parameter(name = "hostname", type = CommandType.STRING, required = true, description = "Hostname")
44-
private String hostname;
45-
46-
@Parameter(name = "port", type = CommandType.INTEGER, required = true, description = "Port")
47-
private int port;
48-
49-
public LdapAddConfigurationCmd() {
50-
super();
51-
}
52-
53-
public LdapAddConfigurationCmd(final LdapManager ldapManager) {
54-
super();
55-
_ldapManager = ldapManager;
56-
}
57-
58-
@Override
59-
public void execute() throws ServerApiException {
60-
try {
61-
final LdapConfigurationResponse response = _ldapManager
62-
.addConfiguration(hostname, port);
63-
response.setObjectName("LdapAddConfiguration");
64-
response.setResponseName(getCommandName());
65-
setResponseObject(response);
66-
} catch (final InvalidParameterValueException e) {
67-
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,
68-
e.toString());
69-
}
70-
71-
}
72-
73-
@Override
74-
public String getCommandName() {
75-
return s_name;
76-
}
77-
78-
@Override
79-
public long getEntityOwnerId() {
80-
return Account.ACCOUNT_ID_SYSTEM;
81-
}
82-
83-
public String getHostname() {
84-
return hostname;
85-
}
86-
87-
public int getPort() {
88-
return port;
89-
}
90-
91-
public void setHostname(final String hostname) {
92-
this.hostname = hostname;
93-
}
94-
95-
public void setPort(final int port) {
96-
this.port = port;
97-
}
36+
public static final Logger s_logger = Logger
37+
.getLogger(LdapAddConfigurationCmd.class.getName());
38+
private static final String s_name = "ldapconfigurationresponse";
39+
40+
@Inject
41+
private LdapManager _ldapManager;
42+
43+
@Parameter(name = "hostname", type = CommandType.STRING, required = true, description = "Hostname")
44+
private String hostname;
45+
46+
@Parameter(name = "port", type = CommandType.INTEGER, required = true, description = "Port")
47+
private int port;
48+
49+
public LdapAddConfigurationCmd() {
50+
super();
51+
}
52+
53+
public LdapAddConfigurationCmd(final LdapManager ldapManager) {
54+
super();
55+
_ldapManager = ldapManager;
56+
}
57+
58+
@Override
59+
public void execute() throws ServerApiException {
60+
try {
61+
final LdapConfigurationResponse response = _ldapManager
62+
.addConfiguration(hostname, port);
63+
response.setObjectName("LdapAddConfiguration");
64+
response.setResponseName(getCommandName());
65+
setResponseObject(response);
66+
} catch (final InvalidParameterValueException e) {
67+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,
68+
e.toString());
69+
}
70+
71+
}
72+
73+
@Override
74+
public String getCommandName() {
75+
return s_name;
76+
}
77+
78+
@Override
79+
public long getEntityOwnerId() {
80+
return Account.ACCOUNT_ID_SYSTEM;
81+
}
82+
83+
public String getHostname() {
84+
return hostname;
85+
}
86+
87+
public int getPort() {
88+
return port;
89+
}
90+
91+
public void setHostname(final String hostname) {
92+
this.hostname = hostname;
93+
}
94+
95+
public void setPort(final int port) {
96+
this.port = port;
97+
}
9898

9999
}

plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapCreateAccountCmd.java

Lines changed: 121 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -43,125 +43,125 @@
4343

4444
@APICommand(name = "ldapCreateAccount", description = "Creates an account from an LDAP user", responseObject = AccountResponse.class, since = "4.2.0")
4545
public class LdapCreateAccountCmd extends BaseCmd {
46-
public static final Logger s_logger = Logger
47-
.getLogger(LdapCreateAccountCmd.class.getName());
48-
private static final String s_name = "createaccountresponse";
49-
50-
@Inject
51-
private LdapManager _ldapManager;
52-
53-
@Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "Creates the user under the specified account. If no account is specified, the username will be used as the account name.")
54-
private String accountName;
55-
56-
@Parameter(name = ApiConstants.ACCOUNT_TYPE, type = CommandType.SHORT, required = true, description = "Type of the account. Specify 0 for user, 1 for root admin, and 2 for domain admin")
57-
private Short accountType;
58-
59-
@Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, entityType = DomainResponse.class, description = "Creates the user under the specified domain.")
60-
private Long domainId;
61-
62-
@Parameter(name = ApiConstants.TIMEZONE, type = CommandType.STRING, description = "Specifies a timezone for this command. For more information on the timezone parameter, see Time Zone Format.")
63-
private String timezone;
64-
65-
@Parameter(name = ApiConstants.USERNAME, type = CommandType.STRING, required = true, description = "Unique username.")
66-
private String username;
67-
68-
@Parameter(name = ApiConstants.NETWORK_DOMAIN, type = CommandType.STRING, description = "Network domain for the account's networks")
69-
private String networkDomain;
70-
71-
@Parameter(name = ApiConstants.ACCOUNT_DETAILS, type = CommandType.MAP, description = "details for account used to store specific parameters")
72-
private Map<String, String> details;
73-
74-
@Parameter(name = ApiConstants.ACCOUNT_ID, type = CommandType.STRING, description = "Account UUID, required for adding account from external provisioning system")
75-
private String accountUUID;
76-
77-
@Parameter(name = ApiConstants.USER_ID, type = CommandType.STRING, description = "User UUID, required for adding account from external provisioning system")
78-
private String userUUID;
79-
80-
public LdapCreateAccountCmd() {
81-
super();
82-
}
83-
84-
public LdapCreateAccountCmd(final LdapManager ldapManager,
85-
final AccountService accountService) {
86-
super();
87-
_ldapManager = ldapManager;
88-
_accountService = accountService;
89-
}
90-
91-
UserAccount createCloudstackUserAccount(final LdapUser user) {
92-
return _accountService.createUserAccount(username, generatePassword(),
93-
user.getFirstname(), user.getLastname(), user.getEmail(),
94-
timezone, accountName, accountType, domainId, networkDomain,
95-
details, accountUUID, userUUID);
96-
}
97-
98-
@Override
99-
public void execute() throws ServerApiException {
100-
final CallContext callContext = getCurrentContext();
101-
callContext.setEventDetails("Account Name: " + accountName
102-
+ ", Domain Id:" + domainId);
103-
try {
104-
final LdapUser user = _ldapManager.getUser(username);
105-
validateUser(user);
106-
final UserAccount userAccount = createCloudstackUserAccount(user);
107-
if (userAccount != null) {
108-
final AccountResponse response = _responseGenerator
109-
.createUserAccountResponse(userAccount);
110-
response.setResponseName(getCommandName());
111-
setResponseObject(response);
112-
} else {
113-
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,
114-
"Failed to create a user account");
115-
}
116-
} catch (final NamingException e) {
117-
throw new ServerApiException(
118-
ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR,
119-
"No LDAP user exists with the username of " + username);
120-
}
121-
}
122-
123-
private String generatePassword() throws ServerApiException {
124-
try {
125-
final SecureRandom randomGen = SecureRandom.getInstance("SHA1PRNG");
126-
final byte bytes[] = new byte[20];
127-
randomGen.nextBytes(bytes);
128-
return Base64.encode(bytes).toString();
129-
} catch (final NoSuchAlgorithmException e) {
130-
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,
131-
"Failed to generate random password");
132-
}
133-
}
134-
135-
@Override
136-
public String getCommandName() {
137-
return s_name;
138-
}
139-
140-
CallContext getCurrentContext() {
141-
return CallContext.current();
142-
}
143-
144-
@Override
145-
public long getEntityOwnerId() {
146-
return Account.ACCOUNT_ID_SYSTEM;
147-
}
148-
149-
private boolean validateUser(final LdapUser user) throws ServerApiException {
150-
if (user.getEmail() == null) {
151-
throw new ServerApiException(
152-
ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, username
153-
+ " has no email address set within LDAP");
154-
}
155-
if (user.getFirstname() == null) {
156-
throw new ServerApiException(
157-
ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, username
158-
+ " has no firstname set within LDAP");
159-
}
160-
if (user.getLastname() == null) {
161-
throw new ServerApiException(
162-
ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, username
163-
+ " has no lastname set within LDAP");
164-
}
165-
return true;
166-
}
46+
public static final Logger s_logger = Logger
47+
.getLogger(LdapCreateAccountCmd.class.getName());
48+
private static final String s_name = "createaccountresponse";
49+
50+
@Inject
51+
private LdapManager _ldapManager;
52+
53+
@Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "Creates the user under the specified account. If no account is specified, the username will be used as the account name.")
54+
private String accountName;
55+
56+
@Parameter(name = ApiConstants.ACCOUNT_TYPE, type = CommandType.SHORT, required = true, description = "Type of the account. Specify 0 for user, 1 for root admin, and 2 for domain admin")
57+
private Short accountType;
58+
59+
@Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, entityType = DomainResponse.class, description = "Creates the user under the specified domain.")
60+
private Long domainId;
61+
62+
@Parameter(name = ApiConstants.TIMEZONE, type = CommandType.STRING, description = "Specifies a timezone for this command. For more information on the timezone parameter, see Time Zone Format.")
63+
private String timezone;
64+
65+
@Parameter(name = ApiConstants.USERNAME, type = CommandType.STRING, required = true, description = "Unique username.")
66+
private String username;
67+
68+
@Parameter(name = ApiConstants.NETWORK_DOMAIN, type = CommandType.STRING, description = "Network domain for the account's networks")
69+
private String networkDomain;
70+
71+
@Parameter(name = ApiConstants.ACCOUNT_DETAILS, type = CommandType.MAP, description = "details for account used to store specific parameters")
72+
private Map<String, String> details;
73+
74+
@Parameter(name = ApiConstants.ACCOUNT_ID, type = CommandType.STRING, description = "Account UUID, required for adding account from external provisioning system")
75+
private String accountUUID;
76+
77+
@Parameter(name = ApiConstants.USER_ID, type = CommandType.STRING, description = "User UUID, required for adding account from external provisioning system")
78+
private String userUUID;
79+
80+
public LdapCreateAccountCmd() {
81+
super();
82+
}
83+
84+
public LdapCreateAccountCmd(final LdapManager ldapManager,
85+
final AccountService accountService) {
86+
super();
87+
_ldapManager = ldapManager;
88+
_accountService = accountService;
89+
}
90+
91+
UserAccount createCloudstackUserAccount(final LdapUser user) {
92+
return _accountService.createUserAccount(username, generatePassword(),
93+
user.getFirstname(), user.getLastname(), user.getEmail(),
94+
timezone, accountName, accountType, domainId, networkDomain,
95+
details, accountUUID, userUUID);
96+
}
97+
98+
@Override
99+
public void execute() throws ServerApiException {
100+
final CallContext callContext = getCurrentContext();
101+
callContext.setEventDetails("Account Name: " + accountName
102+
+ ", Domain Id:" + domainId);
103+
try {
104+
final LdapUser user = _ldapManager.getUser(username);
105+
validateUser(user);
106+
final UserAccount userAccount = createCloudstackUserAccount(user);
107+
if (userAccount != null) {
108+
final AccountResponse response = _responseGenerator
109+
.createUserAccountResponse(userAccount);
110+
response.setResponseName(getCommandName());
111+
setResponseObject(response);
112+
} else {
113+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,
114+
"Failed to create a user account");
115+
}
116+
} catch (final NamingException e) {
117+
throw new ServerApiException(
118+
ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR,
119+
"No LDAP user exists with the username of " + username);
120+
}
121+
}
122+
123+
private String generatePassword() throws ServerApiException {
124+
try {
125+
final SecureRandom randomGen = SecureRandom.getInstance("SHA1PRNG");
126+
final byte bytes[] = new byte[20];
127+
randomGen.nextBytes(bytes);
128+
return Base64.encode(bytes).toString();
129+
} catch (final NoSuchAlgorithmException e) {
130+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,
131+
"Failed to generate random password");
132+
}
133+
}
134+
135+
@Override
136+
public String getCommandName() {
137+
return s_name;
138+
}
139+
140+
CallContext getCurrentContext() {
141+
return CallContext.current();
142+
}
143+
144+
@Override
145+
public long getEntityOwnerId() {
146+
return Account.ACCOUNT_ID_SYSTEM;
147+
}
148+
149+
private boolean validateUser(final LdapUser user) throws ServerApiException {
150+
if (user.getEmail() == null) {
151+
throw new ServerApiException(
152+
ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, username
153+
+ " has no email address set within LDAP");
154+
}
155+
if (user.getFirstname() == null) {
156+
throw new ServerApiException(
157+
ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, username
158+
+ " has no firstname set within LDAP");
159+
}
160+
if (user.getLastname() == null) {
161+
throw new ServerApiException(
162+
ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, username
163+
+ " has no lastname set within LDAP");
164+
}
165+
return true;
166+
}
167167
}

0 commit comments

Comments
 (0)