PwmRequest.java 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. /*
  2. * Password Management Servlets (PWM)
  3. * http://www.pwm-project.org
  4. *
  5. * Copyright (c) 2006-2009 Novell, Inc.
  6. * Copyright (c) 2009-2020 The PWM Project
  7. *
  8. * Licensed under the Apache License, Version 2.0 (the "License");
  9. * you may not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. */
  20. package password.pwm.http;
  21. import lombok.Value;
  22. import org.apache.commons.fileupload.FileItemIterator;
  23. import org.apache.commons.fileupload.FileItemStream;
  24. import org.apache.commons.fileupload.servlet.ServletFileUpload;
  25. import org.apache.commons.io.IOUtils;
  26. import password.pwm.AppProperty;
  27. import password.pwm.PwmApplication;
  28. import password.pwm.PwmApplicationMode;
  29. import password.pwm.PwmConstants;
  30. import password.pwm.PwmDomain;
  31. import password.pwm.bean.DomainID;
  32. import password.pwm.bean.LocalSessionStateBean;
  33. import password.pwm.bean.LoginInfoBean;
  34. import password.pwm.bean.SessionLabel;
  35. import password.pwm.bean.UserIdentity;
  36. import password.pwm.config.DomainConfig;
  37. import password.pwm.config.PwmSetting;
  38. import password.pwm.config.profile.AccountInformationProfile;
  39. import password.pwm.config.profile.ChangePasswordProfile;
  40. import password.pwm.config.profile.DeleteAccountProfile;
  41. import password.pwm.config.profile.HelpdeskProfile;
  42. import password.pwm.config.profile.PeopleSearchProfile;
  43. import password.pwm.config.profile.Profile;
  44. import password.pwm.config.profile.ProfileDefinition;
  45. import password.pwm.config.profile.SetupOtpProfile;
  46. import password.pwm.config.profile.UpdateProfileProfile;
  47. import password.pwm.config.value.data.FormConfiguration;
  48. import password.pwm.error.ErrorInformation;
  49. import password.pwm.error.PwmError;
  50. import password.pwm.error.PwmUnrecoverableException;
  51. import password.pwm.http.bean.ImmutableByteArray;
  52. import password.pwm.http.servlet.AbstractPwmServlet;
  53. import password.pwm.http.servlet.PwmRequestID;
  54. import password.pwm.http.servlet.PwmServletDefinition;
  55. import password.pwm.ldap.UserInfo;
  56. import password.pwm.util.Validator;
  57. import password.pwm.util.java.LazySupplier;
  58. import password.pwm.util.java.StringUtil;
  59. import password.pwm.util.java.TimeDuration;
  60. import password.pwm.util.logging.PwmLogLevel;
  61. import password.pwm.util.logging.PwmLogger;
  62. import password.pwm.util.secure.PwmSecurityKey;
  63. import password.pwm.ws.server.RestResultBean;
  64. import javax.servlet.ServletException;
  65. import javax.servlet.http.HttpServletRequest;
  66. import javax.servlet.http.HttpServletResponse;
  67. import java.io.ByteArrayOutputStream;
  68. import java.io.IOException;
  69. import java.io.InputStream;
  70. import java.io.Serializable;
  71. import java.time.Instant;
  72. import java.util.ArrayList;
  73. import java.util.Collections;
  74. import java.util.EnumSet;
  75. import java.util.LinkedHashMap;
  76. import java.util.List;
  77. import java.util.Locale;
  78. import java.util.Map;
  79. import java.util.Optional;
  80. import java.util.Set;
  81. import java.util.concurrent.locks.Lock;
  82. import java.util.concurrent.locks.ReentrantLock;
  83. import java.util.function.Supplier;
  84. public class PwmRequest extends PwmHttpRequestWrapper
  85. {
  86. private static final PwmLogger LOGGER = PwmLogger.forClass( PwmRequest.class );
  87. private final PwmResponse pwmResponse;
  88. private final PwmURL pwmURL;
  89. private final PwmRequestID pwmRequestID;
  90. private final transient PwmApplication pwmApplication;
  91. private final transient Supplier<SessionLabel> sessionLabelLazySupplier = new LazySupplier<>( this::makeSessionLabel );
  92. private final Set<PwmRequestFlag> flags = EnumSet.noneOf( PwmRequestFlag.class );
  93. private final Instant requestStartTime = Instant.now();
  94. private final DomainID domainID;
  95. private final Lock cspCreationLock = new ReentrantLock();
  96. private static final Lock CREATE_LOCK = new ReentrantLock();
  97. public static PwmRequest forRequest(
  98. final HttpServletRequest request,
  99. final HttpServletResponse response
  100. )
  101. throws PwmUnrecoverableException
  102. {
  103. CREATE_LOCK.lock();
  104. try
  105. {
  106. PwmRequest pwmRequest = ( PwmRequest ) request.getAttribute( PwmRequestAttribute.PwmRequest.toString() );
  107. if ( pwmRequest == null )
  108. {
  109. final PwmApplication pwmApplication = ContextManager.getPwmApplication( request );
  110. pwmRequest = new PwmRequest( request, response, pwmApplication );
  111. request.setAttribute( PwmRequestAttribute.PwmRequest.toString(), pwmRequest );
  112. }
  113. return pwmRequest;
  114. }
  115. finally
  116. {
  117. CREATE_LOCK.unlock();
  118. }
  119. }
  120. private PwmRequest(
  121. final HttpServletRequest httpServletRequest,
  122. final HttpServletResponse httpServletResponse,
  123. final PwmApplication pwmApplication
  124. )
  125. throws PwmUnrecoverableException
  126. {
  127. super( httpServletRequest, pwmApplication.getConfig() );
  128. this.pwmRequestID = PwmRequestID.next();
  129. this.pwmResponse = new PwmResponse( httpServletResponse, this, pwmApplication.getConfig() );
  130. this.pwmApplication = pwmApplication;
  131. this.pwmURL = PwmURL.create( this.getHttpServletRequest() );
  132. this.domainID = PwmHttpRequestWrapper.readDomainIdFromRequest( httpServletRequest );
  133. }
  134. public PwmDomain getPwmDomain( )
  135. {
  136. return pwmApplication.domains().get( getDomainID() );
  137. }
  138. public PwmSession getPwmSession( )
  139. {
  140. return getPwmSession( this.getPwmDomain() );
  141. }
  142. public PwmSession getPwmSession( final PwmDomain pwmDomain )
  143. {
  144. return PwmSessionFactory.readPwmSession( this.getHttpServletRequest().getSession(), pwmDomain );
  145. }
  146. public SessionLabel getLabel( )
  147. {
  148. return sessionLabelLazySupplier.get();
  149. }
  150. private SessionLabel makeSessionLabel( )
  151. {
  152. return getPwmSession().getLabel().toBuilder()
  153. .requestID( pwmRequestID.toString() )
  154. .build();
  155. }
  156. public PwmResponse getPwmResponse( )
  157. {
  158. return pwmResponse;
  159. }
  160. public Locale getLocale( )
  161. {
  162. if ( isFlag( PwmRequestFlag.INCLUDE_CONFIG_CSS ) )
  163. {
  164. return PwmConstants.DEFAULT_LOCALE;
  165. }
  166. if ( !getURL().isLocalizable() )
  167. {
  168. return PwmConstants.DEFAULT_LOCALE;
  169. }
  170. return getPwmSession().getSessionStateBean().getLocale();
  171. }
  172. public void forwardToJsp( final JspUrl jspURL )
  173. throws ServletException, IOException, PwmUnrecoverableException
  174. {
  175. this.getPwmResponse().forwardToJsp( jspURL );
  176. }
  177. public void respondWithError( final ErrorInformation errorInformation )
  178. throws IOException, ServletException, PwmUnrecoverableException
  179. {
  180. respondWithError( errorInformation, true );
  181. }
  182. public void respondWithError(
  183. final ErrorInformation errorInformation,
  184. final boolean forceLogout
  185. )
  186. throws IOException, ServletException, PwmUnrecoverableException
  187. {
  188. if ( forceLogout )
  189. {
  190. getPwmResponse().respondWithError( errorInformation, PwmResponse.Flag.ForceLogout );
  191. }
  192. else
  193. {
  194. getPwmResponse().respondWithError( errorInformation );
  195. }
  196. }
  197. public void outputJsonResult( final RestResultBean restResultBean )
  198. throws IOException
  199. {
  200. this.getPwmResponse().outputJsonResult( restResultBean );
  201. }
  202. public ContextManager getContextManager( )
  203. throws PwmUnrecoverableException
  204. {
  205. return ContextManager.getContextManager( this );
  206. }
  207. public Optional<InputStream> readFileUploadStream( final String filePartName )
  208. throws IOException, ServletException, PwmUnrecoverableException
  209. {
  210. try
  211. {
  212. if ( ServletFileUpload.isMultipartContent( this.getHttpServletRequest() ) )
  213. {
  214. // Create a new file upload handler
  215. final ServletFileUpload upload = new ServletFileUpload();
  216. // Parse the request
  217. for ( final FileItemIterator iter = upload.getItemIterator( this.getHttpServletRequest() ); iter.hasNext(); )
  218. {
  219. final FileItemStream item = iter.next();
  220. if ( filePartName.equals( item.getFieldName() ) )
  221. {
  222. return Optional.of( item.openStream() );
  223. }
  224. }
  225. }
  226. }
  227. catch ( final Exception e )
  228. {
  229. LOGGER.error( () -> "error reading file upload: " + e.getMessage() );
  230. }
  231. return Optional.empty();
  232. }
  233. public Map<String, FileUploadItem> readFileUploads(
  234. final int maxFileSize,
  235. final int maxItems
  236. )
  237. throws PwmUnrecoverableException
  238. {
  239. final Map<String, FileUploadItem> returnObj = new LinkedHashMap<>();
  240. try
  241. {
  242. if ( ServletFileUpload.isMultipartContent( this.getHttpServletRequest() ) )
  243. {
  244. final ServletFileUpload upload = new ServletFileUpload();
  245. final FileItemIterator iter = upload.getItemIterator( this.getHttpServletRequest() );
  246. while ( iter.hasNext() && returnObj.size() < maxItems )
  247. {
  248. final FileItemStream item = iter.next();
  249. final InputStream inputStream = item.openStream();
  250. final ByteArrayOutputStream baos = new ByteArrayOutputStream();
  251. final long length = IOUtils.copyLarge( inputStream, baos, 0, maxFileSize + 1 );
  252. if ( length > maxFileSize )
  253. {
  254. final ErrorInformation errorInformation = new ErrorInformation( PwmError.ERROR_INTERNAL, "upload file size limit exceeded" );
  255. LOGGER.error( this, errorInformation );
  256. respondWithError( errorInformation );
  257. return Collections.emptyMap();
  258. }
  259. final byte[] outputFile = baos.toByteArray();
  260. final FileUploadItem fileUploadItem = new FileUploadItem(
  261. item.getName(),
  262. item.getContentType(),
  263. ImmutableByteArray.of( outputFile )
  264. );
  265. returnObj.put( item.getFieldName(), fileUploadItem );
  266. }
  267. }
  268. }
  269. catch ( final Exception e )
  270. {
  271. LOGGER.error( () -> "error reading file upload: " + e.getMessage() );
  272. }
  273. return Collections.unmodifiableMap( returnObj );
  274. }
  275. @Value
  276. public static class FileUploadItem
  277. {
  278. private final String name;
  279. private final String type;
  280. private final ImmutableByteArray content;
  281. }
  282. public UserIdentity getUserInfoIfLoggedIn( )
  283. {
  284. return this.getPwmSession().isAuthenticated()
  285. ? this.getPwmSession().getUserInfo().getUserIdentity()
  286. : null;
  287. }
  288. public void validatePwmFormID( )
  289. throws PwmUnrecoverableException
  290. {
  291. Validator.validatePwmFormID( this );
  292. }
  293. public boolean convertURLtokenCommand(
  294. final PwmServletDefinition pwmServletDefinition,
  295. final AbstractPwmServlet.ProcessAction processAction
  296. )
  297. throws IOException, PwmUnrecoverableException
  298. {
  299. final String uri = getURLwithoutQueryString();
  300. if ( uri == null || uri.length() < 1 )
  301. {
  302. return false;
  303. }
  304. final String servletPath = this.getHttpServletRequest().getServletPath();
  305. if ( !uri.contains( servletPath ) )
  306. {
  307. LOGGER.error( () -> "unexpected uri handler, uri '" + uri + "' does not contain servlet path '" + servletPath + "'" );
  308. return false;
  309. }
  310. String aftPath = uri.substring( uri.indexOf( servletPath ) + servletPath.length() );
  311. if ( aftPath.startsWith( "/" ) )
  312. {
  313. aftPath = aftPath.substring( 1 );
  314. }
  315. if ( aftPath.contains( "?" ) )
  316. {
  317. aftPath = aftPath.substring( 0, aftPath.indexOf( "?" ) );
  318. }
  319. if ( aftPath.contains( "&" ) )
  320. {
  321. aftPath = aftPath.substring( 0, aftPath.indexOf( "?" ) );
  322. }
  323. if ( aftPath.length() <= 1 )
  324. {
  325. return false;
  326. }
  327. // note this value is still urlencoded - the servlet container does not decode path values.
  328. final String tokenValue = aftPath;
  329. final StringBuilder redirectURL = new StringBuilder();
  330. redirectURL.append( this.getHttpServletRequest().getContextPath() );
  331. redirectURL.append( pwmServletDefinition.servletUrl() );
  332. redirectURL.append( "?" );
  333. redirectURL.append( PwmConstants.PARAM_ACTION_REQUEST ).append( "=" ).append( processAction.toString() );
  334. redirectURL.append( "&" );
  335. redirectURL.append( PwmConstants.PARAM_TOKEN ).append( "=" ).append( tokenValue );
  336. LOGGER.debug( this, () -> "detected long servlet url, redirecting user to " + redirectURL );
  337. getPwmResponse().sendRedirect( redirectURL.toString() );
  338. return true;
  339. }
  340. public void setAttribute( final PwmRequestAttribute name, final Serializable value )
  341. {
  342. this.getHttpServletRequest().setAttribute( name.toString(), value );
  343. }
  344. public Serializable getAttribute( final PwmRequestAttribute name )
  345. {
  346. return ( Serializable ) this.getHttpServletRequest().getAttribute( name.toString() );
  347. }
  348. public PwmURL getURL( )
  349. {
  350. return pwmURL;
  351. }
  352. public void debugHttpRequestToLog( final String extraText, final Supplier<TimeDuration> timeDuration )
  353. throws PwmUnrecoverableException
  354. {
  355. if ( LOGGER.isEnabled( PwmLogLevel.TRACE ) )
  356. {
  357. final String moreExtraText = ( StringUtil.isEmpty( extraText ) ? "" : extraText + " " )
  358. + "request=" + this.getPwmRequestID() + ", domain=" + this.getDomainID().stringValue();
  359. final String debugTxt = debugHttpRequestToString( moreExtraText, false );
  360. LOGGER.trace( this.getLabel(), () -> debugTxt, timeDuration );
  361. }
  362. }
  363. public boolean isAuthenticated( )
  364. {
  365. return getPwmSession().isAuthenticated();
  366. }
  367. public boolean isForcedPageView( ) throws PwmUnrecoverableException
  368. {
  369. if ( !isAuthenticated() )
  370. {
  371. return false;
  372. }
  373. final PwmURL pwmURL = getURL();
  374. final UserInfo userInfoBean = getPwmSession().getUserInfo();
  375. if ( getPwmSession().getLoginInfoBean().isLoginFlag( LoginInfoBean.LoginFlag.forcePwChange ) && pwmURL.isChangePasswordURL() )
  376. {
  377. return true;
  378. }
  379. if ( userInfoBean.isRequiresNewPassword() && pwmURL.isChangePasswordURL() )
  380. {
  381. return true;
  382. }
  383. if ( userInfoBean.isRequiresResponseConfig() && pwmURL.matches( PwmServletDefinition.SetupResponses ) )
  384. {
  385. return true;
  386. }
  387. if ( userInfoBean.isRequiresOtpConfig() && pwmURL.matches( PwmServletDefinition.SetupOtp ) )
  388. {
  389. return true;
  390. }
  391. if ( userInfoBean.isRequiresUpdateProfile() && pwmURL.matches( PwmServletDefinition.UpdateProfile ) )
  392. {
  393. return true;
  394. }
  395. return false;
  396. }
  397. public void setFlag( final PwmRequestFlag flag, final boolean status )
  398. {
  399. if ( status )
  400. {
  401. flags.add( flag );
  402. }
  403. else
  404. {
  405. flags.remove( flag );
  406. }
  407. }
  408. public boolean isFlag( final PwmRequestFlag flag )
  409. {
  410. return flags.contains( flag );
  411. }
  412. public boolean hasForwardUrl( )
  413. {
  414. final LocalSessionStateBean ssBean = this.getPwmSession().getSessionStateBean();
  415. final String redirectURL = ssBean.getForwardURL();
  416. return StringUtil.notEmpty( redirectURL );
  417. }
  418. public String getForwardUrl( )
  419. {
  420. final LocalSessionStateBean ssBean = this.getPwmSession().getSessionStateBean();
  421. String redirectURL = ssBean.getForwardURL();
  422. if ( StringUtil.isEmpty( redirectURL ) )
  423. {
  424. redirectURL = this.getDomainConfig().readSettingAsString( PwmSetting.URL_FORWARD );
  425. }
  426. if ( StringUtil.isEmpty( redirectURL ) )
  427. {
  428. redirectURL = this.getBasePath();
  429. }
  430. if ( StringUtil.isEmpty( redirectURL ) )
  431. {
  432. redirectURL = "/";
  433. }
  434. return redirectURL;
  435. }
  436. public String getLogoutURL(
  437. )
  438. {
  439. final LocalSessionStateBean ssBean = this.getPwmSession().getSessionStateBean();
  440. return ssBean.getLogoutURL() == null ? pwmApplication.getConfig().readSettingAsString( PwmSetting.URL_LOGOUT ) : ssBean.getLogoutURL();
  441. }
  442. public String getCspNonce( )
  443. throws PwmUnrecoverableException
  444. {
  445. cspCreationLock.lock();
  446. try
  447. {
  448. if ( getAttribute( PwmRequestAttribute.CspNonce ) == null )
  449. {
  450. final int nonceLength = Integer.parseInt( getDomainConfig().readAppProperty( AppProperty.HTTP_HEADER_CSP_NONCE_BYTES ) );
  451. final byte[] cspNonce = getPwmDomain().getSecureService().pwmRandom().newBytes( nonceLength );
  452. final String cspString = StringUtil.base64Encode( cspNonce );
  453. setAttribute( PwmRequestAttribute.CspNonce, cspString );
  454. }
  455. return ( String ) getAttribute( PwmRequestAttribute.CspNonce );
  456. }
  457. finally
  458. {
  459. cspCreationLock.unlock();
  460. }
  461. }
  462. public <T extends Serializable> Optional<T> readEncryptedCookie( final String cookieName, final Class<T> returnClass )
  463. throws PwmUnrecoverableException
  464. {
  465. final Optional<String> strValue = this.readCookie( cookieName );
  466. if ( strValue.isEmpty() )
  467. {
  468. return Optional.empty();
  469. }
  470. final PwmSecurityKey pwmSecurityKey = getPwmSession().getSecurityKey( this );
  471. final T t = getPwmDomain().getSecureService().decryptObject( strValue.get(), pwmSecurityKey, returnClass );
  472. return Optional.of( t );
  473. }
  474. @Override
  475. public String toString( )
  476. {
  477. return this.getClass().getSimpleName() + " "
  478. + ( this.getLabel() == null ? "" : getLabel().toString() )
  479. + " " + getURLwithoutQueryString();
  480. }
  481. public void addFormInfoToRequestAttr(
  482. final PwmSetting formSetting,
  483. final boolean readOnly,
  484. final boolean showPasswordFields
  485. )
  486. {
  487. final ArrayList<FormConfiguration> formConfiguration = new ArrayList<>( this.getDomainConfig().readSettingAsForm( formSetting ) );
  488. addFormInfoToRequestAttr( formConfiguration, null, readOnly, showPasswordFields );
  489. }
  490. public void addFormInfoToRequestAttr(
  491. final List<FormConfiguration> formConfiguration,
  492. final Map<FormConfiguration, String> formDataMap,
  493. final boolean readOnly,
  494. final boolean showPasswordFields
  495. )
  496. {
  497. final LinkedHashMap<FormConfiguration, String> formDataMapValue = formDataMap == null
  498. ? new LinkedHashMap<>()
  499. : new LinkedHashMap<>( formDataMap );
  500. this.setAttribute( PwmRequestAttribute.FormConfiguration, new ArrayList<>( formConfiguration ) );
  501. this.setAttribute( PwmRequestAttribute.FormData, formDataMapValue );
  502. this.setAttribute( PwmRequestAttribute.FormReadOnly, readOnly );
  503. this.setAttribute( PwmRequestAttribute.FormShowPasswordFields, showPasswordFields );
  504. }
  505. public void invalidateSession( )
  506. throws PwmUnrecoverableException
  507. {
  508. this.getPwmSession().unauthenticateUser( this );
  509. this.getHttpServletRequest().getSession().invalidate();
  510. }
  511. public String getURLwithQueryString( ) throws PwmUnrecoverableException
  512. {
  513. return PwmURL.appendAndEncodeUrlParameters( getURLwithoutQueryString(), readParametersAsMap() );
  514. }
  515. public boolean endUserFunctionalityAvailable( )
  516. {
  517. final PwmApplicationMode mode = pwmApplication.getApplicationMode();
  518. if ( mode == PwmApplicationMode.NEW )
  519. {
  520. return false;
  521. }
  522. if ( PwmConstants.TRIAL_MODE )
  523. {
  524. return true;
  525. }
  526. if ( mode == PwmApplicationMode.RUNNING )
  527. {
  528. return true;
  529. }
  530. return false;
  531. }
  532. public String getContextPath( )
  533. {
  534. return this.getHttpServletRequest().getContextPath();
  535. }
  536. public String getBasePath( )
  537. {
  538. final String rawContextPath = this.getHttpServletRequest().getContextPath();
  539. if ( getAppConfig().isMultiDomain() )
  540. {
  541. return rawContextPath + "/" + this.getDomainID().stringValue();
  542. }
  543. return rawContextPath;
  544. }
  545. public PwmRequestContext getPwmRequestContext()
  546. {
  547. return new PwmRequestContext( pwmApplication, this.getDomainID(), this.getLabel(), this.getLocale(), pwmRequestID );
  548. }
  549. public String getPwmRequestID()
  550. {
  551. return pwmRequestID.toString();
  552. }
  553. public Instant getRequestStartTime()
  554. {
  555. return requestStartTime;
  556. }
  557. public DomainID getDomainID()
  558. {
  559. return domainID;
  560. }
  561. public DomainConfig getDomainConfig()
  562. {
  563. return getPwmDomain().getConfig();
  564. }
  565. public PwmApplication getPwmApplication()
  566. {
  567. return pwmApplication;
  568. }
  569. private Profile getProfile( final PwmDomain pwmDomain, final ProfileDefinition profileDefinition ) throws PwmUnrecoverableException
  570. {
  571. if ( profileDefinition.isAuthenticated() && !getPwmSession().isAuthenticated() )
  572. {
  573. throw new IllegalStateException( "can not read authenticated profile while session is unauthenticated" );
  574. }
  575. final String profileID = getPwmSession().getUserInfo().getProfileIDs().get( profileDefinition );
  576. if ( profileID != null )
  577. {
  578. return pwmDomain.getConfig().getProfileMap( profileDefinition ).get( profileID );
  579. }
  580. throw new PwmUnrecoverableException( PwmError.ERROR_NO_PROFILE_ASSIGNED );
  581. }
  582. public HelpdeskProfile getHelpdeskProfile() throws PwmUnrecoverableException
  583. {
  584. return ( HelpdeskProfile ) getProfile( getPwmDomain(), ProfileDefinition.Helpdesk );
  585. }
  586. public SetupOtpProfile getSetupOTPProfile() throws PwmUnrecoverableException
  587. {
  588. return ( SetupOtpProfile ) getProfile( getPwmDomain(), ProfileDefinition.SetupOTPProfile );
  589. }
  590. public UpdateProfileProfile getUpdateAttributeProfile() throws PwmUnrecoverableException
  591. {
  592. return ( UpdateProfileProfile ) getProfile( getPwmDomain(), ProfileDefinition.UpdateAttributes );
  593. }
  594. public PeopleSearchProfile getPeopleSearchProfile() throws PwmUnrecoverableException
  595. {
  596. return ( PeopleSearchProfile ) getProfile( getPwmDomain(), ProfileDefinition.PeopleSearch );
  597. }
  598. public DeleteAccountProfile getSelfDeleteProfile() throws PwmUnrecoverableException
  599. {
  600. return ( DeleteAccountProfile ) getProfile( getPwmDomain(), ProfileDefinition.DeleteAccount );
  601. }
  602. public ChangePasswordProfile getChangePasswordProfile() throws PwmUnrecoverableException
  603. {
  604. return ( ChangePasswordProfile ) getProfile( getPwmDomain(), ProfileDefinition.ChangePassword );
  605. }
  606. public AccountInformationProfile getAccountInfoProfile() throws PwmUnrecoverableException
  607. {
  608. return ( AccountInformationProfile ) getProfile( getPwmDomain(), ProfileDefinition.AccountInformation );
  609. }
  610. }