This repository has been archived by the owner on Apr 8, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Delegate 'authorization' to to extensions and remove @RolesAllowed fr…
…om RestController so unauthenticated access is allowed
- Loading branch information
Showing
15 changed files
with
222 additions
and
131 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
38 changes: 38 additions & 0 deletions
38
api/src/main/java/org/gatein/management/api/exceptions/NotAuthorizedException.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,38 @@ | ||
package org.gatein.management.api.exceptions; | ||
|
||
import org.gatein.management.api.ManagedUser; | ||
|
||
/** | ||
* @author <a href="mailto:nscavell@redhat.com">Nick Scavelli</a> | ||
*/ | ||
public class NotAuthorizedException extends OperationException | ||
{ | ||
private final ManagedUser user; | ||
|
||
public NotAuthorizedException(ManagedUser user, String operationName) | ||
{ | ||
super(operationName, createMessage(user, operationName)); | ||
this.user = user; | ||
} | ||
|
||
public NotAuthorizedException(ManagedUser user, String operationName, Throwable cause) | ||
{ | ||
super(operationName, createMessage(user, operationName), cause); | ||
this.user = user; | ||
} | ||
|
||
public ManagedUser getUser() | ||
{ | ||
return user; | ||
} | ||
|
||
private static String createMessage(ManagedUser user, String operationName) | ||
{ | ||
if (user == null) | ||
{ | ||
return "Authentication required for operation " + operationName; | ||
} | ||
|
||
return user.getUserName() + " is not authorized to execute operation " + operationName; | ||
} | ||
} |
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
62 changes: 62 additions & 0 deletions
62
cli/src/main/java/org/gatein/management/cli/crash/plugins/CustomWebPluginLifecycle.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,62 @@ | ||
package org.gatein.management.cli.crash.plugins; | ||
|
||
import org.crsh.plugin.WebPluginLifeCycle; | ||
import org.gatein.common.logging.Logger; | ||
import org.gatein.common.logging.LoggerFactory; | ||
|
||
import javax.servlet.ServletContextEvent; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Properties; | ||
|
||
/** | ||
* Used to bootstrap crash and also provide access to crash.properties data. | ||
* | ||
* @author <a href="mailto:nscavell@redhat.com">Nick Scavelli</a> | ||
*/ | ||
public class CustomWebPluginLifecycle extends WebPluginLifeCycle | ||
{ | ||
private static final Properties crashProperties = new Properties(); | ||
private static final Logger log = LoggerFactory.getLogger(CustomWebPluginLifecycle.class); | ||
|
||
public static Properties getCrashProperties() | ||
{ | ||
return crashProperties; | ||
} | ||
|
||
@Override | ||
public void contextInitialized(ServletContextEvent sce) | ||
{ | ||
super.contextInitialized(sce); | ||
String path = "/WEB-INF/crash/crash.properties"; | ||
InputStream in = sce.getServletContext().getResourceAsStream(path); | ||
try | ||
{ | ||
crashProperties.load(in); | ||
} | ||
catch (IOException e) | ||
{ | ||
log.error("Exception reading file " + path, e); | ||
} | ||
finally | ||
{ | ||
if (in != null) | ||
{ | ||
try | ||
{ | ||
in.close(); | ||
} | ||
catch (IOException e) | ||
{ | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void contextDestroyed(ServletContextEvent sce) | ||
{ | ||
super.contextDestroyed(sce); | ||
crashProperties.clear(); | ||
} | ||
} |
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.