You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ArchivaXworkUser.java 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package org.apache.maven.archiva.web.util;
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. import com.opensymphony.xwork.ActionContext;
  21. import org.apache.maven.archiva.security.ArchivaRoleConstants;
  22. import org.apache.maven.archiva.security.ArchivaUser;
  23. import org.codehaus.plexus.redback.system.SecuritySession;
  24. import org.codehaus.plexus.redback.users.User;
  25. import java.util.HashMap;
  26. import java.util.Map;
  27. /**
  28. * ArchivaXworkUser
  29. *
  30. * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
  31. * @version $Id$
  32. *
  33. * @plexus.component role="org.apache.maven.archiva.security.ArchivaUser"
  34. * role-hint="xwork"
  35. */
  36. public class ArchivaXworkUser
  37. implements ArchivaUser
  38. {
  39. private Map<String, Object> getContextSession()
  40. {
  41. ActionContext context = ActionContext.getContext();
  42. Map<String, Object> sessionMap = context.getSession();
  43. if ( sessionMap == null )
  44. {
  45. sessionMap = new HashMap<String, Object>();
  46. }
  47. return sessionMap;
  48. }
  49. private SecuritySession getSecuritySession()
  50. {
  51. return (SecuritySession) getContextSession().get( SecuritySession.ROLE );
  52. }
  53. public String getActivePrincipal()
  54. {
  55. SecuritySession securitySession = getSecuritySession();
  56. if ( securitySession == null )
  57. {
  58. return ArchivaRoleConstants.PRINCIPAL_GUEST;
  59. }
  60. User user = securitySession.getUser();
  61. if ( user == null )
  62. {
  63. return ArchivaRoleConstants.PRINCIPAL_GUEST;
  64. }
  65. return (String) user.getPrincipal();
  66. }
  67. }