Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'stable' of github.com:abiquo/abiquo into ABICLOUDPREMIU…
…M-3550-StatisticsVMachinesNotAllocated
- Loading branch information
Showing
84 changed files
with
2,058 additions
and
625 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
143 changes: 76 additions & 67 deletions
143
api/src/main/java/com/abiquo/api/exceptions/APIError.java
Large diffs are not rendered by default.
Oops, something went wrong.
90 changes: 90 additions & 0 deletions
90
api/src/main/java/com/abiquo/api/handlers/AdminEnterpriseSecurityRequestHandler.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,90 @@ | ||
/** | ||
* Abiquo community edition | ||
* cloud management application for hybrid clouds | ||
* Copyright (C) 2008-2010 - Abiquo Holdings S.L. | ||
* | ||
* This application is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU LESSER GENERAL PUBLIC | ||
* LICENSE as published by the Free Software Foundation under | ||
* version 3 of the License | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* LESSER GENERAL PUBLIC LICENSE v.3 for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, write to the | ||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
* Boston, MA 02111-1307, USA. | ||
*/ | ||
|
||
package com.abiquo.api.handlers; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import org.apache.wink.server.handlers.HandlersChain; | ||
import org.apache.wink.server.handlers.MessageContext; | ||
import org.springframework.security.AccessDeniedException; | ||
|
||
import com.abiquo.api.resources.EnterprisesResource; | ||
|
||
/** | ||
* Request handler to check permissions of the logged user to use the requested virtual datacenter. | ||
* This means that all request to uris who depend on "cloud/virtualdatacenters/{id}" will be checked | ||
* by this handler. | ||
* | ||
* @author scastro | ||
*/ | ||
public class AdminEnterpriseSecurityRequestHandler extends SecurityPathRequestHandler | ||
{ | ||
|
||
/** | ||
* in this case must be a <code>\w</code> and not a <code>\d</code> | ||
*/ | ||
private static String ENTERPRISE_ID_REGEX = EnterprisesResource.ENTERPRISES_PATH + "/(\\w+)"; | ||
|
||
private static String ENTERPRISES_PATH_REGEX = ENTERPRISE_ID_REGEX + "[/]?.*$"; | ||
|
||
@Override | ||
public boolean matches(final String path) | ||
{ | ||
return path.matches(ENTERPRISES_PATH_REGEX); | ||
} | ||
|
||
@Override | ||
public void handleRequest(final MessageContext context, final HandlersChain chain) | ||
throws Throwable | ||
{ | ||
// check if path maches with 'admin/enterprises/{id}*' | ||
String path = context.getUriInfo().getPath(); | ||
// 1. get user from context [userName, authType, privileges list] | ||
Object[] userprorps = getCurrentLoginInfo(); | ||
|
||
// 3. get enterprise id from path | ||
Pattern p = Pattern.compile(ENTERPRISE_ID_REGEX); | ||
Matcher m = p.matcher(path); | ||
// matcher ALLWAYS must find the enterprise id in the second group (remember that group 0 is | ||
// the original string) | ||
m.find(); | ||
String gr = m.group(1); | ||
if (!gr.equals("_")) | ||
{ | ||
Integer idEnt = new Integer(gr); | ||
|
||
boolean isAllowed = | ||
getUserService().isUserAllowedToEnterprise((String) userprorps[0], | ||
(String) userprorps[1], (String[]) userprorps[2], idEnt); | ||
|
||
if (!isAllowed) | ||
{ | ||
// throw forbidden if is not allowed | ||
throw new AccessDeniedException("Missing privilege to get info from other enterprises"); | ||
} | ||
} | ||
|
||
// finally | ||
chain.doChain(context); | ||
} | ||
} |
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.